【问题标题】:Geotools distance calculation fails with no convergence exception for several lat lon pointsGeotools 距离计算失败,几个纬度点没有收敛异常
【发布时间】:2015-11-05 00:36:52
【问题描述】:

我有很多点导致 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.referenceencing.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方法。有什么解决方法吗?

【问题讨论】:

    标签: exception geotools convergence


    【解决方案1】:

    问题在于这不是一个简单的计算,因为 Vincenty 算法是一个迭代过程,并且一些 sets of points 不一定会收敛(在限制集内)。

    有两种可能的解决方案 1 - 编辑 GeodeticCalculator 以将可能的迭代次数从 12 次增加到 15 次,这在这种情况下有效,但我不能保证在其他情况下。或者 2 使用另一种算法,遵循来自 this question's answers 的链接,我在 Sourceforge 找到了 GeographicLib library 并将其用于您的观点。它是由另一个答案中链接到的paper 的作者 (@cffk) 编写的。

    根据您的观点,它给出了一个非常合理的 20004 公里。

    【讨论】:

    • 如果您想观看,我已经提出了错误报告 (osgeo-org.atlassian.net/browse/GEOT-5191)
    • 是的,我也对其进行了研究,GeographicLib 库是一个候选解决方案,它运行良好,因为它实现了不同的算法,一个可以收敛任何一对点的算法,而 Vincenty 的设计却没有。我会看这个bug thnx!
    • 请找到一组130对点,也可以作为测试用例bad points
    • 我已经提交了这个pull request 供geotools 解决这个问题。请试一试。 (目前,构建检查失败;但我认为这与补丁无关。)
    • 感谢@cffk,这对于 GeoTools 14+ 将不再是问题
    猜你喜欢
    • 1970-01-01
    • 2011-08-16
    • 2012-10-13
    • 2012-01-26
    • 2011-02-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多