Skip to content

Commit 5858f8d

Browse files
committed
Update filter_shoreline to accept less parameters
1 parent 436292f commit 5858f8d

File tree

1 file changed

+38
-18
lines changed

1 file changed

+38
-18
lines changed

src/coastsat/SDS_shoreline.py

+38-18
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,12 @@ def get_extract_shoreline_extraction_area_array(shoreline_extraction_area:gpd.Ge
125125

126126
return shoreline_extraction_area_array
127127

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,):
129129
"""Filter the shoreline based on the extraction area.
130130
131131
Args:
132132
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.
138134
shoreline_extraction_area (GeoDataFrame): The area to extract the shoreline from.
139135
140136
Returns:
@@ -145,19 +141,9 @@ def filter_shoreline(shoreline, satname, sl_date, acc_georef, cloud_cover, outpu
145141
shoreline_extraction_area_gdf = shoreline_extraction_area.to_crs(f"epsg:{output_epsg}")
146142

147143
# 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}",)
158145
if shoreline_gdf is None:
159146
return shoreline
160-
shoreline_gdf.reset_index(drop=True, inplace=True)
161147

162148
# Filter shorelines within the extraction area.
163149
filtered_shoreline_gdf = ref_poly_filter(shoreline_extraction_area_gdf, shoreline_gdf)
@@ -301,6 +287,38 @@ def create_gdf(
301287
return None
302288

303289

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+
304322
def ref_poly_filter(ref_poly_gdf:gpd.GeoDataFrame, raw_shorelines_gdf:gpd.GeoDataFrame)->gpd.GeoDataFrame:
305323
"""
306324
Filters shorelines that are within a reference polygon.
@@ -684,7 +702,7 @@ def extract_shorelines(
684702
roi_gdf = SDS_preprocess.create_gdf_from_image_extent(height,width, georef,image_epsg,output_epsg)
685703

686704
# 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)
688706
shoreline_extraction_area_array = get_extract_shoreline_extraction_area_array(shoreline_extraction_area, output_epsg, roi_gdf)
689707

690708
# visualize the mapped shorelines, there are two options:
@@ -1341,6 +1359,8 @@ def show_detection(
13411359
output_directory: str
13421360
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.
13431361
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+
13441364
Returns:
13451365
-----------
13461366
skip_image: boolean

0 commit comments

Comments
 (0)