如何在 GeoDataFrame 中创建一个 ---
dict
可能是最好的--- 在顶点处入射。多边形将相交但永远不会交叉。
import geopandas as gpd
from shapely.geometry import Polygon
import matplotlib.pyplot as plt
polys = gpd.GeoSeries([Polygon([(0,0), (2,0), (2, 1.5), (2,2), (0,2)]),
Polygon([(0,2), (2,2), (2,4), (0,4)]),
Polygon([(2,0), (5,0), (5,1.5), (2,1.5)]),
Polygon([(3,3), (5,3), (5,5), (3,5)])])
fp = gpd.GeoDataFrame({'geometry': polys, 'name': ['a', 'b', 'c', 'd']})
fig, ax = plt.subplots(figsize=(5, 5))
fp.plot(ax=ax, alpha=0.3, cmap='tab10', edgecolor='k',)
fp.apply(lambda x: ax.annotate(text=x['name'], xy=x.geometry.centroid.coords[0], ha='center'), axis=1)
plt.show()
for i, row in fp.iterrows():
oring = list(row.geometry.exterior.coords)#, row['ground_height']
if row.geometry.exterior.is_ccw == False:
#-- to get proper orientation of the normals
oring.reverse()
for (j, v) in enumerate(oring[:-1]):
print([oring[j][0], oring[j][1], row['name']])
[0.0, 0.0, 'a']
[2.0, 0.0, 'a']
[2.0, 1.5, 'a']
[2.0, 2.0, 'a']
[0.0, 2.0, 'a']
[0.0, 2.0, 'b']
[2.0, 2.0, 'b']
[2.0, 4.0, 'b']
[0.0, 4.0, 'b']
[2.0, 0.0, 'c']
[5.0, 0.0, 'c']
[5.0, 1.5, 'c']
[2.0, 1.5, 'c']
[3.0, 3.0, 'd']
[5.0, 3.0, 'd']
[5.0, 5.0, 'd']
[3.0, 5.0, 'd']
所以在第一个顶点我们应该有:
一个;
第二:a,c;
第三:a,c;
第四:a,b;
5rd: a, b;
第 6:b,a;
第 7:b,a;
第八名:b;等等