【问题标题】:distance between multilinestring and point多线串和点之间的距离
【发布时间】:2017-07-17 12:58:04
【问题描述】:

如果我必须计算点和多边形之间的最近距离(例如点和湖 (naturalearthdata.com)),我可以这样做(取自 here):

...
LocationIndexedLine line = new LocationIndexedLine(((MultiPolygon)    feature.getDefaultGeometry()).getBoundary());
LinearLocation here = line.project(coordinate);
Coordinate point = line.extractPoint(here);
...

和:

      ...
      NearestPolygon polyFinder = new NearestPolygon(features);

      GeometryFactory gf = JTSFactoryFinder.getGeometryFactory();
      Point p = gf.createPoint(new Coordinate(-49.2462798, -16.7723987));

      Point pointOnLine = polyFinder.findNearestPolygon(p);
      if (!pointOnLine.isEmpty()) {
        System.out.println(pointOnLine + " is closest to " + p);
        SimpleFeature lastMatched2 = polyFinder.getLastMatched();
        String attribute = (String) lastMatched2.getAttribute("name");
        if(attribute.isEmpty()) {
          attribute = (String) lastMatched2.getAttribute("note");
        }
        if (((Geometry) (lastMatched2.getDefaultGeometry())).contains(p)) {
          System.out.println("is in lake " + attribute);
        } else {
          System.out.println("nearest lake is " + attribute);
        }
...

到这里为止。

但是,我怎样才能找到一个点和一条多线串而不是多边形的海岸线之间的最近距离。 或者,如果我有线串?

我应该遵循什么方法?LocationIndexedLineLinearLocation 呢?

【问题讨论】:

    标签: java gis geotools


    【解决方案1】:

    我认为您可以通过将行更改为:

    LocationIndexedLine line = new LocationIndexedLine(((Geometry)
         feature.getDefaultGeometry()));
    

    由于某种原因,getDefaultGeometry 返回一个Object,因此您需要将其转换为有用的东西。

    【讨论】:

    • Hmm.Nice!它有效!但是(我刚刚注意到)如果我有一个“点”几何图形呢?如果我使用上面的它显示我Input geometry must be linear。如果我使用原始@ 987654326@ 它显示com.vividsolutions.jts.geom.Point cannot be cast to com.vividsolutions.jts.geom.MultiPolygon,如果我在上一行中将MultiPolygon 替换为Point,它会再次显示Input geometry must be linear。如果我有Multipoint 怎么办?非常感谢!(赞成)跨度>
    • 索引线是计算线或边界上最接近您的点的点,如果您有两个点,那么您可以简单地计算两者之间的距离,对于多点计算与每个人的距离并选择最近的
    • 我只是使用“ports.shp”而不是“lakes.shp”,因为你有here。它表明它是一个geom.Point。所以,在这种情况下你说不要使用任何 LocationIndexedLine 但只计算距离?谢谢!
    • 索引线是计算线或边界上最接近您的点的点,如果您有两个点,那么您可以简单地计算两者之间的距离,对于多点计算与每个人的距离并选择最近的
    • 好的,谢谢! (我为此打开了一个新的post)。我很难从 ports.shp 文件中读取坐标。在多边形情况下,我们使用BBOX,'ReferencedEnvelope, LocationIndexedLine`,但在这种情况下,我迷路了!
    猜你喜欢
    • 2018-04-04
    • 2021-08-02
    • 2017-01-08
    • 2017-07-06
    • 2020-04-27
    • 2020-01-26
    • 2014-01-28
    • 1970-01-01
    • 2018-05-21
    相关资源
    最近更新 更多