Skip to content

Commit

Permalink
build_shapes: replace unary union from shapely by geopandas equivalent
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianHofmann committed Feb 7, 2023
1 parent c25f02d commit efedfa9
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions scripts/build_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
import pycountry as pyc
from _helpers import configure_logging
from shapely.geometry import MultiPolygon, Polygon
from shapely.ops import unary_union

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -158,8 +157,7 @@ def country_cover(country_shapes, eez_shapes=None):
shapes = country_shapes
if eez_shapes is not None:
shapes = pd.concat([shapes, eez_shapes])

europe_shape = unary_union(shapes)
europe_shape = shapes.unary_union
if isinstance(europe_shape, MultiPolygon):
europe_shape = max(europe_shape, key=attrgetter("area"))
return Polygon(shell=europe_shape.exterior)
Expand Down Expand Up @@ -265,6 +263,7 @@ def nuts3(country_shapes, nuts3, nuts3pop, nuts3gdp, ch_cantons, ch_popgdp):
)
offshore_shapes.reset_index().to_file(snakemake.output.offshore_shapes)


europe_shape = gpd.GeoDataFrame(
geometry=[country_cover(country_shapes, offshore_shapes.geometry)]
)
Expand Down

0 comments on commit efedfa9

Please sign in to comment.