【发布时间】:2017-10-18 03:22:38
【问题描述】:
所以我有一个包含一堆多边形的 shp 文件。在这种情况下,多边形是一片内陆水域(如湖泊之类的东西)。
我的系统正在跟踪一个移动的物体,所以为了确定这个物体是什么,我想看看这个物体是在水中还是在陆地上,以及它离最近的海岸有多远(是的,如果它在或出水)。我会不时从对象中抽取一个样本点并对其进行测试。
系统是Java编写的,我已经导入了GeoTools snapshot 17。但是如果其他utils更容易使用,没有要求使用这个。
要测试该点是否在水中(即在多边形内),此方法有效:
private void findPolygonsForPoint(Coordinate point) {
Filter filter = null;
SimpleFeatureIterator iterator = null;
try {
filter = CQL.toFilter("CONTAINS(the_geom, POINT(" + point.x + " " + point.y + "))");
SimpleFeatureCollection collection = source.getFeatures(filter);
if(collection.size() < 1) {
System.out.println(coordinate2String(point) + " is NOT in a polygon");
} else {
System.out.println(coordinate2String(point) + " IS in a polygon");
insidePolygon++;
iterator = collection.features();
while(iterator.hasNext()) {
SimpleFeature feature = iterator.next();
//find nearest edge of the polygon
}
}
} catch(CQLException e) {
aLog.error("", e);
} catch(IOException e) {
aLog.error("", e);
} finally {
if(iterator != null) {
iterator.close();
}
}
}
现在问题:
1) 如果点不在多边形中,我如何在源中找到最近的多边形(作为 SimpleFeatureSource)?
2) 如何找到距离最近的多边形边缘的距离?
任何帮助将不胜感激!尤其是代码示例——我对数学和几何有点生疏了。
谢谢。
【问题讨论】:
标签: java polygon distance geotools