overlaying mapinfo on google/bing

Topics: Data Access, SharpMap v0.9 / v1.x, Web Controls
May 27, 2011 at 4:26 AM

hi all,

I want to use sharpmap to overlay a mapinfo tab file onto google or bing.

I have it working pretty much at the moment however the co-ordinates that bing/google show are in correct so my mapinfo file doesnt make any sense to teh region its being overlayed on. I think I need to transform the mapinfo co-ordinates to the bing/google type but I'm not entirely sure how to do this or if this is the correct thing.

Im using sharpmap 0.9

This is my code so far

            myMap = new Map(new Size((int)imgMap.Width.Value, (int)imgMap.Height.Value));

            var ogrProvider = new Ogr(@"C:\test.tab");

            var layer = new VectorLayer("test");
            layer.DataSource = ogrProvider;

            var layerbing = new TileLayer(new BingTileSource(BingRequest.UrlBing, "", BingMapType.Aerial), "TileLayer");

            //var layergoogle = new TileLayer(new GoogleTileSource(GoogleMapType.GoogleMap), "googlemaps");

            myMap.Layers.Add(layerbing);
            
           
           // myMap.Layers.Add(layergoogle);

            myMap.Layers.Add(layer);
            myMap.ZoomToBox(layer.Envelope);

When I run it up the "layer" has a SRID of 7 and the "layerbing" has a SRID of -1, I think this might be the issue and I need to transform the co-ordinates,.

 

Would appreciate some help In pushing this in the right direction.

May 27, 2011 at 8:04 AM
Edited May 27, 2011 at 8:07 AM

I have figured out that bing uses the co-ordinates system EPSG:3785 (Popular Visualisation CRS / Mercator) and my layer uses the system EPSG:28356 (GDA94 / MGA zone 56) (checked this in mapinfo).

In my code I am creating a transformation from 28356 -> 3785 using well known text from http://spatialreference.org/ref/epsg/28356/esriwkt/ (reading this from teh 28356.txt file), interestingly enough I couldnt get the 3785 wkt from the same website to parse so I have copied it from another post on this forum.

            myMap = new Map(new Size((int)imgMap.Width.Value, (int)imgMap.Height.Value));

            var ogrProvider = new Ogr(@"C:\test.tab");

            var layer = new VectorLayer("test");
            layer.DataSource = ogrProvider;

            //layer.CoordinateTransformation.
            var layerbing = new TileLayer(new BingTileSource(BingRequest.UrlBing, "", BingMapType.Roads), "TileLayer");

            var layergoogle = new TileLayer(new GoogleTileSource(GoogleMapType.GoogleMap), "googlemaps");

           

            string mga56string;

            using(var reader = new StreamReader(@"C:\28356.txt"))
            {

                 mga56string = reader.ReadToEnd();
            }           


            var epsg3785 = new CoordinateSystemFactory().CreateFromWkt(
                                                                        "PROJCS[\"Popular Visualisation CRS / Mercator\", " +
                                                                        "GEOGCS[\"Popular Visualisation CRS\", " +
                                                                        "DATUM[\"Popular Visualisation Datum\", " +
                                                                        "SPHEROID[\"Popular Visualisation Sphere\", 6378137, 0, AUTHORITY[\"EPSG\",\"7059\"]], " +
                                                                        "TOWGS84[0, 0, 0, 0, 0, 0, 0], " +
                                                                        "AUTHORITY[\"EPSG\",\"6055\"]], " +
                                                                        "PRIMEM[\"Greenwich\", 0, AUTHORITY[\"EPSG\", \"8901\"]], " +
                                                                        "UNIT[\"degree\", 0.0174532925199433, AUTHORITY[\"EPSG\", \"9102\"]], " +
                                                                        "AXIS[\"E\", EAST], AXIS[\"N\", NORTH], " +
                                                                        "AUTHORITY[\"EPSG\",\"4055\"]], " +
                                                                        "PROJECTION[\"Mercator\"], " +
                                                                        "PARAMETER[\"False_Easting\", 0], " +
                                                                        "PARAMETER[\"False_Northing\", 0], " +
                                                                        "PARAMETER[\"Central_Meridian\", 0], " +
                                                                        "PARAMETER[\"Latitude_of_origin\", 0], " +
                                                                        "UNIT[\"metre\", 1, AUTHORITY[\"EPSG\", \"9001\"]], " +
                                                                        "AXIS[\"East\", EAST], AXIS[\"North\", NORTH], " +
                                                                        "AUTHORITY[\"EPSG\",\"3785\"]]");


            var mga56 = new CoordinateSystemFactory().CreateFromWkt(mga56string);

            var ctf = new CoordinateTransformationFactory();

            layer.CoordinateTransformation = ctf.CreateFromCoordinateSystems(mga56, epsg3785);

            //myMap.Layers.Add(layerbing);
            myMap.Layers.Add(layergoogle);

            myMap.Layers.Add(layer);
            myMap.ZoomToBox(layer.Envelope);



No that I have done this the overlapping of my layers is closer than it was without it, but still not correct.

Before the transformation the layers should have shown an area in  Waverly, NSW, QLD, Australia, but it seemed to be looking at a point in France somewhere, with this applied it gets closer and it shows an area in Narrabeen, NSW, QLD, Australia, it seems to be very roughtly around 200km north of where it should be

Is there something else I'm missing here?

Coordinator
May 27, 2011 at 8:56 AM

I have experienced issues with coordinate using Proj.Net.

You may want to use DotSpatial.Projections instead. This involves changing Target Framework to at least 3.5.
There is example code of how to do that in WinFormSamples

For performance reason I strongly suggest you do the reprojection beforehand (save as in mapinfo and change the projection to epsg:3875) and use that file instead.

Hth FObermaier

May 27, 2011 at 10:13 AM

Do you know what category 3875 falls under in mapinfo? I cant seem to locate it

Developer
May 27, 2011 at 10:35 AM

try to use 900913 if defined in mapinfo

Coordinator
May 30, 2011 at 10:29 AM
thecubical wrote:

Do you know what category 3875 falls under in mapinfo? I cant seem to locate it

The category is "World Projections" and the projection itself is labeled something like "Popular Worldprojection-CRS (EPSG:3857)".

If you export the layer to MIF the coordsys clause looks like this:

CoordSys Earth Projection 10, 157, "m", 0 Bounds (-40075016.6856, -20037508.343) (40075016.6856, 20037508.343)

Hth FObermaier

May 30, 2011 at 10:42 AM

cheers