@@ -89,7 +89,7 @@ def assert_year(gdf1, gdf2, ds, year):
8989 sys .exit (1 )
9090
9191
92- def format_all_tiles (fp_labels_shp , ept_labels_shp , ept_data_type , ept_year , labels_4326_gdf , category , supercategory , zoom_level , output_dir = 'outputs' ):
92+ def format_all_tiles (fp_labels_shp , ept_labels_shp , ept_data_type , ept_year , labels_4326_gdf , category , supercategory , zoom_level , output_dir = 'outputs' ):
9393 """
9494 Format all tiles of a given area from a geodataframe.
9595
@@ -347,18 +347,17 @@ def merge_adjacent_detections(detections_gdf, tiles_gdf, year=None, buffer_dista
347347def prepare_labels (labels_shp , category , supercategory , prefix = '' , output_dir = 'outputs' ):
348348 """
349349 Prepare a shapefile of labels into a formatted GeoPandas DataFrame.
350-
351350 Args:
352351 labels_shp (string): path to the shapefile of labels
353352 category (string): column name of the category
354353 supercategory (string): column name of the supercategory
355354 prefix (string): prefix for the output filename
356355 output_dir (string): output directory for the GeoPackage
357-
358356 Returns:
359357 labels_4326_gdf (GeoDataFrame): formatted GeoPandas DataFrame of labels
360358 written_files (list): list of written files
361359 """
360+
362361 logger .info ('Convert labels shapefile into formatted geopackage (EPSG:4326)...' )
363362 labels_gdf = gpd .read_file (labels_shp )
364363 labels_gdf = check_validity (labels_gdf , correct = True )
@@ -369,7 +368,6 @@ def prepare_labels(labels_shp, category, supercategory, prefix='', output_dir='o
369368 labels_4326_gdf = labels_gdf .to_crs (epsg = 4326 ).drop_duplicates (subset = ['geometry' ])
370369 nb_labels = len (labels_4326_gdf )
371370 logger .info (f'There are { nb_labels } polygons in { labels_shp } ' )
372-
373371 if category and category in labels_4326_gdf .columns :
374372 labels_4326_gdf ['CATEGORY' ] = labels_4326_gdf [category ]
375373 category = labels_4326_gdf ['CATEGORY' ].unique ()
@@ -379,12 +377,11 @@ def prepare_labels(labels_shp, category, supercategory, prefix='', output_dir='o
379377 logger .warning (f'No category column in { labels_shp } . A unique category "{ category } " will be assigned' )
380378 labels_4326_gdf ['CATEGORY' ] = category
381379 labels_4326_gdf ['SUPERCATEGORY' ] = supercategory
382-
383380 label_filepath = os .path .join (output_dir , f'{ prefix if prefix .endswith ("_" ) or prefix == "" else prefix + "_" } labels.gpkg' )
384381 labels_4326_gdf .to_file (label_filepath )
385382 written_files = [label_filepath ]
386383 logger .success (f"Done! A file was written: { label_filepath } " )
387-
384+
388385 return labels_4326_gdf , written_files
389386
390387
0 commit comments