-
-
Notifications
You must be signed in to change notification settings - Fork 313
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 view/update computational region #3838
grass.jupyter: Allow Users to view/update computational region #3838
Conversation
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 spent some time looking into this and I think what we should do is this:
Create a toggle button and when activated, we add an editable Rectangle. Upon untoggling it will save the changed region. It may be nicer to have a button to save it dynamically showed, when you activate the region mode, but we can leave that for later. The code for this:
from ipyleaflet import Map, Rectangle
polygon = Rectangle(
bounds=((52, 63), (53, 67)),
color="red",
fill_color="red",
rotation=False,
draggable=True,
transform=True
)
m = Map(center=(42.5531, -48.6914), zoom=6)
m.add(polygon);
m
So we won't use the DrawControl, we will use it later for drawing geometries we want to save as vector map.
Couple more notes below:
When drawing I am getting:
TypeError: handle_draw() got multiple values for argument 'action'
When I press Save button, I get:
TypeError: save_region() takes 0 positional arguments but 1 was given
I don't see any reprojection here, you need to reproject the rectangle to get the proper coordinates.
From Ipyleaflet documentation:
The DrawControl is deprecated and will be removed in a future release. Please use GeomanDrawControl instead.
Also it should probably zoom to the region when you activate it. |
Hi Anna, I tried various ways to allow users to draw rectangle using |
On Sun, Jun 23, 2024, 7:30 PM Riya Saxena ***@***.***> wrote:
Hi Anna, I tried various ways to
I spent some time looking into this and I think what we should do is this:
Create a toggle button and when activated, we add an editable Rectangle.
Upon untoggling it will save the changed region. It may be nicer to have a
button to save it dynamically showed, when you activate the region mode,
but we can leave that for later. The code for this:
from ipyleaflet import Map, Rectangle
polygon = Rectangle(
bounds=((52, 63), (53, 67)),
color="red",
fill_color="red",
rotation=False,
draggable=True,
transform=True
)
m = Map(center=(42.5531, -48.6914), zoom=6)
m.add(polygon);
m
So we won't use the DrawControl, we will use it later for drawing
geometries we want to save as vector map.
Couple more notes below:
When drawing I am getting:
TypeError: handle_draw() got multiple values for argument 'action'
When I press Save button, I get:
TypeError: save_region() takes 0 positional arguments but 1 was given
I don't see any reprojection here, you need to reproject the rectangle to
get the proper coordinates.
From Ipyleaflet documentation:
*The DrawControl is deprecated and will be removed in a future release.
Please use GeomanDrawControl instead.*
Hi Anna, I tried various ways to allow users to draw rectangle using
ipyleaflet.Rectangle but it looks like it can only be done if the user
gives the coordinates, and user is not able to draw anything on the map
with this rectangle.
User would not be drawing the rectangle, the rectangle would be displayed
automatically, showing the current computational region. The coordinates of
the region will have to be transformed to lat lon.
… —
Reply to this email directly, view it on GitHub
<#3838 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABZFVKG6PA6G4PHRWZ7FVYTZI4A27AVCNFSM6AAAAABJL5EK32VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCOBVGIYTIMBTHE>
.
You are receiving this because you commented.Message ID:
***@***.***>
|
Just to ensure, the task is to allow users to draw the computational region? I'll just push the changes as of now. |
It looks like there is still some misunderstanding. Let me try to explain better what I described above so that we can progress with this. This is how I envision this to work from the point of view of a user:
You will use the ipyleaflet.Rectangle to achieve that, see the code above. You will need to reproject the coordinates of the rectangle from the original CRS to latlon and then the new coordinates from latlon to the original CRS. Note the original region is a rectangle, after transformation it may be rotated, so you need to take a bounding box of it and similarly when transforming the modified rectangle back to the original CRS. If the user doesn't modify the rectangle, don't modify the computational region. Ideally, you could dynamically add a save button next to the toggle button, so when you toggle, the save button shows up, when you untoggle it, it would disappear. But let's leave this for later. Don't use the DrawControl. Let me know if this still needs some clarifications. |
Oh, okay. I thought the user began by drawing the rectangle. One more thing, how should I define the original computational region? |
I know that's how we thought about this before, but I tried to explain that in my initial comment in this PR. This solution is better because it also allows user to visualize current computational region. Also it looks like you can't have multiple draw controls, so we will instead use the draw controls for drawing vector geometries that can be then saved as a vector map. You don't define computational region, it is set by the user, you can get the current computational region with |
I can't figure out why the output_widget is not updated when the user saves the region. Also, I'm aware of the fact that I need to convert the coordinates to CRS; I wanted to first display the coordinates in terms of latlon correctly. |
69213e0
to
a9d5490
Compare
The zoom-in should not be happening every time user edits the rectangle, it creates a weird flashing. |
@29riyasaxena could you please update the description of this PR too? Thanks! |
Hi Anna, I am getting the following errors after pulling the changes from the updated code:
Could you please confirm if things are okay from your side? |
Is it possible to see a little bit more of the error (traceback), including line numbers if possible? It's hard to know what called this function with the wrong number of arguments |
Hi @echoix, this error was resolved when I made a local correction by adjusting the |
The underscore (probably) can't really be used like most Python projects here, as it is used for gettext translation. So you are in fact passing in an argument that is a callable (like a lambda), by passing a function without calling it. (It can be called inside that function by using the argument name, adding the parentheses and any parameters inside the parentheses). The point is, the underscore (probably) isn't a discard variable in this context, and is neither the previous result like in interactive Python |
Thank you for your explanation @echoix. I think this is the reason why the function wasn't behaving as expected. |
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 think this is ready to merge.
It occurred to me that part of this functionality (displaying region) could be done with folium as well. I would leave that for a separate PR.
…#3838) This pull request introduces a new feature to grass.jupyter.interactivemap.py: a "View/Update Computational Region" button that allows users to update the computational region by adjusting its boundaries interactively. Users can move the rectangle representing the current computation region and adjust its size by changing its vertex. --------- Co-authored-by: Anna Petrasova <[email protected]>
Hello Everyone,
This pull request introduces a new feature to
grass.jupyter.interactivemap.py
: a "View/Update Computational Region" button that allows users to update the computational region by adjusting its boundaries interactively. Users can move the rectangle representing the current computation region and adjust its size by changing its vertex.Here's how it works:
For a visual demonstration, please watch the following recording:
computational_region_button_working.mp4