我试图将shapefile转换为一个纬度和经度点的列表,这些点表示shapefile定义的每个点。使用geopandas
读取文件并使用.plot()
函数将这些点显示为一个图形,但我希望使用原始点。我试图在geopandas
.geometry
中迭代多边形,并存储多边形中的所有点。我画了这些点来测试它们是否能准确地表示出这个区域,但是它们没有。我用以下代码完成了这些:
import re
import geopandas as gpd
import matplotlib.pyplot as plt
def geoToList(geodataframe):
points = []
for s in geodataframe.geometry:iq
s = str(s)
s = re.sub('[^0-9., ]+', '', s).split(',')
s = map(lambda x: x.strip(), s)
s = map(lambda x: (float(x.split()[0]), float(x.split()[1])), s)
points.extend(list(s))
return points
habitat = gpd.read_file('desktop/species_19377/species_19377.shp')
#borough = borough.to_crs(epsg=4326)
points = geoToList(habitat)
x = [point[0] for point in points]
y = [point[1] for point in points]
plt.scatter(x, y)
plt.show() #representation of the points in all polygons
habitat.plot() #representtation of the points I want
我想要一些函数,它返回可以绘制的点列表,看起来与habitat.plot()
的输出完全相同
我的下一个想法是将图形存储为图像,并根据图形的比例分配像素值纬度和经度值,但我确信这比实际需要的要复杂。在
任何帮助都将不胜感激!在
要从一组多边形/多多边形提取所有点,可以执行以下操作:
相关问题 更多 >
编程相关推荐