Sync Shapefile Data with Background Map

Jan 15, 2011 at 1:47 PM

Hello! Me yet again...

I was able to implement BruTile in our programm and it works so far.

The only problem is that the Shapefile Output does not  sync to the Background Map (Vienna lies in front of the African coast for example)

I dont know if this is a transformation or a coordination problem or if it is along a problem with the ShapeFiles.

Any help would be very appreciated!

Kind Regards

Marc Reinmayr

Jan 17, 2011 at 2:15 PM

Hi nahro1001

It's a transformation problem. You have to reproject your shapefiles to your tile source coordinate system.

I did this for reprojecting WGS84 to Google Maps.

private static ICoordinateTransformation ReProjection(ICoordinateSystem source, ICoordinateSystem target)
    {
        CoordinateTransformationFactory ctFac = new CoordinateTransformationFactory();
        return ctFac.CreateFromCoordinateSystems(source, target);
    }
    private static IGeographicCoordinateSystem c_WGS84()
    {
        CoordinateSystemFactory csFac = new CoordinateSystemFactory();
        IGeographicCoordinateSystem wgs84 = csFac.CreateGeographicCoordinateSystem(
           "WGS 84", AngularUnit.Degrees, HorizontalDatum.WGS84, PrimeMeridian.Greenwich,
           new AxisInfo("South", AxisOrientationEnum.South), new AxisInfo("West", AxisOrientationEnum.West));
        return wgs84;
    }
    private static IProjectedCoordinateSystem c_EPSG900913() // Google Mercator
    {
        CoordinateSystemFactory csFac = new CoordinateSystemFactory();
        List<ProjectionParameter> parameters = new List<ProjectionParameter>();
        parameters.Add(new ProjectionParameter("semi_major", 6378137.0));
        parameters.Add(new ProjectionParameter("semi_minor", 6378137.0));
        parameters.Add(new ProjectionParameter("latitude_of_origin", 0.0));
        parameters.Add(new ProjectionParameter("central_meridian", 0.0));
        parameters.Add(new ProjectionParameter("scale_factor", 1.0));
        parameters.Add(new ProjectionParameter("false_easting", 0.0));
        parameters.Add(new ProjectionParameter("false_northing", 0.0));
        IProjection projection = csFac.CreateProjection("Google Mercator", "mercator_1sp", parameters);

        IProjectedCoordinateSystem epsg900913 = csFac.CreateProjectedCoordinateSystem(
            "Google Mercator", c_WGS84(), projection, LinearUnit.Metre,
            new AxisInfo("West", AxisOrientationEnum.West), new AxisInfo("South", AxisOrientationEnum.South));
        return epsg900913;
    }

 then...

layer.CoordinateTransformation = ReProjection(c_WGS84(), c_EPSG900913());
Hope this helps you.
Jan 18, 2011 at 12:20 PM

Thank you for your help.

Now I know at least where the problem is.

I only have one question do I have to set the Projection depending on my source CoordinateSystem (from the Shapefile)

or does it project any kind of Coordinate System to the one specified?

Kind Regards

Marc Reinmayr

Jan 18, 2011 at 1:58 PM

Marc

You have to know exactly your source and target coordinate system in order to reproject.

You can look the SharpMap trunk at WinFormSamples project --> Samples --> TileLayerSample.cs to find how to transform to OSM projection. 

Jan 18, 2011 at 6:49 PM

Thanks again I now know how to project and how to implement it in my programm

The only problem I am facing is that not all shapefiles have there projection data with them

and I therefore not always know how to to project it.

I will implement it nethertheless to enable users that have that file to use the background map anyway.

The only question for me would be, if I dont have the CS, can I manually adjust the Coordinates of the

Layers so the user could align the map at least a little?

Anyway thank you for your fast help!

Greets

Marc

Jan 18, 2011 at 7:20 PM

I'm not sure if I completely get your question. Sorry, my understanding of english isnt 100%.

You can't manually adjust layer CS with SharpMap, I'd suggest to define the projection for each one of your shapefiles with no CS with third party GIS tools.

I do it myself with ArcGIS but I'm sure you can do it with another free tool.