@@ -593,21 +593,36 @@ def check_dem_type_in_bounds(
593593 logger .info (f"Searching { dem_index_path } " )
594594
595595 gdf = gpd .read_file (dem_index_path , layer = layer )
596- bounding_box = shapely . geometry . box ( * bounds )
596+ intersecting_tiles = 0
597597
598- if gdf . crs is not None :
599- # ensure same crs
600- bounding_box = (
601- gpd . GeoSeries ([ bounding_box ], crs = "EPSG:4326" ). to_crs ( gdf . crs ). iloc [ 0 ]
598+ # handle antimeridian crossing
599+ if bounds [ 0 ] > bounds [ 2 ]:
600+ logger . warning (
601+ "bounds cross the antimeridian, searching for intersections either side."
602602 )
603+ bounds_east , bounds_west = split_bounds_at_antimeridian (bounds )
604+ search_shapes = [
605+ shapely .geometry .box (* bounds_east ),
606+ shapely .geometry .box (* bounds_west ),
607+ ]
603608 else :
604- logger .info ('No crs found for index file. Assuming EPSG:4326"' )
605- bounding_box = gpd .GeoSeries ([bounding_box ], crs = "EPSG:4326" )
606- # Find rows that intersect with the bounding box
607- intersecting_tiles = gdf [gdf .intersects (bounding_box )]
608- if len (intersecting_tiles ) == 0 :
609+ search_shapes = [shapely .geometry .box (* bounds )]
610+
611+ for bounding_box in search_shapes :
612+ if gdf .crs is not None :
613+ # ensure same crs
614+ bounding_box = (
615+ gpd .GeoSeries ([bounding_box ], crs = "EPSG:4326" ).to_crs (gdf .crs ).iloc [0 ]
616+ )
617+ else :
618+ logger .info ('No crs found for index file. Assuming EPSG:4326"' )
619+ bounding_box = gpd .GeoSeries ([bounding_box ], crs = "EPSG:4326" )
620+ # Count rows that intersect with the bounding box
621+ intersecting_tiles += len (gdf [gdf .intersects (bounding_box )])
622+
623+ if intersecting_tiles == 0 :
609624 logger .info (f"No intersecting tiles found" )
610625 return False
611626 else :
612- logger .info (f"{ len ( intersecting_tiles ) } intersecting tiles found" )
627+ logger .info (f"{ intersecting_tiles } intersecting tiles found" )
613628 return True
0 commit comments