使用shapefile库将Geojson转换为shapefile [英] Geojson to shapefile convertion using shapefile library
问题描述
我知道,如果shapefile
仅包含多边形,则可以从geojson
创建shapefile
,但是如果出现MultiPolygon
,则会出现以下错误:
I know I can create a shapefile
from a geojson
if the shapefile
only contains Polygons, but in case there is a MultiPolygon
I get the following error:
返回[min(x),min(y),max(x),max(y)]
return [min(x), min(y), max(x), max(y)]
TypeError:'<' 'list'和'float'**实例之间不支持**
TypeError: '<' not supported between instances of 'list' and 'float'**
在shapefile.py**
任何有关如何克服此问题的想法都将受到赞赏.
Any ideas of how I can overcome this problem would be appreciated.
谢谢.
import shapefile
shape_file_writer = shapefile.Writer(SHAPE_FILE_TYPE)
#example of field [field, "C", 200, 0]
shape_file_writer.fields = self.__get_shape_file_fields()
for feature in geojson_data["features"]:
if feature["geometry"]["type"] == "MultiPolygon":
continue
else:
shape_file_writer.poly(parts=feature["geometry"]["coordinates"], shapeType=5)
shape_file_writer.record(*feature["properties"].values())
推荐答案
经过一番搜索,我发现它是多多边形的
after some search I found that in a multi-polygon
[ 多边形_0, 多边形_1, . . ]
[ polygon_0, polygon_1, . . ]
只有 polygon_0 是实际的多边形,其余的多边形是孔. 就我而言,我根本不需要孔,所以我基本上将多面体转换为面体.
only polygon_0 is the actual polygon and the rest of polygons are holes. In my case I didn't need the holes at all so I converted multi-polygons into polygons basically.
这篇关于使用shapefile库将Geojson转换为shapefile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!