Geotools distance calculation is not performed without convergence exception for multiple lat lon points

I have several points that make the getOrthodromicDistance method fail with the exception in geotools lib, while these points are real lat lon points:

The point that throws the exception (lat, lon):

val p1= (5.318765,-75.786109) val p2= (-6.32907,106.09254) 

for example, an exception: There is no convergence for points 75 ° 47.2'W 06 ° 19.7 and 106 ° 05.6'E 05 ° 19.1'N. java.lang.ArithmeticException: there is no convergence for the points 75 ° 47.2'W 06 ° 19.7 and 106 ° 05.6'E 05 ° 19.1'N. at org.geotools.referencing.GeodeticCalculator.computeDirection (GeodeticCalculator.java:1073)

Code used in Scala:

  def latlonDistance(p1:(Double,Double), p2:(Double,Double)):Double={ val world= new GeodeticCalculator() world.setStartingGeographicPoint(p1._2, p2._1) world.setDestinationGeographicPoint(p2._2, p1._1) world.getOrthodromicDistance } 

Note. My point format passed in latlonDistance (lat, lon), as mentioned above, while setStartingGeographicPoint, setDestinationGeographicPoint need (lon, lat) order.

Used Version:

  <dependency> <groupId>org.geotools</groupId> <artifactId>gt-referencing</artifactId> <version>13.2</version> </dependency> 

In python, it works as expected:

 >>> from geopy.distance import vincenty >>> pt1= [5.318765,-75.786109] >>> pt2= [-6.32907,106.09254] >>> vincenty(pt1 , pt2) Distance(19791.6883647) 

This is the orthodromicDistance method in org.geotools.referencing.datum.DefaultEllipsoid that does not converge. Any workarounds?

+4
source share
1 answer

The problem is that this is not a simple calculation, since the Vincenti algorithm is an iterative process, and some sets of points do not necessarily converge (within the established limit).

There are two possible solutions: 1 - edit the GeodeticCalculator to increase the number of possible iterations from 12 to 15, this works in this case, but I can not guarantee it in others. Or 2, use a different algorithm, following the links from the answers to this question . I found the GeographicLib library in Sourceforge and used this instead of your glasses. This is written by the author (@cffk) of a document related to another answer.

For your purposes this gives a very reasonable view of 20004 km.

+2
source

All Articles