def merge_to_multi_polygon(feature_collection: str, dissolve: bool) -> geojson.MultiPolygon:
"""
Merge all geometries to a single multipolygon
:param feature_collection: geojson feature collection str containing features
:param dissolve: flag for wther to to dissolve internal boundaries.
:return: geojson.MultiPolygon
"""
parsed_geojson = GridService._to_shapely_geometries(json.dumps(feature_collection))
multi_polygon = GridService._convert_to_multipolygon(parsed_geojson)
if dissolve:
multi_polygon = GridService._dissolve(multi_polygon)
aoi_multi_polygon_geojson = geojson.loads(json.dumps(mapping(multi_polygon)))
# validate the geometry
if type(aoi_multi_polygon_geojson) is not geojson.MultiPolygon:
raise InvalidGeoJson('Area Of Interest: geometry must be a MultiPolygon')
is_valid_geojson = geojson.is_valid(aoi_multi_polygon_geojson)
if is_valid_geojson['valid'] == 'no':
raise InvalidGeoJson(f"Area of Interest: Invalid MultiPolygon - {is_valid_geojson['message']}")
return aoi_multi_polygon_geojson
评论列表
文章目录