我想你应该用三角形来填充这个区域。你的“三角形”只是其中的一半。如果只需要你的那一半,只需注释掉for循环的第二部分。在import numpy as np
from shapely.geometry import Polygon
from geopandas import GeoSeries
xlen = 20
ylen = 20
x0 = 0
y0 = 0
xPoints = np.arange(x0, xlen + 1, 1)
yPoints = np.arange(y0, ylen + 1, 1)
GridPoints = list((x, y) for x in xPoints for y in yPoints)
triangles = [] # list of triangles to be populated
for i in range(ylen):
for j in range(xlen):
# triangles with perpendicular angle on the bottom left
triangles.append([i + j * (ylen + 1), (i + 1) + j * (ylen + 1), i + (j + 1) * (ylen + 1)])
# triangles with perpendicular angle on the top right
triangles.append([(i + 1) + j * (ylen + 1), i + (j + 1) * (ylen + 1), (i + 1) + (j + 1) * (ylen + 1)])
polygons = [] # list of polygons to be populated
for triangle in triangles:
polygon = Polygon([GridPoints[triangle[0]], GridPoints[triangle[1]], GridPoints[triangle[2]]])
polygons.append(polygon)
gs = GeoSeries(polygons) # save polygons to geopandas GeoSeries
我将把你的多边形保存到GeoPandas GeoSeries中。结果如下:
plotted GeoSeries
使用Python Shapely创建三角网格
这篇博客展示了如何利用Python的Shapely库创建一个三角网格。通过使用numpy生成坐标点,然后通过循环构建三角形,并将其保存为Polygon对象,最终存储在GeoPandas的GeoSeries中。
2940

被折叠的 条评论
为什么被折叠?



