Geotools 距离计算失败,几个经纬度点没有收敛异常

2023-12-19

我有很多点使 getOrthodromicDistance 方法在 geotools lib 中失败并出现异常,而这些点是有效的经纬度点:

抛出异常的点(纬度,经度):

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

例如例外: 75°47,2'W 06°19,7'S 和 106°05,6'E 05°19,1'N 点没有收敛。 java.lang.ArithmeticException:点 75°47,2'W 06°19,7'S 和 106°05,6'E 05°19,1'N 没有收敛。 在 org.geotools.referencing.GeodeticCalculator.computeDirection(GeodeticCalculator.java:1073)

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
   }

注意:我在 latlonDistance 中传递的点格式是 (lat,lon) 如上所述,而 setStartingGeographicPoint、setDestinationGeographicPoint 需要 (lon,lat) 命令。

使用的版本:

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

在 python 中按预期工作:

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

这是 org.geotools.referencing.datum.DefaultEllipsoid 中的 orthodromicDistance 方法不收敛。有什么解决方法吗?


问题是这不是一个简单的计算,因为 Vincenty 算法是一个迭代过程,并且一些点集 https://en.wikipedia.org/wiki/Geodesics_on_an_ellipsoid#Software_implementations不一定收敛(在限制范围内)。

有两种可能的解决方案 1 - 编辑 GeodeticCalculator 将可能的迭代次数从 12 增加到 15,这在这种情况下有效,但我不能保证在其他情况下也有效。或者 2 使用另一种算法,遵循以下链接这个问题的答案 https://stackoverflow.com/questions/27715532/python-vincentys-inverse-formula-not-converging-finding-distance-between-poi我找到了地理图书馆 http://geographiclib.sourceforge.net/html/java/在 Sourceforge 并用它来代替你的观点。它是由作者 (@cffk) 编写的paper https://dx.doi.org/10.1007/s00190-012-0578-z链接到另一个答案。

对于您的积分,它给出了看起来非常合理的 20004 公里。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Geotools 距离计算失败,几个经纬度点没有收敛异常 的相关文章

随机推荐