Coordinate Conversion

Topics: General Topics
Aug 10, 2006 at 7:52 PM
I think there is a "correct" way to do this coordinate conversion using well known text, but I can't figure out how. Everything I'm setting in the parameters I copied from the well known text string at the bottom.

Could someone show me how to make the conversion without hacking the sources?

(To make this work I changed TransverseMercator and MapProjection from internal to public.)

private void btProject_Click(object sender, EventArgs e)
{
//CoordinateSystemFactory cFac = new CoordinateSystemFactory();
//ICoordinateSystem bermuda = cFac.CreateFromWkt(txtWKT.Text);

List<ProjectionParameter> parameters = new List<ProjectionParameter>(5);
parameters.Add(new ProjectionParameter("latitudeoforigin", 32));
parameters.Add(new ProjectionParameter("central_meridian", -64.75));
parameters.Add(new ProjectionParameter("scale_factor", 1));
parameters.Add(new ProjectionParameter("false_easting", 550000));
parameters.Add(new ProjectionParameter("false_northing", 100000));
//gleened from Ellipsoid
//_SemiMinorAxis = (1.0 - (1.0 / InverseFlattening)) * semiMajorAxis
parameters.Add(new ProjectionParameter("semi_minor", (1.0 - (1.0 / 298.257223563)) * 6378137.0));
parameters.Add(new ProjectionParameter("semi_major", 6378137.0));

TransverseMercator projection = new TransverseMercator(parameters);

SharpMap.Geometries.Point inpt = new SharpMap.Geometries.Point(Convert.ToDouble(txtLon.Text),Convert.ToDouble(txtLat.Text));
SharpMap.Geometries.Point outpt = projection.DegreesToMeters(inpt);
this.txtNorthing.Text = outpt.Y.ToString();
this.txtEasting.Text = outpt.X.ToString();

}



PROJCS"Bermuda_2000_National_Grid",GEOGCS["GCS_Bermuda_2000",DATUM["D_Bermuda_2000",SPHEROID["WGS_1984",6378137.0,298.257223563]],PRIMEM["Greenwich",0.0],UNIT["Degree",0.0174532925199433]],PROJECTION["Transverse_Mercator"],PARAMETER["False_Easting",550000.0],PARAMETER["False_Northing",100000.0],PARAMETER["Central_Meridian",-64.75],PARAMETER["Scale_Factor",1.0],PARAMETER["Latitude_Of_Origin",32.0],UNIT["Meter",1.0]

Developer
Aug 14, 2006 at 4:04 PM
You must use the factories to make a projection, but use the corrent name of the mercator projection (no need to hack it).
The correct projection names are listed in the last column here: http://www.codeplex.com/Wiki/View.aspx?ProjectName=SharpMap&title=Which%20projections%20are%20supported

What was wrong with using the WKT parsers that you have commented out? Using that will save you a lot of troubles.

Furthermore, you might want to check the Wiki regarding transformations here:
http://www.codeplex.com/Wiki/View.aspx?ProjectName=SharpMap&title=Apply%20on%20the%20fly%20transformation%20to%20a%20layer