Skip to content

Commit

Permalink
Change the way to save geojson file
Browse files Browse the repository at this point in the history
  • Loading branch information
29riyasaxena committed Jul 11, 2024
1 parent 029fcf0 commit 9b0f836
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion python/grass/jupyter/interactivemap.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ def setup_drawing_interface(self):
"""
import ipywidgets as widgets
from IPython.display import display
import tempfile

draw_control = self._ipyleaflet.DrawControl()
drawn_geometries = []
Expand Down Expand Up @@ -412,8 +413,17 @@ def save_geometries(b):
with open(geojson_filename, "w") as f:
json.dump(geo_json, f)
try:
save_vector(geojson_filename, name)
with tempfile.NamedTemporaryFile(
suffix=".geojson", delete=False
) as temp_file:
temp_filename = temp_file.name
json.dump(geo_json, temp_file)
save_vector(temp_filename, name)
print(f"Imported geometry with name '{name}' into GRASS GIS.")
geo_json_layer = self._ipyleaflet.GeoJSON(
data=geo_json, name=name
)
self.map.add_layer(geo_json_layer)
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)
Expand Down

0 comments on commit 9b0f836

Please sign in to comment.