I’m using NetTopologySuite 2.5.0. I have a Geometry, say a Point at (1.57554173300002, 42.646007512) with an SRID of 4326.
I would like to change the SRID to 3857, so a Point at (175388.50344111404, 5258244.862258436).
However, when I change the SRID to 3857, the new Point has the correct SRID but the Point hasn’t changed. I have the same behavior with (Multi)Polygons as well.
Am I not creating/reassigning the SRID correctly? Does the GeometryFactory
require a different/additional step to do this? I know many change the SRID for their Geometry objects so I expect many have solved this already. Thank you in advance.
Example 1, changing SRID directly
const double inputX = 1.57554173300002;
const double inputY = 42.646007512;
var point = new Point(new Coordinate(inputX, inputY))
{
SRID = 3857
};
Console.WriteLine($"x = {point.X}, y = {point.Y}");
// Prints "x = 1.57554173300002, y = 42.646007512"
Example 2, using GeometryFactory
const double inputX = 1.57554173300002;
const double inputY = 42.646007512;
var factory = new GeometryFactory(new PrecisionModel(), 3857);
var point = factory.CreatePoint(new Coordinate(inputX, inputY));
Console.WriteLine($"x = {point.X}, y = {point.Y}");
// Prints "x = 1.57554173300002, y = 42.646007512"
NetTopologySuite does not perform coordinate transformation on its own. You will have to use other libraries like
- ProjNet
- SharpProj
- DotSpatial.Projections
- …
to achieve that. (See: https://github.com/NetTopologySuite/NetTopologySuite/issues/771)