4646import shapely .vectorized
4747import shapely .wkt
4848from cartopy .io import shapereader
49- from shapely .geometry import MultiPolygon , Point , Polygon , box
49+ from shapely .geometry import MultiPolygon , Point , box
5050from sklearn .neighbors import BallTree
5151
5252import climada .util .hdf5_handler as u_hdf5
@@ -1723,19 +1723,20 @@ def bounding_box_from_countries(country_names, buffer=1.0):
17231723 """
17241724
17251725 country_geometry = get_country_geometries (country_names ).geometry
1726- longitudes , latitudes = [], []
1727- for multipolygon in country_geometry :
1728- if isinstance (multipolygon , Polygon ): # if entry is polygon
1729- for coord in polygon .exterior .coords : # Extract exterior coordinates
1730- longitudes .append (coord [0 ])
1731- latitudes .append (coord [1 ])
1732- else : # if entry is multipolygon
1733- for polygon in multipolygon .geoms :
1734- for coord in polygon .exterior .coords : # Extract exterior coordinates
1735- longitudes .append (coord [0 ])
1736- latitudes .append (coord [1 ])
1726+ generator_country_geometry = (
1727+ poly if isinstance (poly , MultiPolygon ) else MultiPolygon ([poly ])
1728+ for poly in country_geometry
1729+ )
1730+ lon , lat = np .concatenate (
1731+ [
1732+ np .array (pg .exterior .coords ).T
1733+ for poly in generator_country_geometry
1734+ for pg in poly .geoms
1735+ ],
1736+ axis = 1 ,
1737+ )
17371738
1738- return latlon_bounds (np . array ( latitudes ), np . array ( longitudes ) , buffer = buffer )
1739+ return latlon_bounds (lat , lon , buffer = buffer )
17391740
17401741
17411742def bounding_box_from_cardinal_bounds (* , northern , eastern , western , southern ):
@@ -1756,12 +1757,13 @@ def bounding_box_from_cardinal_bounds(*, northern, eastern, western, southern):
17561757 Returns
17571758 -------
17581759 tuple
1759- The resulting normalized bounding box (min_lon, min_lat, max_lon, max_lat) with -180 <= min_lon < max_lon < 540
1760+ The resulting normalized bounding box (min_lon, min_lat, max_lon, max_lat)
1761+ with -180 <= min_lon < max_lon < 540
17601762
17611763 """
17621764
17631765 # latitude bounds check
1764- if not (( 90 >= northern > southern >= - 90 )) :
1766+ if not 90 >= northern > southern >= - 90 :
17651767 raise ValueError (
17661768 "Given northern bound is below given southern bound or out of bounds"
17671769 )
0 commit comments