@@ -784,21 +784,17 @@ def get_country_geometries(
784784 if isinstance (country_names , str ):
785785 country_names = [country_names ]
786786
787- # print warning if ISO code not recognized
787+ # raise error if a country name is not recognized
788788 for country_name in country_names :
789789 if not country_name in nat_earth [["ISO_A3" , "WB_A3" , "ADM0_A3" ]].values :
790- LOGGER . warning (f"ISO code { country_name } not recognized." )
790+ raise ValueError (f"ISO code { country_name } not recognized." )
791791
792792 country_mask = np .isin (
793793 nat_earth [["ISO_A3" , "WB_A3" , "ADM0_A3" ]].values ,
794794 country_names ,
795795 ).any (axis = 1 )
796796 out = out [country_mask ]
797797
798- # exit with Value error if no country code was recognized
799- if out .size == 0 :
800- raise ValueError (f"None of the given country codes were recognized." )
801-
802798 if extent :
803799 if extent [1 ] - extent [0 ] > 360 :
804800 raise ValueError (
@@ -1729,10 +1725,15 @@ def get_country_bounding_box(country_names, buffer=1.0):
17291725 country_geometry = get_country_geometries (country_names ).geometry
17301726 longitudes , latitudes = [], []
17311727 for multipolygon in country_geometry :
1732- for polygon in multipolygon . geoms : # Loop through each polygon
1728+ if isinstance ( multipolygon , Polygon ) : # if entry is polygon
17331729 for coord in polygon .exterior .coords : # Extract exterior coordinates
17341730 longitudes .append (coord [0 ])
17351731 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 ])
17361737
17371738 return latlon_bounds (np .array (latitudes ), np .array (longitudes ), buffer = buffer )
17381739
0 commit comments