[Gdal-dev] GPSDrive Success! (Partial, labor-intensive...)

S Clark smc+gdal at dogphilosophy.net
Sun Sep 12 15:00:28 EDT 2004

Quick recap:  I'm attempting to learn to convert various map images,
starting with UTM map images, to one of the two projections supported
by GPSDrive.  At present, the image sources I am using give me only
the following pieces of information:

1)Latitude and Longitude of the center point of the image
2)A "scale", which appears to related to meters/pixel
3)A known image size, required to be 1280x1024 pixels
4)The projection of the source image (currently UTM)

I was able to SUCCESSFULLY convert the previously mentioned Terraserver image
of the "King's Bowl" crater (crater itself is at 42.94944 -113.21637, if
anyone wants to look up a picture of it) such that it is scaled and positioned
correctly in GPSDrive.  I've still got a ways to go to learn what I need, as
there is still a great deal of manual intervention required at the last step,
but here's what I've got so far:

1)Create a "world file" to go with the source image, using the small amount of 
information available for the image:
   A)Calculate the meters/pixel of the image - conversion from the "map scale"
   of GPSDrive, according to the GPSDrive source code gives the formula for   
   this as "map scale/2817.947378".  This gives 1.956033687155673 m/pixel
   for the "scale 5512" original image.

   B)use the 'proj' command (from the proj.4 project) to calculate the
   "easting" and "northing":
      proj +proj=utm +lon_0=(lon of image center) +ellps=WGS84 -r << EOF
      > 42.94584 -113.2167
      > EOF
      319158.52       4757184.46

   C)Create the world file (in this case, named    

2)use gdalwarp to convert the image
(NOTE: GPSDrive "top_*" images should be "latlong".  "map_*" images
MAY be Orthographic [unconfirmed])
(QUESTION: What's the difference between "eqc" (Equirectangular) and 
"latlon" ("Geographic")?)
   A)calculate the UTM zone (floor(abs(-180.000-$image_center_longitude)/6))
   B)gdalwarp to a .bmp (imagemagick appears to have trouble with GeoTIFF)
      /usr/bin/gdalwarp -s_srs '+proj=utm +zone=12 +datum=NAD83 +x0=500000' 
-t_srs '+proj=latlong +datum=WGS84' -of bmp map_42.94584_-113.2167_5512.jpeg 
      Creating output file is that 1432P x 851L.
      ERROR 6: Dataset does not support the SetProjection() method.
      :0...10...20...30...40...50...60...70...80...90...100 - done.
(PROBLEM: gdalwarp couldn't convert to ortho: "too many pixels failed to
transform (441 of 441)")

   C)convert the image to 1280x1024 without changing the center or rescaling
   or warping the map
      i)for undersized height or width, add equal-sized blank borders to
      both sides of the undersized dimension
      ii)for oversized height/width, cut out an appropriately-sized center

      mogrify -border 0x87 -crop 1280x1024+76+0 top_kings_bowl.bmp

3)Add the image to GPSDrive
   A)Copy image to ~/.gpsdrive or wherever GPSDrive looks for images
   B)Add the image to map_koord.txt
      top_kings_bowl.bmp 42.94584 -113.2167 5512
   C)(The worst part right now) - fiddle with the "scale" until the map    
   actually works right.  By trial and error (and examining how the saved
   track file lined up with the road in the aerial photo) I was able to 
   determine that the new image appeared to be about 1:7000 instead of 5512.
   Change the map_koord.txt line accordingly.
      top_kings_bowl.bmp 42.94584 -113.2167 7000
(QUESTION: has the image actually been "rescaled" by the gdalwarp process
from GPSDrive's perspective, or has the "scale" of 5512 been wrong all along?
The 5512 "scale" looks as correct as can be expected when left as UTM and
displayed as a "map_" file in GPSDrive...)

And now the track showing our travel correctly follows the road we took
into the feature.  Screenshots:

Since the real goal here for me is to be able to automate the entire 
fetch/convert/add-to-GPSDrive process, I still need to figure out what
the problem is with the "scale", but otherwise this seems to be working.

It would also be nice to figure out why I can't get gdalwarp to convert
the image to an Orthographic projection as well (since the information
from Ed McNierney [thanks!] seems to imply there's a good chance that's the
"map_*" projection that GPSDrive uses), but being able to get working
Geographic (latlong) projection images is good enough for my purposes right

Thanks again - suggestions welcome!


More information about the Gdal-dev mailing list