我有一个二维的双精度数组,它隐含地定义了二维有界整数晶格上的值。另外,我有 n 2D种子点(可能有非整数坐标)。我想用最接近的种子点识别每个网格点,然后将用每个种子点标识的网格点的值相加。
使用JTS / Geotools最有效的方法是什么?我已经用VoronoiDiagramBuilder
建立了Voronoi图,但我不确定如何根据它有效地分配所有网格点。
答案 0 :(得分:1)
最佳方法取决于 n 的大小和voronoi图中的多边形数量。但是,基本上你需要迭代其中一个集合,并在另一个集合中找到与之交互的元素。
假设 n 小于多边形的数量,我会做类似的事情:
// features is the collection of Voronoi polygons
// Points is the N points
Expression propertyName = filterFactory.property(features.getSchema()
.getGeometryDescriptor()
.getName());
for (Point p: points) {
Filter filter = filterFactory.contains(propertyName,
filterFactory.literal(p));
SimpleFeatureCollection sub = features.subCollection(filter);
//sub now contains your polygon
//do some processing or save ID
}
如果 n 大于多边形数量 - 反转循环并使用within
而不是包含来查找每个多边形中的所有点。