4

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, but I'm not sure how to transfrom them and from/to what I need to.

4
  • I have figured out that bing uses the co-ordinates system "EPSG:3785" and my layer uses the system "EPSG:28356", still not sure how to convert though May 27, 2011 at 3:57
  • You should be able to transform the layer you are adding
    – Hairy
    May 27, 2011 at 6:19
  • I can transform it now, but it is about 200km out of where it should be....sharpmap.codeplex.com/discussions/259181 May 27, 2011 at 7:15
  • You're not transforming it correctly then Daniel. Or, is the original data ok?
    – Hairy
    May 27, 2011 at 7:46

1 Answer 1

2

First, you need to use BruTile 0.7.4 for the Bing maps to work correctly (there was a bug in the 0.7.3). 0.7.4 is newly released on NuGet

The you can do like this..

SharpMap.Layers.VectorLayer vLay = new SharpMap.Layers.VectorLayer("Name of layer", provider);

ICoordinateTransformationFactory ctFact = new ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory();
vLay.CoordinateTransformation = 
   ctFact.CreateFromCoordinateSystems(getGDA94(csFact), GetEPSG900913(csFact));
vLay.ReverseCoordinateTransformation = 
ctFact.CreateFromCoordinateSystems(GetEPSG900913(csFact), getGDA94(csFact));

And the helper methods

        ICoordinateSystem getGDA94(ICoordinateSystemFactory csFact)
        {
            return csFact.CreateFromWkt("PROJCS[\"GDA94 / MGA zone 56\",GEOGCS[\"GDA94\",DATUM[\"D_GDA_1994\",SPHEROID[\"GRS_1980\",6378137,298.257222101]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"latitude_of_origin\",0],PARAMETER[\"central_meridian\",153],PARAMETER[\"scale_factor\",0.9996],PARAMETER[\"false_easting\",500000],PARAMETER[\"false_northing\",10000000],UNIT[\"Meter\",1]]");
        }

        private IProjectedCoordinateSystem GetEPSG900913(ICoordinateSystemFactory csFact)
        {
            List<GeoAPI.CoordinateSystems.ProjectionParameter> parameters = new List<GeoAPI.CoordinateSystems.ProjectionParameter>();

            parameters.Add(new GeoAPI.CoordinateSystems.ProjectionParameter("semi_major", 6378137.0));
            parameters.Add(new GeoAPI.CoordinateSystems.ProjectionParameter("semi_minor", 6378137.0));
            parameters.Add(new GeoAPI.CoordinateSystems.ProjectionParameter("latitude_of_origin", 0.0));
            parameters.Add(new GeoAPI.CoordinateSystems.ProjectionParameter("central_meridian", 0.0));
            parameters.Add(new GeoAPI.CoordinateSystems.ProjectionParameter("scale_factor", 1.0));
            parameters.Add(new GeoAPI.CoordinateSystems.ProjectionParameter("false_easting", 0.0));
            parameters.Add(new GeoAPI.CoordinateSystems.ProjectionParameter("false_northing", 0.0));

            GeoAPI.CoordinateSystems.IProjection projection = csFact.CreateProjection("Google Mercator", "mercator_1sp", parameters);
            GeoAPI.CoordinateSystems.IGeographicCoordinateSystem wgs84 = csFact.CreateGeographicCoordinateSystem(
                "WGS 84", ProjNet.CoordinateSystems.AngularUnit.Degrees,
                ProjNet.CoordinateSystems.HorizontalDatum.WGS84,
                ProjNet.CoordinateSystems.PrimeMeridian.Greenwich,
                new GeoAPI.CoordinateSystems.AxisInfo("north", GeoAPI.CoordinateSystems.AxisOrientationEnum.North),
                new GeoAPI.CoordinateSystems.AxisInfo("east", GeoAPI.CoordinateSystems.AxisOrientationEnum.East)
            );

            GeoAPI.CoordinateSystems.IProjectedCoordinateSystem epsg900913 = csFact.CreateProjectedCoordinateSystem("Google Mercator", wgs84, projection,
                ProjNet.CoordinateSystems.LinearUnit.Metre, new GeoAPI.CoordinateSystems.AxisInfo("East", GeoAPI.CoordinateSystems.AxisOrientationEnum.East),
                new GeoAPI.CoordinateSystems.AxisInfo("North", GeoAPI.CoordinateSystems.AxisOrientationEnum.North)
            );

            return epsg900913;
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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