[GIS] Transform for geometry in JTS

coordinate systemgeotoolsjts-topology-suite

I am using JTS in my application, and I want to transform the geometry from longitude and latitude to pixel.

And the algorithm for this translation has been providered by an interface:

public double[] fromLngLatToPixel(double lat, double lng);

Now I have to read the coordinates for the source geometry ,transform the coordinates and then create a new geometry.

However, I found that JTS has a transfrom method like this:

public static Geometry transform(Geometry geom, MathTransform transform);

But I do not know to to implement the MathTransform according to fromLngLatToPixel.

Any suggestion?

Best Answer

If you really want to know the maths behind creating your own transform then you will want to follow the Affine Transform tutorial.

However, since you tag GeoTools in your question, you can take the shortcut of using RenderUtilities.worldToScreenTransform. You simply pass in the bounds of the screen in world coordinates and the size of the screen as a Rectangle.

public static AffineTransform worldToScreenTransform(ReferencedEnvelope mapExtent,
                                                 Rectangle paintArea)