-
-
Notifications
You must be signed in to change notification settings - Fork 295
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
grass.jupyter: Allow users to draw simple geometries and save it as vector #4003
base: main
Are you sure you want to change the base?
Conversation
Right now it's not creating a GRASS vector, it's just adding geojson layer to the map. The vector needs to be imported, I think v.import should do that as we discussed before. |
Hi Anna, |
This is not working, in the jupyterlab log I get:
Please test more. Run it in the notebook and check the output is correctly written as a vector map. |
python/grass/jupyter/utils.py
Outdated
@@ -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): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is rather trivial function, perhaps this could include the temporary file creation (and removal).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To clarify, should I add a button to delete the the drawn vector?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am talking about moving some of the code handling temporary file creation to this function. The temporary file needs to be removed once it's not needed.
Hi Anna, I can successfully add vectors and save them, but I am stuck on the part when deleting them. I tried clearing all the geometries and removing layers when clicking the delete button, but things aren't working. Could you please share your opinions on this? |
param geojson_filename: name of the geojson file to be saved | ||
param name: name with which vector should be saved | ||
""" | ||
with tempfile.NamedTemporaryFile( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like the temp file is not being removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure why and when to delete the temp file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the why, its because it is not deleted automatically with delete=False. Take a look at the section here: https://docs.python.org/3/library/tempfile.html#tempfile.NamedTemporaryFile, it goes through the behavior of NamedTemporaryFile vs other tempfile classes.
Hi there,
Here’s my basic idea for implementing a feature that allows users to draw simple geometries to add as a GRASS native vector map. I’d love to hear your suggestions on how to improve it.