Dec 1, 2008 at 3:44 PM
Edited Dec 1, 2008 at 5:37 PM

Hello,
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 'onceandforall' coordinate transformation to shape files, given two EPSG codes or two WKT definitions (like
OGR)?
Best regards,
Paolo



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.
http://sharpmapv2.googlecode.com
If this is not what you mean, can you explain further
hth jd



Hi John, thanks for answering.
Yes, this is exaclty what I mean.
Do you know if there are any samples?
Best regards,
Paolo



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



Hi John, I've tried to follow your steps:
GeometryServices gs = new GeometryServices(); ShapeFileProvider sf = new ShapeFileProvider(path, gs.DefaultGeometryFactory, gs.CoordinateSystemFactory); sf.Open(false);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]]," + @"PRIMEM[""Greenwich"",0.0],UNIT[""Degree"",0.0174532925199433]]");
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."
Source="ProjNet"
StackTrace:
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?
Paolo



Hi Paulo, not all transforms have been implemented yet..



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!
Paolo



Thanks Paulo  I have added it to the src..

