Geographic Point to Projection point

Topics: SharpMap Project
Aug 7, 2008 at 8:34 AM
Hi, I have Vector Layer: SharpMap.Layers.VectorLayer laySelected = new SharpMap.Layers.VectorLayer("tracker102_layer"); Collection<SharpMap .Geometries.Geometry=""> geoList = new Collection<SharpMap .Geometries.Geometry="">(); Collection<SharpMap .Geometries.Point=""> geoPoints = new Collection<SharpMap .Geometries.Point="">(); foreach (CDataItem di in lst) geoPoints.Add(new SharpMap.Geometries.Point(di.Lon, di.Lat)); SharpMap.Geometries.LineString ls = new SharpMap.Geometries.LineString(geoPoints); laySelected.DataSource = new SharpMap.Data.Providers.GeometryProvider(ls); All other map layers in Mercator projection, but my laySelected in Gepgraphic Projection, How transform Geographic points into projection points ?
Aug 7, 2008 at 10:56 AM
Hi artemon, You need to apply a coordinate transformation to the layer. Please see in short you would need to use a CoordinateTransformationFactory to create a transform between your source coordinate system and the target coordinate system. Then you set the CoordinateTransformation property of the layer to the transformation you have created and everything else should drop into place...

Having the coordinate systems described in wkt will be a big help here as you can create the coordinate system from this (using a CoordinateSystemFactory) otherwise you will have to build it by hand..

hth jd
Aug 7, 2008 at 1:14 PM
Hi John,

that sounds promissing, but i'm not that fumiliar with the subject. Is there a simple howto or example available?



Aug 7, 2008 at 3:09 PM
Hi Jan, the only one i can think of is on Morten's (the original SharpMap developer) site you can skip a lot of the creation of Coordinate system if you have the wkt. hth jd
Aug 7, 2008 at 9:46 PM
Thanks John, i will look at that.
Aug 8, 2008 at 4:27 AM
Hi, This working: public static IGeographicCoordinateSystem GetLatLonPlane() { CoordinateSystemFactory cFac = new CoordinateSystemFactory(); //Define datums HorizontalDatum wgs72 = HorizontalDatum.WGS72; HorizontalDatum ed50 = HorizontalDatum.ED50; //Define geographic coordinate systems IGeographicCoordinateSystem gcsWGS84 = cFac.CreateGeographicCoordinateSystem("WGS84 Geographic", AngularUnit.Degrees, HorizontalDatum.WGS84, PrimeMeridian.Greenwich, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); return gcsWGS84; } public static ICoordinateTransformation Transform2Mercator(ICoordinateSystem source) { CoordinateSystemFactory cFac = new SharpMap.CoordinateSystems.CoordinateSystemFactory(); System.Collections.Generic.List <ProjectionParameter> parameters = new System.Collections.Generic.List <ProjectionParameter>(5); parameters.Add(new ProjectionParameter("latitude_of_origin", 0)); parameters.Add(new ProjectionParameter("central_meridian", 0)); parameters.Add(new ProjectionParameter("false_easting", 0)); parameters.Add(new ProjectionParameter("false_northing", 0)); IProjection projection = cFac.CreateProjection("Mercator", "Mercator_2SP", parameters); IProjectedCoordinateSystem coordsys = cFac.CreateProjectedCoordinateSystem("Mercator", source as IGeographicCoordinateSystem, projection, LinearUnit.Metre, new AxisInfo("East", AxisOrientationEnum.East), new AxisInfo("North", AxisOrientationEnum.North)); return new CoordinateTransformationFactory().CreateFromCoordinateSystems(source, coordsys); } ... ... IGeographicCoordinateSystem latlon = GetLatLonPlane(); laySelected.CoordinateTransformation = Transform2Mercator(latlon); // laySelected my own vector layer NOT FROM shp File (from geometry)