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?