build_shapes: replace unary union from shapely by geopandas equivalent
This commit is contained in:
parent
c25f02d681
commit
efedfa945b
@ -80,7 +80,6 @@ import pandas as pd
|
|||||||
import pycountry as pyc
|
import pycountry as pyc
|
||||||
from _helpers import configure_logging
|
from _helpers import configure_logging
|
||||||
from shapely.geometry import MultiPolygon, Polygon
|
from shapely.geometry import MultiPolygon, Polygon
|
||||||
from shapely.ops import unary_union
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -158,8 +157,7 @@ def country_cover(country_shapes, eez_shapes=None):
|
|||||||
shapes = country_shapes
|
shapes = country_shapes
|
||||||
if eez_shapes is not None:
|
if eez_shapes is not None:
|
||||||
shapes = pd.concat([shapes, eez_shapes])
|
shapes = pd.concat([shapes, eez_shapes])
|
||||||
|
europe_shape = shapes.unary_union
|
||||||
europe_shape = unary_union(shapes)
|
|
||||||
if isinstance(europe_shape, MultiPolygon):
|
if isinstance(europe_shape, MultiPolygon):
|
||||||
europe_shape = max(europe_shape, key=attrgetter("area"))
|
europe_shape = max(europe_shape, key=attrgetter("area"))
|
||||||
return Polygon(shell=europe_shape.exterior)
|
return Polygon(shell=europe_shape.exterior)
|
||||||
@ -265,6 +263,7 @@ if __name__ == "__main__":
|
|||||||
)
|
)
|
||||||
offshore_shapes.reset_index().to_file(snakemake.output.offshore_shapes)
|
offshore_shapes.reset_index().to_file(snakemake.output.offshore_shapes)
|
||||||
|
|
||||||
|
|
||||||
europe_shape = gpd.GeoDataFrame(
|
europe_shape = gpd.GeoDataFrame(
|
||||||
geometry=[country_cover(country_shapes, offshore_shapes.geometry)]
|
geometry=[country_cover(country_shapes, offshore_shapes.geometry)]
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user