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

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

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

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, privacy policy and cookie policy

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