Custom maps in SportTracks with GDAL and Oziexplorer plugin

Frequenly Asked Questions

Moderator: FAQ Moderators

Custom maps in SportTracks with GDAL and Oziexplorer plugin

Postby CHnuschti » Wed Apr 21, 2010 5:39 pm

Question:

My custom map program allows only the export of tiles with limited size. How can I join these tiles to create a single map section?

Answer:

Procedure can be done with several graphics software. This howto explains how to do this with the freeware Irfanview and paint.net.

1) Download and install IrfanView and paint.net
2) Establish the max. size your custom maps software can export at once. Then set up/draw a corresponding overlay layer (use thinnest line width possible) with the tools of your custom maps software and export all tiles. If you can't export tiles with exact defined position, width and height, export in such way that the layer borders are included.
Image

3) Now if required crop your tiles up to the layers borders. Open tile image with paint.net (Menu File=>Open), set the view to 100% (Menu View=>Actual Size), then use the "Rectangle Select" feature from the "Tools" palette, set your section exactly along the layer borders and crop selection (Menu Image=>Crop to Selection). Then save (Menu File=>Save as...). Proceed with all your tiles. You must assure all your tiles have the exact same pixel width/height on their adjacent borders. Monitor this with the selection size displayed on bottom left of paint.net window.
Notes:
  • Irfanview also has a corresponding crop tool (Menu Edit=>Crop Selection).
  • I recommend to save in best image quality possible. This has an enlarging effect on size. However, IMO it is better to work with best quality throughout the procedure and apply a quality (and size) fit only on the final image.

Image

4) Finally join your tiles together. Use Irfanview (Menu Image=>Create Panorama Image...). Select your tiles (Hold Ctrl or Shift Key for multiple selection with mouseclick in the dialog), sort them if needed, select "direction" (horizontal/vertical) and create image and finally save it.
If you have rows and columns of tiles, you first must build each single row/colum in an intermediary step, and then join them together in a final step.
Image
CHnuschti
 
Posts: 267
Joined: Tue Feb 13, 2007 3:28 am
Location: Switzerland

Postby CHnuschti » Wed Apr 21, 2010 5:40 pm

Question:

What is the procedure to warp / reproject custom maps with GDAL?

Answer:

The objective is to transform your custom map into the projection of the "google maps", so it can be used in SportTracks with the Oziexplorer and custom maps plugin.
Minimum requirements for the procedure used here are:
  • Windows OS (and maybe other OS where a *.bat file runs)
  • Your custom map image, for which you must know the "national" (original) coordinates of the corners top left and bottom right, as well as the corresponding, descriptive 4to6-digit EPSG code (example: epsg:4326).
GDAL is able to deal with several image formats.

1) To use GDAL you must install FWTools (free, Windows/Linux).

2) Edit this batch file (example included). Start your editor (notepad.exe), open batch file (Menu File=>Open), and edit some values.
There is a first section with required ("must have") values (coordinates, paths etc.), and a second section with optional values (cutline, correction, gdal settings). Descriptions see file. Save it (as *.bat), then launch it with doubleclick on the file (or "send to" commandline (="DOS Window")).
The hole process is automated, you finally get a transformed/reprojected image file and a *.map file to be used in Oziexplorer plugin. Drop/copy these 2 files into your chosen "final" folder.
Notes:
  • Top left/bottom right coordinates have to be entered as "national" coordinates as given in your map.
  • EPSG code: you must figure out yourself which one corresponds to your map. Search the internet, ask the publisher of your map software, search in the EPSG (Microsoft Access) database (online version here) or in the spatial reference database.
  • The process is a get all or nothing thing. If your EPSG code is not correct, you may not even get a result image file. At least it is automatized, so you can crawl through a bunch of such (adequate appearing) codes easily in a try&error procedure. *.bat file can be kept open in the editor, once saved.
  • Set up a new folder on the desktop, copy your maps to be reprojected therein. Use a small map section first (for example 1000x600 pixel) to get a clue of the output, it will be processed in no time, don't use correction or cutlines.
  • Correction option: this is a final, fine-adjusting tool (e.g. correction of 50-100 scaled meters in a 1:100000 map). Even if you use the correct EPSG code, there may be some inaccuracy at the borders/cutlines. This option can correct ("fake") it. But can not help if you use a wrong EPSG code.
  • Set deleting=1 in the optional settings to get a clue what output is produced. There are 2 intermediary image files in a successful reprojection.
  • Setting *.jpeg as final image format reduces size of input JPG file to approx. factor 0.33, with still decent image quality.
  • Created *.map files are not valid Oziexplorer files. But they will work for the Oziexplorer plugin.
  • Cutlines in decimal degrees, positive or negative. Longitude positive in northern hemisphere, negative in southern. Latitude positive east of Greenwich meridian, negative west of it.
  • For GDAL options settings, see additional informations here.


Editable (highlighted) fields (required/optional):
Image Image

Scheme of map reprojection:
First the input scheme.
Second left the output, when not using cutlines. The latitude/longitude coordinate grid is supposed to be parallel to the image borders in case of "success". Second left the output if you use cutlines.

Image

Image Image
Last edited by CHnuschti on Sat Jun 05, 2010 4:55 am, edited 6 times in total.
CHnuschti
 
