2

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?

1

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)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.