Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I would like to include an overlay raster layer into my OpenLayers map. I've pre-transformed the image into the correct projection (EPSG:900913) and saved as a png using the gdal_translate command:

gdal_translate -a_srs "EPSG:900913" -of "PNG" $RASTERFILEDIR/$x ../data/$x.png

When the file converts it includes an .xml file with transform information as follows:

<GeoTransform>  
  7.0153687766181468e+05,  
  2.9999999999999904e+01,  
  0.0000000000000000e+00,  
  9.5377345182658464e+05,  
  0.0000000000000000e+00, 
  -2.9999999999999904e+01
</GeoTransform>

In OpenLayers I'm loading the image like this:

var imageLayer = new OpenLayers.Layer.Image(source.label, source.src,
  new OpenLayers.Bounds(source.bounds[0],source.bounds[1],source.bounds[2],source.bounds[3]), 
  new OpenLayers.Size(source.size[0], source.size[1]), 
  {
     isBaseLayer: false,
     alwaysInRange: true,
     projection: new OpenLayers.Projection("EPSG:900913")
  });
mapObj.map.addLayers([imageLayer]);

Where the bounds and size are calculated correctly. I end up seeing my image hovering over Africa instead of Columbia. It looks very much like there needs to be a translation included, but I'm not doing it correctly.

How do I know where to look for the translation amount, and how do I provide that information to OpenLayers?

The application I'm working on is here: http://www.stanford.edu/~rpsharp/map-overlay-annotation-test/inseam_explorer.html

Thanks for any help!

share|improve this question
    
The GeoTransform[0] and [3] values describe the top left position, but are <1000km from the "origin" at 0,0 degrees. What values are you using for your bounds? and what does gdalinfo show for your source image (Coordinate System and Corner Coordinates)? –  rcoup Jun 8 '11 at 2:11
add comment

1 Answer

up vote 2 down vote accepted

Just assigning a projection to an image won't cut it, as you can tell you're 700km east of the prime meridian. You will need to know either:

  • The top left corner and the metres per pixel of the image in the EPSG:900913 projection (you should use the equivalent EPSG:3857 these days).
  • If the image is originally in a different projection, the bounds of the image in that projection.

I assume you don't know the first (otherwise you wouldn't be asking the question!), and if it is the latter, you will need to assign the projection and bounds in your source projection before warping it.

For instance, if your image is in the unprojected WGS84 coordinate system (EPSG:4326), you'd use something like:

gdal_translate -of "PNG" -a_srs EPSG:4326 -a_ullr <coordinates of the image bounds> src_file file_out_a

This will produce an XML file with the georeference coordinates similar to the one you posted but in degrees rather than metres. Next use gdal_warp:

gdalwarp -t_srs EPSG:3857 -of "PNG" file_out_a file_out_b

It is likely you'll get black borders around your new image because a square on a spheroid doesn't map to a square on a plane. So you will need to think about mask layers or nodata values.

share|improve this answer
    
Thanks, this is exactly the functionality I was needing. –  Rich Aug 18 '11 at 23:11
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.