问题
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