Skip to content

Commit 19dd2d3

Browse files
authored
Merge pull request #29 from GeoscienceAustralia/fix/handle_am_for_dem_in_bounds
fix for checking dem intersection over the AM
2 parents 747cf32 + 99f4501 commit 19dd2d3

File tree

2 files changed

+47
-11
lines changed

2 files changed

+47
-11
lines changed

dem_handler/utils/spatial.py

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -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

tests/utils/test_utils.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,25 @@ class BoundsDEMCheckCase:
214214
is_error=False,
215215
)
216216

217+
# crosses AM over the coast, no intersect
218+
test_antimeridian_no_intersect_with_rema = BoundsDEMCheckCase(
219+
dem_type="rema",
220+
resolution=32,
221+
bounds=(173.430893, -71.618423, -178.032867, -68.765106),
222+
in_bounds=False,
223+
is_error=False,
224+
)
225+
226+
# crosses AM over the coast, no intersect
227+
test_antimeridian_no_intersect_with_cop30 = BoundsDEMCheckCase(
228+
dem_type="cop30",
229+
resolution=30,
230+
bounds=(173.430893, -71.618423, -178.032867, -68.765106),
231+
in_bounds=False,
232+
is_error=False,
233+
)
234+
235+
217236
test_cases = [
218237
test_invalid_dem_type,
219238
test_invalid_dem_resolution,
@@ -224,6 +243,8 @@ class BoundsDEMCheckCase:
224243
test_heard_island_bounds_with_cop30,
225244
test_antimeridian_with_cop30,
226245
test_antimeridian_with_rema,
246+
test_antimeridian_no_intersect_with_rema,
247+
test_antimeridian_no_intersect_with_cop30,
227248
]
228249

229250

0 commit comments

Comments
 (0)