Coordinate transformation in SharpMap

Topics: General Topics
Dec 1, 2008 at 2:44 PM
Edited Dec 1, 2008 at 4:37 PM
I'm a student and I'm developing an open source Shape2Kml conversion tool.
Just a question:
Does it is possibile, with SharpMap, to apply a 'once-and-for-all' coordinate transformation to shape files, given two EPSG codes or two WKT definitions (like OGR)?

Best regards,

Dec 1, 2008 at 9:22 PM

Hi Paulo, do you mean transform a shapefile into a new coordinate system and then save it as a new shapefile? If so, the answer is yes with v2 of sharpmap.

If this is not what you mean, can you explain further

hth jd

Dec 1, 2008 at 9:37 PM
Hi John, thanks for answering.
Yes, this is exaclty what I mean.
Do you know if there are any samples?

Best regards,

Dec 2, 2008 at 8:58 AM
Hi Paulo, there aren't may examples overall at the moment - it is still in the early adopter stages. However you would probably start with an instance of SharpMap.Utilities.GeometryServices which would give you access to an ICoordinateSystemFactory an ICoordinateTransformationFactory and an IGeometryFactory.
Use the ICoordinateSystemFactory to create the coordinate systems from the wkt.
Use the ICoordinateTransformationFactory to build the transform between the coordinate systems.
use a SharpMap.Data.Providers.ShapeFileProvider to open your shapefile use another one to create your target shapefile (there is a demo for this)
read through the src copying the attribute table to the other and applying the transform to the geometry
hth jd
Dec 3, 2008 at 2:44 PM
Hi John, I've tried to follow your steps:
GeometryServices gs = new GeometryServices();
ShapeFileProvider sf = new ShapeFileProvider(path, gs.DefaultGeometryFactory, gs.CoordinateSystemFactory);

ICoordinateSystem srs = gs.CoordinateSystemFactory.CreateFromWkt(sf.SpatialReference.Wkt);
ICoordinateSystem dst = gs.CoordinateSystemFactory.CreateFromWkt(
@"GEOGCS[""Lat Long WGS84"",DATUM[""D_WGS84""," +
@"SPHEROID[""World_Geodetic_System_of_1984"",6378137.0,298.257222932867]]," +

ICoordinateTransformation ics = gs.CoordinateTransformationFactory.CreateFromCoordinateSystems(srs, dst);
sf.CoordinateTransformation = ics;

However, when I try to read a shape geometry, I'm getting a NotImplementedException():
System.NotImplementedException was unhandled

  Message="The method or operation is not implemented."



       at ProjNet.CoordinateSystems.Transformations.ConcatenatedTransform`1.Transform(ICoordinate coordinate)
Same thing if I use the ICoordinateTransformation.MathTransform.Transform for transforming a single coordinate.
I'm using the latest svn version, what am I doing wrong?

Dec 3, 2008 at 3:00 PM
Hi Paulo, not all transforms have been implemented yet..
Dec 3, 2008 at 3:52 PM
I've just written the missing method in the ProjNet library, and now everything seems to work.
For all people who are interested, just replace the ProjNet.CoordinateSystems.Transformations.ConcatenatedTransform`1.Transform(ICoordinate coordinate) method with this one:
public override ICoordinate Transform(ICoordinate coordinate)
    foreach (ICoordinateTransformation<TCoordinate> ct in _transforms)

        coordinate = ct.MathTransform.Transform(coordinate);

    return coordinate;

Thanks for your help!


Dec 3, 2008 at 4:25 PM
Thanks Paulo - I have added it to the src..