如何计算地理点和给定面之间的距离(以米为单位)?

2022-09-03 14:35:14

首先,我是 GIS 新手,所以请原谅任何错误。我需要发现纬度和经度点与纬度/经度多边形(常规或非常规)之间的距离。确切地说,我需要发现从给定点到多边形边界内点的最小距离,如下图所示。在此示例中,从点到面的距离越近,即 。注意:我不需要点,只需要最小距离。pd

Problem Illustration

经过一些阅读,我使用GeoTools API提出了以下最小工作示例。但是,我认为我在输出中搞砸了。任何人都可以向我介绍如何在mteres中获取点和多边形之间的最小距离?

MWE.java:

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import com.vividsolutions.jts.geom.Point;

public class MWE {

    public static void main(String[] args) throws Exception {
        GeometryFactory gf = JTSFactoryFinder.getGeometryFactory();

        Coordinate[] c = new Coordinate[5];
        c[0] = new Coordinate(-49.242986, -16.662430);
        c[1] = new Coordinate(-49.241999, -16.664465);
        c[2] = new Coordinate(-49.239146, -16.663828);
        c[3] = new Coordinate(-49.239832, -16.661443);
        c[4] = new Coordinate(-49.242986, -16.662430);

        Geometry geo = gf.createPolygon(c);

        Point p = gf.createPoint(new Coordinate(-49.246870, -16.665493));

        double distance = geo.distance(p);

        System.out.println("Distance: " + distance);

    }
}

答案 1

因此,您所做的是正确的,但它将以大地测量单位(弧度)而不是米为单位返回距离。您有两种选择:

  1. 将点和多边形几何转换为平面参考系统 http://docs.geotools.org/latest/tutorials/geometry/geometrycrs.html
  2. 使用大地测量计算器 http://docs.geotools.org/stable/userguide/library/referencing/calculator.html

要使用大地测量计算器,您需要确定面边界上离您的点最近的点。例如:DistanceOp.closestPoints(geo, p)[0]

// adapted from http://docs.geotools.org/stable/userguide/library/referencing/calculator.html
CoordinateReferenceSystem crs = CRS.decode("EPSG:4326");
GeodeticCalculator gc = new GeodeticCalculator(crs);
gc.setStartingPosition( JTS.toDirectPosition(  DistanceOp.closestPoints(geo, p)[0], crs ) );
gc.setDestinationPosition( JTS.toDirectPosition( p, crs ) );

double distance = gc.getOrthodromicDistance();

答案 2

推荐