2

我有一系列使用 JTS 拓扑套件创建的多边形。每个多边形是一组点、经度和纬度,形成一个形状,如下图所示。

((lat1,lon1),(lat2,lon2),....(lat1,lon1))

我想找到这些多边形邻居中的每一个,以及物理上靠近它们的其他形状。我曾想过寻找匹配点,但显然这并不适用于所有情况。我想知道是否有任何软件包可以检查多边形是否共享我可以在这种情况下使用的相同边缘?或者,如果不是,那么在 Java 中执行此操作的另一种方法。

谢谢。

4

3 回答 3

1

There was in fact a very simple way to do this. I created an arraylist containing an array of objects. The object referenced the name/id of the polygon, the actual polygon coordinates and then a string that would contain ids of any neighbours.

In JTS Topology suite there is a method that you can call on polygons called touches that returns a boolean; so I had a double for loop, going through my arraylist twice and calling the method touches on polygon(i) so:

arraylist<object[]>..
//where in the array the objects are
object[0] = id
object[1] = polygon
object[2] = neighbours

for (int i=0;i<arraylist;i++)
  for (int j=0;j<arraylist;j++)
    if (i)[1].touches(j)[1]
      update i[2]..

It's probably not the best method but it seems to work.

于 2013-01-28T11:00:54.687 回答
1

由于您正在寻找共享边,因此您可以创建一个哈希表,使用边作为键,并使用该边作为其项目的多边形列表。

然后你遍历每个多边形并填满表格。这在边数上是线性的。

然后您浏览表格并查找与多个多边形相关的边,这就是您要查找的内容。这与唯一边的数量成线性关系。

我不确定 Java 如何实现哈希表,因此获得此设置可能需要一些工作。确保对边缘进行排序,以防止边缘 (A,B) 与边缘 (B,A) 不同,这会弄乱算法。

至于库,似乎您正在尝试做的事情可能有点专业,因此不确定您是否会找到库实现,因此我概述了一个算法。

于 2013-01-27T16:31:15.567 回答
1

如果您使用 JTS 几何图形,则可以使用可与任何几何图形对象一起使用的空间关系。

如果您可以确保邻居之间至少有一个点是共同的并且它们的内部不相交,请使用触摸。

如果您不能确保内部不相交,请使用相交。根据数据源,这可能是更好的选择。

给定多边形,获取邻居的方法如下所示:

public ArrayList<Polygon> getNeighbourList(Polygon center, ArrayList<Polygon> possibleNeighbourList){
    // result list
    ArrayList realNeighbourList = new ArrayList();
    for(Polygon p : possibleNeighbourList){
        // check if current polygon is a neighbour of the center polygon by using the spatial relation touches or intersects
        if(center.intersects(p)){
            realNeighbourList.add(p);
        }
    }
    return realNeighbourList;
}
于 2016-07-11T16:25:26.823 回答