GDALRasterLayer and Coordinate Transform

Jan 18, 2012 at 2:33 PM


I have an OSM TileLayer upon which I wish to draw a GDALRasterLayer of a JPEG image and a Shapefile. The TileLayer is in Google Spherical Mercator Coordinates, and the Shapefile and JPEG (with which I have a generated corresponding georeference file) are in Lat/Long WGS84. I add a CoordinateTransformation to the Shapefile layer which translates the shapefile to the correct location. However, when I add the coordinate transform to the raster layer it doesn't transform the layer. Do I  need to do this another way? I can see by debugging that the envelope for the raster layer is correct, but when applying the CoordinateTransform nothing changes (the envelope changes to the new coordinate system on the Shapefile).

Any help would be appreciated.



Jan 18, 2012 at 3:27 PM

Extra information:

I have noticed that in GdalRasterLayer that there is a ReprojectToMap method which takes a Map. However, the _transform property is never set as null is passed through instead of an ICoordinateSystem, which GetTransform needs.

// public method to set envelope and transform to new projection       
public void ReprojectToMap(Map map)       

Is this a bug? Or is this functionality deliberately disabled at present?



Jan 18, 2012 at 6:42 PM

On the fly reprojection -though possible using gdal- is currently not implemented.

If you have the need for it, raise an issue, or better provide a patch to solve it :).



Jan 19, 2012 at 2:27 PM

Thanks, that's what I thought. At the moment I am just converting my tile manually using gdalwarp instead of doing it on the fly.  I may have to raise an issue later (I'll look into fixing it too!)

I'm having another problem with GdalRasterLayer though. GDAL seems to crash when I run the compiled version of the code (it does it using the WinForms example). Running it through Visual Studio in Debug or Release works fine. Do I need to update the GDAL version I am using? I am currenlty using the DLLS from FWTools2.4.7.


Jan 19, 2012 at 3:52 PM

This problem seems related to

Was this ever resolved?


Apr 11, 2013 at 1:09 PM
Hi jp_england

I am working on raster reprojection on the fly too, how is your recent progress?
Dec 18, 2013 at 10:30 AM

I need gdal reprojection too... Any working solution or work in progress ?
Dec 18, 2013 at 11:08 AM
This seams to work :
Changing the visibility of "ApplyTransformToEnvelope" to public, using with this code :
                SharpMap.Layers.GdalRasterLayer layer = new SharpMap.Layers.GdalRasterLayer(Path.GetFileNameWithoutExtension(fi.Name), fi.FullName);

                var ctfac = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
                layer.Transform = ctfac.CreateFromCoordinateSystems(ProjNet.CoordinateSystems.GeographicCoordinateSystem.WGS84,
Dec 18, 2013 at 12:15 PM
why not
Dec 18, 2013 at 1:39 PM
Because you are right :)

I was on trunk, I have switched to Branch/1.0

Seams to work like a charm, thanks :)