简体   繁体   English

如何计算地理位置和给定多边形之间的距离(以米为单位)?

[英]How to calculate the distance in meters between a geographic point and a given polygon?

First of all, I'm new to GIS, so pardon any mistakes. 首先,我是GIS的新手,所以请原谅任何错误。 I need to discover the distance between a latitude and longitude point and a latitude/longitude polygon (regular or not). 我需要发现一个纬度和经度点与一个纬度/经度多边形(规则与否)之间的距离。 Precisely, I need to discover the minimal distance from a given point to a point in the polygon's boundary, as illustrated below. 精确地,我需要发现从给定点到多边形边界中的点的最小距离,如下所示。 In the example, the closer distance from point p to the polygon is d . 在该示例中,从点p到多边形的更近距离为d Note: I don't need the point, just the minimum distance. 注意:我不需要这个点,只需要最小距离即可。

问题图

After some reading, I've come up with the following minimum working example using the GeoTools API. 阅读后,我使用GeoTools API提出了以下最低工作示例。 However, I think I'm messing up in the output. 但是,我想我搞砸了输出。 Can anyone enlight me on how to get the minimum distance between a point and polygon in mteres? 有人能启发我如何获得以点为单位的点和多边形之间的最小距离吗?

MWE.java: 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);

    }
}

So what you are doing is correct, but it will return distance in geodetic units (degrees of arc) rather than metres. 因此,您所做的是正确的,但是它将返回以大地测量单位(弧度)而不是米为单位的距离。 You have two options: 您有两种选择:

  1. transform the point and the polygon geometries to a planar reference system http://docs.geotools.org/latest/tutorials/geometry/geometrycrs.html 将点和多边形的几何形状转换为平面参考系统http://docs.geotools.org/latest/tutorials/geometry/geometrycrs.html
  2. Use the GeodeticCalculator http://docs.geotools.org/stable/userguide/library/referencing/calculator.html 使用GeodeticCalculator http://docs.geotools.org/stable/userguide/library/referencing/calculator.html

To use the GeodeticCalculator you will need to determine the closest point on the polygon boundary to your point. 要使用GeodeticCalculator,您需要确定多边形边界上最接近您的点的点。 eg DistanceOp.closestPoints(geo, p)[0] 例如, 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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 更快速地计算两点之间的地理距离 - Quicker way to calculate geographic distance between two points 如何快速计算在给定距离内哪些点 - How to quickly calculate what points are within a given distance of my point 如何计算两个给定点和给定距离之间的点? - How to calculate the points between two given points and given distance? 如何计算路径上两点之间的距离 - How to calculate distance between two point over a path 计算与另一个纬度/经度点有米距离的纬度和经度 - Calculate latitude and longitude having meters distance from another latitude/longitude point 如何在经纬度两点之间推进X距离(米)? - How to advance X distance (meters) between two points of latitude and longitude? 给定第一个点和距离,如何计算第二个点的纬度/经度? - How to calculate the lat/lng of a 2nd point given 1st point and distance? 给定点与点之间的距离,如何从给定点查找其纬度和经度? - How to find the latitude and longitude of a point from a given point, given the distance between the two? 如何在谷歌地图上绘制一个多边形(矩形),距离用户输入点的距离(米) - How to draw a Polygon (Rectangle) on Google Maps with defined distance (Meters) from user's input points 如何在处理中计算两个给定点之间的点? - How can I calculate a point between two given points in processing?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM