@@ -125,16 +125,12 @@ def get_extract_shoreline_extraction_area_array(shoreline_extraction_area:gpd.Ge
125
125
126
126
return shoreline_extraction_area_array
127
127
128
- def filter_shoreline (shoreline , satname , sl_date , acc_georef , cloud_cover , output_epsg , shoreline_extraction_area ):
128
+ def filter_shoreline (shoreline ,shoreline_extraction_area , output_epsg ,):
129
129
"""Filter the shoreline based on the extraction area.
130
130
131
131
Args:
132
132
shoreline (array): The original shoreline data.
133
- satname (str): Name of the satellite.
134
- sl_date (GeoDataFrame): the date of the satellite image.
135
- acc_georef (float): Accuracy of georeferencing.
136
- cloud_cover (float): Cloud cover percentage.
137
- output_epsg (int): EPSG code for the output coordinate reference system.
133
+ shoreline_extraction_area (GeoDataFrame): The area to extract the shoreline from.
138
134
shoreline_extraction_area (GeoDataFrame): The area to extract the shoreline from.
139
135
140
136
Returns:
@@ -145,19 +141,9 @@ def filter_shoreline(shoreline, satname, sl_date, acc_georef, cloud_cover, outpu
145
141
shoreline_extraction_area_gdf = shoreline_extraction_area .to_crs (f"epsg:{ output_epsg } " )
146
142
147
143
# Convert the shoreline to a GeoDataFrame.
148
- shoreline_gdf = create_gdf (
149
- shoreline ,
150
- sl_date ,
151
- satname ,
152
- acc_georef ,
153
- cloud_cover ,
154
- 0 ,
155
- "lines" ,
156
- crs = f"epsg:{ output_epsg } " ,
157
- )
144
+ shoreline_gdf = create_gdf_from_type (shoreline ,"lines" ,crs = f"epsg:{ output_epsg } " ,)
158
145
if shoreline_gdf is None :
159
146
return shoreline
160
- shoreline_gdf .reset_index (drop = True , inplace = True )
161
147
162
148
# Filter shorelines within the extraction area.
163
149
filtered_shoreline_gdf = ref_poly_filter (shoreline_extraction_area_gdf , shoreline_gdf )
@@ -301,6 +287,38 @@ def create_gdf(
301
287
return None
302
288
303
289
290
+ def create_gdf_from_type (
291
+ shoreline : List [List [float ]],
292
+ geomtype : str ,
293
+ crs : str = None ,
294
+ ) :
295
+ """
296
+ Creates a GeoDataFrame for a given shoreline and its attributes.
297
+
298
+ Parameters:
299
+ -----------
300
+ shoreline: List[List[float]]
301
+ List of shoreline coordinates.
302
+ geomtype: str
303
+ Type of geometry ('lines' or 'points').
304
+
305
+ Returns:
306
+ --------
307
+ Optional[gpd.GeoDataFrame]
308
+ The created GeoDataFrame or None if invalid.
309
+ """
310
+ geom = create_geometry (geomtype , shoreline )
311
+ if geom :
312
+ # Creating a GeoDataFrame directly with all attributes
313
+ gdf = gpd .GeoDataFrame (geometry = [geom ],)
314
+ if crs :
315
+ gdf .crs = crs
316
+ return gdf
317
+
318
+ return None
319
+
320
+
321
+
304
322
def ref_poly_filter (ref_poly_gdf :gpd .GeoDataFrame , raw_shorelines_gdf :gpd .GeoDataFrame )-> gpd .GeoDataFrame :
305
323
"""
306
324
Filters shorelines that are within a reference polygon.
@@ -684,7 +702,7 @@ def extract_shorelines(
684
702
roi_gdf = SDS_preprocess .create_gdf_from_image_extent (height ,width , georef ,image_epsg ,output_epsg )
685
703
686
704
# filter shorelines within the extraction area
687
- shoreline = filter_shoreline ( shoreline , satname , metadata [ satname ][ "dates" ][ i ], metadata [ satname ][ "acc_georef" ][ i ], cloud_cover , output_epsg , shoreline_extraction_area )
705
+ shoreline = filter_shoreline ( shoreline ,shoreline_extraction_area , output_epsg )
688
706
shoreline_extraction_area_array = get_extract_shoreline_extraction_area_array (shoreline_extraction_area , output_epsg , roi_gdf )
689
707
690
708
# visualize the mapped shorelines, there are two options:
@@ -1341,6 +1359,8 @@ def show_detection(
1341
1359
output_directory: str
1342
1360
path to the output directory to save the jpg file. If none, the jpg file will be saved at the same location as the input image.
1343
1361
The jpg files will be saved at output_directory/jpg_files/detection or if output_directory is None, at filepath/jpg_files/detection
1362
+
1363
+
1344
1364
Returns:
1345
1365
-----------
1346
1366
skip_image: boolean
0 commit comments