@@ -177,6 +177,7 @@ def extract_dgo_metrics_to_dataframe(gpkg_path: str, spatialite_path: str) -> pd
177177
178178 t2 = time .time ()
179179 sql = f'SELECT { ", " .join (col_names )} FROM vbet_dgos'
180+ log .debug (f"Select query:\n { sql } " )
180181 df = pd .read_sql_query (sql , conn )
181182 log .debug (f"Loaded data from sql to dataframe in { time .time () - t2 :.2f} s. Shape { df .shape } " )
182183
@@ -208,7 +209,8 @@ def extract_dgo_metrics_to_dataframe(gpkg_path: str, spatialite_path: str) -> pd
208209 df_final = df_final .pivot_table (
209210 index = ['fid' , 'landcover' , 'epoch_length' , 'epoch_name' , 'confidence' ],
210211 columns = 'metric_name' ,
211- values = 'measurement'
212+ values = 'measurement' ,
213+ observed = True
212214 ).reset_index ()
213215 log .debug (f"Pivot data { time .time () - t6 :.2f} s" )
214216
@@ -222,6 +224,7 @@ def extract_dgo_metrics_to_dataframe(gpkg_path: str, spatialite_path: str) -> pd
222224def extract_dgos_to_geodataframe (gpkg_path : str , spatialite_path : str ) -> gpd .GeoDataFrame :
223225 """
224226 Connect to the GeoPackage, run the SQL, and return a GeoDataFrame.
227+ Assumes data are in EPSG:2193 (True for at least one of the New Zealand projects)
225228 """
226229 conn = apsw .Connection (gpkg_path )
227230 conn .enable_load_extension (True )
@@ -265,7 +268,8 @@ def extract_dgos_to_geodataframe(gpkg_path: str, spatialite_path: str) -> gpd.Ge
265268 df = df .loc [:, [col for col in df .columns if col != 'dgoid' ]]
266269 # convert wkb geometry to shapely objects
267270 df ['dgo_geom' ] = df ['dgo_geom' ].apply (wkb .loads ) # pyright: ignore[reportCallIssue, reportArgumentType]
268- gdf = gpd .GeoDataFrame (df , geometry = 'dgo_geom' , crs = 'EPSG:4326' )
271+ gdf = gpd .GeoDataFrame (df , geometry = 'dgo_geom' , crs = 'EPSG:2193' ) # SOURCE EPSG
272+ gdf = gdf .to_crs ('EPSG:4326' ) # DESTINATION EPSG
269273
270274 bbox_df = gdf .geometry .bounds .rename (columns = {'minx' : 'xmin' , 'miny' : 'ymin' , 'maxx' : 'xmax' , 'maxy' : 'ymax' })
271275 # Combine into a struct-like dict for each row
0 commit comments