Skip to content

Commit

Permalink
Save annotations to a temporary file
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs committed Dec 6, 2024
1 parent 1b2eb23 commit 2370db4
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions leafmap/maplibregl.py
Original file line number Diff line number Diff line change
Expand Up @@ -3635,7 +3635,12 @@ def add_gps_trace(
raise FileNotFoundError(f"File not found: {data}")

if isinstance(data, str):
tmp_file = os.path.splitext(data)[0] + "_tmp.csv"
gdf = common.points_from_xy(data, x=x, y=y)
# If the temporary file exists, read the annotations from it
if os.path.exists(tmp_file):
df = pd.read_csv(tmp_file)
gdf[ann_column] = df[ann_column]
elif isinstance(data, gpd.GeoDataFrame):
gdf = data
else:
Expand Down Expand Up @@ -4587,6 +4592,7 @@ def features_change(change):
def on_save_click(b):
output.clear_output()
download_widget.clear_output()

m.gdf.loc[m.gdf[ann_column_edited] == "selected", ann_column] = dropdown.value
m.gdf.loc[m.gdf[ann_column_edited] == "selected", ann_column_edited] = (
dropdown.value
Expand Down Expand Up @@ -4614,6 +4620,10 @@ def on_save_click(b):
m.gdf[ann_column_edited] = m.gdf[ann_column]
m.set_data(layer_name, m.gdf.__geo_interface__)

# Save the annotation to a temporary file
temp_file = os.path.splitext(filename)[0] + "_tmp.csv"
m.gdf[[ann_column]].to_csv(temp_file, index=False)

save.on_click(on_save_click)

def on_export_click(b):
Expand Down Expand Up @@ -4662,6 +4672,11 @@ def on_export_click(b):
print(f"Saved CSV: {os.path.basename(output_csv)}")
print(f"Saved GeoJSON: {os.path.basename(output_geojson)}")

# Remove the temporary file if it exists
tmp_file = os.path.splitext(filename)[0] + "_tmp.csv"
if os.path.exists(tmp_file):
os.remove(tmp_file)

export.on_click(on_export_click)

def on_reset_click(b):
Expand Down

0 comments on commit 2370db4

Please sign in to comment.