2016-08-23 43 views
0

我刚刚开始使用shapefiles。我有一个shapefile,其中每个对象都是一个多边形。我想要生成一个新的shapefile,其中每个多边形的几何图形都由其质心替换。有我的代码。在生成具有geopandas的形状文件时引发ValueError

当我运行该脚本,我结束了raise ValueError("Geometry column cannot contain mutiple " ValueError: Geometry column cannot contain mutiple geometry types when writing to file. 我不明白什么是错的。任何帮助?

回答

1

问题是您正在使用几何体的字符串表示形式填充几何体字段,而不是几何形状对称。

无需转换为wkt。您的循环可能会改为:

for i,r in shp.iterrows(): 
    index.append(i) 
    centroid = r['geometry'].centroid 
    centroids.append(centroid) 

但是,根本不需要遍历地理数据框。您可以创建一个新的shapefile质心,如下所示:

df=gp.GeoDataFrame(data=shp, geometry=shp['geometry'].centroid) 
df.to_file(outfile) 
相关问题