tile layer coordinate transformation 9009013 to 4326

Apr 11, 2011 at 2:52 PM

Is it possible to perform a transformation from EPSG:9009013 (i.e. Google and Open Street Map) to EPSG:4326 coordinate system. I am using the following code, however it seems that the tileLayer does not permit transformation.

 

ITileSourcetileSource = new TileSource(new BruTile.FileSystem.FileTileProvider(new FileCache(@"d:\cache", "png")), new SphericalMercatorInvertedWorldSchema());

 TileLayer tileLayer = new TileLayer(tileSource, "test");

var ctf = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();

var cf = new ProjNet.CoordinateSystems.CoordinateSystemFactory();

 

ICoordinateSystem epsg4326 = cf.CreateFromWkt(

   @"GEOGCS[""WGS 84"",

           DATUM[""WGS_1984"",SPHEROID[""WGS 84"",6378137,298.257223563,AUTHORITY[""EPSG"",""7030""]],

           AUTHORITY[""EPSG"",""6326""]],

           PRIMEM[""Greenwich"",0,AUTHORITY[""EPSG"",""8901""]],

           UNIT[""degree"",0.01745329251994328,AUTHORITY[""EPSG"",""9122""]],

           AUTHORITY[""EPSG"",""4326""]]");

ICoordinateSystem epsg9009013 = cf.CreateFromWkt(

   @"PROJCS[""WGS 84 / Pseudo-Mercator"",

           GEOGCS[""WGS 84"",

           DATUM[""WGS_1984"",

           SPHEROID[""WGS 84"", 6378137, 298.257223563, AUTHORITY[""EPSG"",""7030""]],

           AUTHORITY[""EPSG"",""6326""]],

           PRIMEM[""Greenwich"", 0, AUTHORITY[""EPSG"",""8901""]],

           UNIT[""degree"", 0.01745329251994328, AUTHORITY[""EPSG"",""9122""]],

           AUTHORITY[""EPSG"",""4326""]],

           PROJECTION[""Mercator_1SP""],

           PARAMETER[""semi_minor"",6378137],

           PARAMETER[""central_meridian"",0],

           PARAMETER[""scale_factor"",1],

          PARAMETER[""false_easting"",0],

           PARAMETER[""false_northing"",0],

           PARAMETER[""Latitude_of_origin"", 0],

           UNIT[""metre"", 1, AUTHORITY[""EPSG"",""9001""]],

           AXIS[""X"",EAST],

           AXIS[""Y"",NORTH],

          AUTHORITY[""EPSG"",""3857""]]");

 

var ct = ctf.CreateFromCoordinateSystems(epsg909013, epsg4326);

tileLayer.CoordinateTransformation = ct;

MainMapImage.Map.Layers.Add(tileLayer);

Coordinator
Apr 13, 2011 at 7:38 AM
Edited Apr 13, 2011 at 7:39 AM

You are correct. It is not possible to project TileLayers. I think none of the open source projects have a means to do raster projections using C#. There might be a samples doing raster projection with SharpMap using GDAL (not sure). In Mapsui I would prefer a pure C# solution.

Paul

Editor
Oct 31, 2011 at 8:06 PM

If you have some code to fit a Graphics.Transform affine approximation to some point pairs (Least Squares fit), you can do an approximate transformation as you display.  For some situations, you might see some small gaps in your display on tile boundaries, but I have been doing this and am happy with it for the most part.  A lot would depend on if your particular application has the concept of on-the-fly reprojection (that is your map coordinate system and layer coordinate system can be different).

Kyle

Developer
Nov 9, 2011 at 3:15 PM
kellison wrote:

If you have some code to fit a Graphics.Transform affine approximation to some point pairs (Least Squares fit), you can do an approximate transformation as you display.  For some situations, you might see some small gaps in your display on tile boundaries, but I have been doing this and am happy with it for the most part.  A lot would depend on if your particular application has the concept of on-the-fly reprojection (that is your map coordinate system and layer coordinate system can be different).

Kyle

You are warping/transforming the tiles in the rendering process though, not when you get them, don't you?

Felix

Editor
Nov 9, 2011 at 3:28 PM

Yes, transforming in the rendering process.  That way, the tile cache logic is not affected and you do not have to refetch the tiles if you change coordinate systems.

Kyle

Coordinator
Nov 20, 2011 at 7:19 PM
Edited Nov 20, 2011 at 7:19 PM

hi Kyle,

How does that work? You use a projection lib to transform some points (corners?) and then create a Graphics.Transform from this? 

Did you use this in C# applications? It might be relevant for SharpMap and Mapsui.

Paul

Editor
Nov 21, 2011 at 6:29 PM

Pretty much.  First, I tried just projecting the corners of the map view and fit a non-conformal affine transform (and setting that as the Graphics.Transform).  That worked OK until you zoomed out rather far (e.g. looking at an entire continent) where you would see shifts of up to 60 display pixels or so.  Next, I tried projecting the 4 corners of each 256x256 tile so I had a different Graphics.Transform for each tile.  The performance for this is still good and the results are much better.  You do see skinny little tear drop shaped slivers of missing data sometimes along tile boundaries, but that is much better than misregistration for most applications where you are just wanting background context information from OSM or a WMS server.  I was using this in the Dot Spatial environment (using Dot Spatial ProjectionInfo objects to transform).  I wasn't able to commit this to Dot Spatial as Dot Spatial does not currently have the concept of the Map and MapLayers being in different coordinate systems and performing on-the-fly projection between the two.

Kyle