4

From point A, I want to check if a point B is within a certain radius from A. How calculate it usindo JTS?

I tried this:

Coordinate posicaoAtual = new Coordinate(-12.974900375893823, -38.48034163207694); 
Localidade localidade = new Localidade(-12.976353604547635, -38.47492356986686);
Geometry ponto = new GeometryFactory().createPoint(localidade.getCoordenada());
Geometry pos = new GeometryFactory().createPoint(posicaoAtual);
Geometry raio = ponto.buffer(100.0, 8); // HERE
System.out.println(raio.contains(pos));

My doubt is to know which the distance unit from the first parameter of the buffer method?

6
  • the buffer distance is in the same units as the coordinates - probably degrees in your example.
    – Ian Turton
    Jul 17, 2013 at 13:52
  • How to convert degrees in meters? Because the user will send the distance in meters. Jul 17, 2013 at 14:04
  • gis.stackexchange.com/questions/4906/…
    – Ian Turton
    Jul 17, 2013 at 14:09
  • Correcting my question: Geometry raio = ponto.buffer(METER_TO_DEGREE, 8); The buffer method receive in degree. How convert meters in degree? Jul 18, 2013 at 5:09
  • I use this calc: (PARAMETER_IN_METER * 0.00001)/1.1132 Is it acceptable? Jul 18, 2013 at 5:19

1 Answer 1

1

JTS is only for cartesian coordinates, your's are ellipsoidal. So I would say the answer is "do not use JTS for this". You would need write a method for the calculation yourself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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