From 21eea312f0ce9ebec0b2b136d4aceab942ec4670 Mon Sep 17 00:00:00 2001 From: rosepearson Date: Tue, 3 Sep 2024 14:36:52 +1200 Subject: [PATCH] add error checks for missing crs in the vector module --- src/geoapis/vector.py | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/src/geoapis/vector.py b/src/geoapis/vector.py index 76ac87d..d99eb42 100644 --- a/src/geoapis/vector.py +++ b/src/geoapis/vector.py @@ -72,10 +72,21 @@ def __init__( def _set_up(self): """Ensure the bouding_polygon and CRS are in agreement.""" + error_message = "Either the crs or the bounding_polygon with a CRS mus be specified." + if self.crs is None and self.bounding_polygon is None: + logging.error(error_message) + raise ValueError(error_message) + # Set the crs from the bounding_polygon if it's not been set - if self.crs is None and self.bounding_polygon is not None: - self.crs = self.bounding_polygon.crs.to_epsg() - # Set the bounding_polygon crs from the crs if they differ + if self.bounding_polygon is not None: + if self.crs is None and self.bounding_polygon.crs is not None: + self.crs = self.bounding_polygon.crs.to_epsg() + elif self.crs is not None and self.bounding_polygon.crs is None: + self.bounding_polygon.set_crs(self.crs, inplace=True) + elif self.crs is None and self.bounding_polygon.crs is None: + logging.error(error_message) + raise ValueError(error_message) + # Convert the bounding_polygon crs from the crs if they differ if ( self.bounding_polygon is not None and self.crs != self.bounding_polygon.crs.to_epsg()