@@ -294,8 +294,34 @@ def reference_layer(self):
294294 """Get the admin boundary reference layer."""
295295 return self .layer_combo .currentLayer ()
296296
297- def crs (self ):
298- """Get the crs for the Geest project."""
297+ def crs (self , working_directory = None ):
298+ """Get the crs for the Geest project.
299+
300+ If study area already exists, return its CRS.
301+ Otherwise, calculate CRS from the boundary layer.
302+
303+ Args:
304+ working_directory: Optional working directory path. If not provided, uses self.working_dir
305+ """
306+ # Use provided working_directory, otherwise fall back to self.working_dir
307+ work_dir = working_directory or self .working_dir
308+
309+ # First, try to get CRS from existing study area
310+ if work_dir and os .path .exists (work_dir ):
311+ study_area_gpkg = os .path .join (work_dir , "study_area" , "study_area.gpkg" )
312+ if os .path .exists (study_area_gpkg ):
313+ try :
314+ study_area_layer = QgsVectorLayer (
315+ f"{ study_area_gpkg } |layername=study_area_polygons" , "study_area" , "ogr"
316+ )
317+ if study_area_layer .isValid ():
318+ crs = study_area_layer .crs ()
319+ self .crs_label .setText (f"CRS: { crs .authid ()} " )
320+ return crs
321+ except Exception as e :
322+ log_message (f"Could not load study area CRS: { e } " , level = Qgis .Warning )
323+
324+ # If no study area exists yet, calculate CRS from boundary layer
299325 crs = None
300326 if self .use_boundary_crs .isChecked ():
301327 log_message ("Using boundary CRS" )
0 commit comments