如何计算地理点和给定面之间的距离(以米为单位)?
2022-09-03 14:35:14
首先,我是 GIS 新手,所以请原谅任何错误。我需要发现纬度和经度点与纬度/经度多边形(常规或非常规)之间的距离。确切地说,我需要发现从给定点到多边形边界内点的最小距离,如下图所示。在此示例中,从点到面的距离越近,即 。注意:我不需要点,只需要最小距离。p
d
经过一些阅读,我使用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);
}
}