Skip to content

Commit

Permalink
Allow user to save the drawn vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
29riyasaxena committed Jul 9, 2024
1 parent 8e22fd0 commit 029fcf0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
12 changes: 9 additions & 3 deletions python/grass/jupyter/interactivemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import base64
import json
from .reprojection_renderer import ReprojectionRenderer
from .utils import save_vector


def get_backend(interactive_map):
Expand Down Expand Up @@ -407,11 +408,16 @@ def save_geometries(b):
"type": "FeatureCollection",
"features": drawn_geometries,
}
geojson_filename = f"/tmp/{name}.geojson"
with open(geojson_filename, "w") as f:
json.dump(geo_json, f)
try:
save_vector(geojson_filename, name)
print(f"Imported geometry with name '{name}' into GRASS GIS.")
except Exception as e:
print(f"Failed to import geometries into GRASS GIS: {e}")
geo_json_layer = self._ipyleaflet.GeoJSON(data=geo_json, name=name)
self.map.add_layer(geo_json_layer)
print(
f"Saved {len(drawn_geometries)} geometries with name '{name}'"
)

save_button.on_click(save_geometries)

Expand Down
10 changes: 10 additions & 0 deletions python/grass/jupyter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,16 @@ def get_rendering_size(region, width, height, default_width=600, default_height=
return (default_width, round(default_width * region_height / region_width))


def save_vector(geojson_filename, name):
"""
Saves the user drawn vector.
param geojson_filename: name of the geojson file to be saved
param name: name with which vector should be saved
"""
gs.run_command("v.import", input=geojson_filename, output=name)


def save_gif(
input_files,
output_filename,
Expand Down

0 comments on commit 029fcf0

Please sign in to comment.