【发布时间】: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);
}
...
到这里为止。
但是,我怎样才能找到一个点和一条多线串而不是多边形的海岸线之间的最近距离。 或者,如果我有线串?
我应该遵循什么方法?LocationIndexedLine 和 LinearLocation 呢?
【问题讨论】: