形状层叠的联合-返回的多边形过多

时间:2019-01-31 08:53:21

标签: python-3.x union polygon shapely

我正在尝试使用Shapely的cascaded_union函数合并约4,000个多边形。此函数的输出是在我的情况下,这是正常的,因为许多输入多边形不重叠一个多面。

但是,当我绘制输出时,我可以清楚地看到其中包含一些小的多边形,而这些多边形属于更大的多边形(请参见下面的屏幕截图)。在我看来,这些小多边形应该被排除在联盟。

下面是代码

的样品
# Take a union of my list of 4,000 polygons
polygons = [Polygon(p) for p in df["polygon"]]
union = cascaded_union(polygons)
# The returned union has a len of around 700 elements

# I then mapped the output using Folium
# I thus have to create a feature collection with all my polygons
def makeFeature(xs,ys,index):
    lps = [p for p in zip(*(xs,ys))]
    feature = dict()
    feature["type"] = "Feature"
    feature["geometry"] = dict()
    feature["geometry"]["type"] = "Polygon"
    feature["geometry"]["coordinates"] = list()
    feature["geometry"]["coordinates"].append(lps)
    feature["properties"] = dict()
    feature["properties"]["name"] = "{}".format(index)
    return feature
def makeFeatureCollection(lfeatures):
    collec = dict()
    collec["type"] = "FeatureCollection"
    collec["features"] = lfeatures
    return json.dumps(collec,indent=3)
# Make the feature
lfeatures = list()
for index,el in enumerate(union):
    xs, ys = el.exterior.coords.xy
    feature = makeFeature(xs,ys,index)
    lfeatures.append(feature)
collec = makeFeatureCollection(lfeatures)
# Draw it
m = folium.Map(location=[df["lat_center"][0],df["lon_center"][0]],zoom_start=3)
folium.GeoJson(collec).add_to(m)
m.save(outmap+"test_union.html")

下面是输出

的一部分的屏幕截图

Map

为什么会这样?

预先感谢

马特

0 个答案:

没有答案
相关问题