Basic transform from lat long to epsg:21781

Jan 11, 2013 at 10:44 AM

Hi

We're currently working on a windowsphone map app using mapsui. The map is based on the epsg:21781 projection so I thought maybe Proj4Net can help.

I'm not quite sure how to use this library to transform from a latitude longtitude provided by gps. I don't understand why BasicCoordinateTransform.Transform method takes two coordinates source and target, while I only have one latlong coordinate provided.
Take, for example lat long of: 46.732321197594587 7.6183164216221844
I guess These provided coordinates are in WGS84 which is something like SphericalMercator?

How would I now correctly transform to epsg:21781? And then, could I use the Mapsui Viewport.WorldToScreen method with these transformed coordinates to set the Viewport Center?

What steps are required to transform from one to another coordinatesystem?
Thanks for your help.



 

Coordinator
Jan 21, 2013 at 11:39 AM
Edited Jan 21, 2013 at 11:48 AM

 

var crsFactory = new Proj4Net.CoordinateReferenceSystemFactory();
var crsSource = crsFactory.CreateFromName("EPSG:4326");
var crsTarget = crsFactory.CreateFromName("EPSG:21781");

var transformFactory = new Proj4Net.CoordinateTransformFactory();
var transform = transformFactory.Create(crsSource, crsTarget);

// now you can use transform to transform your gps points.
...

 

Please excuse any typos, as this code has not seen a compiler, but it should get you there. How this behaves with MapsUI, I don't know.

The coordinate returned by the Transform function is the same that is passed as argument. I'm not sure why it is this way, the only excues I have is that it is a port of Proj4J.

Please note well: On the fly reprojection always comes with a cost. If you have any chance, circumvent it and transform your geometries beforehand.

Hth FObermaier