Help with reprojection

Topics: SharpMap v2.0
Feb 3, 2009 at 5:08 PM
Hi list,
I'm using the latest Sharpmap 2 revision (http://sharpmapv2.googlecode.com/svn/trunk/) .
I'm trying to reproject shapefiles to WGS84.
Here's my code:

GeometryServices gs = new GeometryServices();
ShapeFileProvider sf = new ShapeFileProvider(....)
.....
ICoordinateSystem srs = gs.CoordinateSystemFactory.CreateFromWkt(wktSrs);
ICoordinateSystem dst = gs.CoordinateSystemFactory.CreateFromWkt(wktDst); //WGS84
ICoordinateTransformation ics = gs.CoordinateTransformationFactory.CreateFromCoordinateSystems(srs, dst);

I'm getting an exception, in the last line, when the WKT definition (wktDst) contains the "TOWGS84" keyword:

System.NullReferenceException was unhandled
  Message="Object reference not set to an instance of an object."
  Source="GeoAPI"
  StackTrace:
       at GeoAPI.CoordinateSystems.Wgs84ConversionInfo.GetAffineTransform(IMatrixFactory`1 matrixFactory)

       ...
      at ProjNet.CoordinateSystems.Transformations.CoordinateTransformationFactory`1.GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformationFactory.CreateFromCoordinateSystems(ICoordinateSystem source, ICoordinateSystem target)

I need the TOWGS84 clause for a better reprojection approximation on my area of interest...
Is there any other way to have more accuracy?

Thanks,

Paolo
Coordinator
Feb 3, 2009 at 5:16 PM
Edited Feb 3, 2009 at 5:16 PM
Hi Paolo, can you post the wkt for src and dest coordinate reference systems cheers jd
Feb 3, 2009 at 5:34 PM
Hi john, thanks for answering

wktSrs (UTM 32 N with "false_northing" = -4000000 and "towgs84" keyword)

PROJCS["LGD2006 / UTM zone 32N",GEOGCS["LGD2006",DATUM["Libyan_Geodetic_Datum_2006",SPHEROID["International 1924",6378388,297,AUTHORITY["EPSG","7022"]],TOWGS84[-87,-98,-121,0,0,0,0],AUTHORITY["EPSG","6754"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4754"]],PROJECTION["Transverse_Mercator"],PARAMETER["latitude_of_origin",0],PARAMETER["central_meridian",9],PARAMETER["scale_factor",0.9996],PARAMETER["false_easting",500000],PARAMETER["false_northing",-4000000],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AUTHORITY["EPSG","3199"]]

wktDst (WGS84 EPSG: 4326):

GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],TOWGS84[0,0,0,0,0,0,0],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]

Paolo

Coordinator
Feb 3, 2009 at 9:43 PM
Hi Paolo, I will look into it asap.. cheers jd
Coordinator
Feb 3, 2009 at 11:32 PM
Hi Paolo, I have tracked down a few ommisions and implemented a few methods and can now run your test case above without error.. Get the latest code and hopefully you can too ;) hth jd
Feb 4, 2009 at 2:28 PM
Edited Feb 4, 2009 at 2:33 PM
Hi John, thanks for your interest.
I've checked out the last revision, but I'm still having problems when I try to set the shape's coordinate transformation:

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

System.NotImplementedException was unhandled
  Message="The method or operation is not implemented."
  Source="ProjNet"
  StackTrace:
       at ProjNet.CoordinateSystems.Transformations.DatumTransform`1.Transform(ICoordinate coordinate)
       at ProjNet.CoordinateSystems.Transformations.ConcatenatedTransform`1.Transform(ICoordinate coordinate)
       at ProjNet.CoordinateSystems.Transformations.ConcatenatedTransform`1.Transform(ICoordinate coordinate)
       at ProjNet.CoordinateSystems.Transformations.CoordinateTransformation`1.GeoAPI.CoordinateSystems.Transformations.ICoordinateTransformation.Transform(IExtents extents, IGeometryFactory factory)
       at SharpMap.Data.Providers.ShapeFile.ShapeFileProvider.OnPropertyChanged(PropertyDescriptor property)
       at SharpMap.Data.Providers.ProviderBase.set_CoordinateTransformation(ICoordinateTransformation value)
       ...


Paolo
Coordinator
Feb 4, 2009 at 3:12 PM
Hi Paolo, unfortunately I think you have reached an area that is yet to be completed..