Posts: 267
Joined: Tue Feb 13, 2007 3:28 am
Location: Switzerland

Postby CHnuschti » Wed Apr 21, 2010 5:46 pm

Question:

How do I use these reprojected maps in Oziexplorer plugin?

Answer:

Install the Oziexplorer and custom maps plugin. In SportTracks go to Settings=>Plugins=>OziExplorer and click "Rescan OziExplorer Maps" and select the "final" directory containing your maps and their corresponding *.map calibration files. Select and activate in the list. Set backgroung map as "Street" or "Satellite". In the Daily Activity view route panel select the OziExplorer maps. Your map should be displayed. In "overzoom" and "underzoom" (too high/low resolution), your map will not be displayed.

Notes:
  • Experience here is that Oziexplorer plugin can handle maps with size up to approx. 80MB. Will be progressively slower with increasing map size. Successfully tested here up to size 14000x8000 pixel.
  • You still can reduce the size of a final result JPG image file with for example IrfanView or paint.net. Open it, then save with lower quality (higher compression).


Image Image
Last edited by CHnuschti on Thu Apr 22, 2010 4:20 pm, edited 1 time in total.
CHnuschti
 
Posts: 267
Joined: Tue Feb 13, 2007 3:28 am
Location: Switzerland

Postby CHnuschti » Wed Apr 21, 2010 5:48 pm

Question:

What is the correct EPSG code for my map?

Answer:

Figure out yourself.

List of user inputs (Country / commercial map name (region) / EPSG code), see/please report in this SportTracks forum thread

Switzerland / Swiss map 25,50,100 / 21781
Last edited by CHnuschti on Thu Apr 22, 2010 4:20 pm, edited 1 time in total.
CHnuschti
 
Posts: 267
Joined: Tue Feb 13, 2007 3:28 am
Location: Switzerland

Postby CHnuschti » Thu Apr 22, 2010 3:10 pm

Question:

What GDAL processes are used in a "manual process" for a reprojection up from a simple image file?

Answer:

There is only need of 2 steps + one optional, additional one. Commands must be entered (or pasted over mouse right click menu) as a single line in the commandline of FWTools. Enclose any paths with quotes (""), in order that blanks/spaces are interpreted correctly.


1) First georeference your image file with gdal_translate:
Code: Select all
gdal_translate -of tif -a_srs EPSG:21781 -a_ullr 660079 276673 695659 249987 "C:\Users\admin\Desktop\mapconversion gdal\testfile.JPG" "C:\Users\admin\Desktop\mapconversion gdal\map_georeferenced.tif"
Notes:
  • -of: optionally set output image format (JPG, GeoTiff, etc.). If output will be reused in GDAL, do not set, default GeoTiff will be used throughout the processes.
  • -a_srs: assign EPSG code specifications to the output file. There is also the possiblity for an own definition with a set of several values. Not very practical however, if you are not used with this stuff.
  • -a_ullr: used to set national coordinates (source EPSG) for the 2 corners upper left and lower right.
  • Last 2 entries of line are the source and destination files with full path. (unless your path is already set to the corresponding folder).


2) Second reproject/warp your image file with gdalwarp:
Code: Select all
gdalwarp -s_srs EPSG:21781 -t_srs EPSG:900913 -order 2 -te 916656.74464589   6006584.25810779  969754.063709977   6046834.75877197  -ts 3558  2666 -wo "SAMPLE_STEPS=21" -wo "SAMPLE_GRID=NO" -r cubic -of tif "C:\Users\admin\Desktop\mapconversion gdal\map_georeferenced.tif" "C:\Users\admin\Desktop\mapconversion gdal\map_warped.tif"
Notes:
  • -s_srs and -t_srs: source(file) and target(file) EPSG code.
  • -order: polynomial order for warping (1 to 3).
  • -te: set (optional) cutlines (in units of the target EPSG projection).
  • -ts: set (optional) image size (width & height). Set same or similar to original size. If you don't, image may be considerably stretched in unproportional way.
  • -wo: set additional (optional) warp options, each option with own -wo tag.
  • -r: method of resampling. This influences the quality of the output image.
  • -of: (optional) same as above.
  • Last 2 entries again source/destination file.


3) Transform into final image format with gdal_translate. This is optional, can be set already in step 1)/2)
Code: Select all
gdal_translate -of jpeg "C:\Users\admin\Desktop\mapconversion gdal\map_warped.tif" "C:\Users\admin\Desktop\mapconversion gdal\map_final.jpeg"



Conversion of coordinates with gdaltransform:
Code: Select all
gdaltransform -s_srs epsg:4326 -t_srs epsg:900913 -order 2

First enter line with source/target code alone, then hit Enter key. Now enter a coordinate pair x/y (z optional). Hit enter to get the tranformed coordinates. Comes as triplette, last is "z"=height, usually not used. Only decimal format is accepted, no E, N or min/sec (' ") etc. suffixes accepted. Enter another pair and hit Enter again, etc.. Leave with key Ctrl+C.
CHnuschti
 
Posts: 267
Joined: Tue Feb 13, 2007 3:28 am
Location: Switzerland


Return to FAQ

Who is online

Users browsing this forum: No registered users and 0 guests

cron