Geojson to shapefile convertion using shapefile library

▼魔方 西西 提交于 2019-12-13 03:02:27

问题


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:

return [min(x), min(y), max(x), max(y)]

TypeError: '<' not supported between instances of 'list' and 'float'**

In return self.__bbox(self._shapes) method under shapefile.py**

Any ideas of how I can overcome this problem would be appreciated.

Thanks in advance.

    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())

回答1:


after some search I found that in a multi-polygon

[ polygon_0, polygon_1, . . ]

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.



来源:https://stackoverflow.com/questions/50953209/geojson-to-shapefile-convertion-using-shapefile-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!