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?

Luciano Borges
  • 295
  • 2
  • 14
  • 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
  • http://gis.stackexchange.com/questions/4906/why-is-law-of-cosines-more-preferable-than-haversine-when-calculating-distance-b/4909#4909 – Ian Turton Jul 17 '13 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? – Luciano Borges Jul 18 '13 at 05:09
  • I use this calc: (PARAMETER_IN_METER * 0.00001)/1.1132 Is it acceptable? – Luciano Borges Jul 18 '13 at 05:19
  • You can't simply scale from metres to degrees or vice-versa. You need to project your coordinates. You can roll your own or use an existing library, such as this or this. Both of these are ports of Proj.4. Once you have projected coordinates, you can use JTS to your heart's content. – Rob Skelly Aug 13 '15 at 23:10

1 Answers1

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.

bugmenot123
  • 11,011
  • 3
  • 34
  • 69