Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save annotations to a temporary file #1016

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading