-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Rubberband/digitizing not working correctly with snapping after database trigger has normalized polygon with inner ring during saving #57181
Comments
The bug exists on 3.34.3-Prizren as well. |
Is this also a #31251 duplicate? |
Reproduced on master 623ceab11d8 With a more simple test case, on one polygon only: qgis_issue_57181-2024-07-29_17.08.32_srt.mp4It seems to be related to how the vertices order is not updated in the cache, when saving after a modification action, but it is updated when saving after digitizing a new feature. This vertex confusion stays even after digitizing other features. A refresh via the toolbar I will investigate further into the code. |
After some investigations, we are on a case where QGIS can't be aware of underlying data change. 💾 When the "save layer" button is pushed, the trigger 🧠 This explains why everything works fine when not saving the layer and doing all the digitizing steps: the geometry is always in a state that QGIS knows about. 🤔 "But... the label with the geometry WKT is up-to-date right after saving, so... surly somewhere QGIS does know that the geometry has changed?" Well... the label expression directly queries the data provider (PostgreSQL) after the save action (because of refreshing the canvas after saving a layer). 📡 Right. What now? We have a solution! Let's use PostgreSQL notification signal! With NOTIFY qgis; SQL statement, that we will add in our trigger that becomes -- create trigger function to normalize polygons
CREATE OR REPLACE FUNCTION public.normalize_geom()
RETURNS trigger AS $$
BEGIN
NEW.geom = ST_Normalize(NEW.geom);
NOTIFY qgis; -- tell QGIS layers listening to the notification to refresh!
RETURN NEW;
END; $$ LANGUAGE 'plpgsql'; And configure our layers to listen to the provider notifications in the ✅ This configuration fixes the vertex tool geometry cache and snapping index being wrong.
NB: the notification can include a message: |
Another solution is to check the layer itself in In this way, every change on the layer will trigger a full refresh of the data, caches, and rubber bands. |
Thank you for the workaround suggestions. We tried these and using "refresh layer on notification" option did solve the issue but unfortunately this created a new one: each layer with the option enabled seems to create a new Postgresql connection and therefore the maximum connection limit is reached at some point. We have about 100 layers and 100 users so this would result in 10 000+ extra connections? I tested this with QGIS-3.34.3-1 though and QGIS crashed if number of layers exceeded database's max_connection-setting (the crashing may have been fixed in #54260 but not sure if the number of connections used is fixed). However, we came up with a 3rd workaround: reloading the layer after the layer is saved. This seems to fix vertex ordering. # pseudo code, not actually tested with this
layer.afterCommitChanges.connect(lambda: layer.reload()) |
@troopa81 What are your thoughts about this? |
What is the bug or the crash?
If a polygon with inner ring is changed in the database with trigger after saving edits (e.g. due to normalization of polygon), rubberband snaps to old vertices and not to the updated ones if the inner ring is used as snapping target. This looks very confusing to the user although in some cases the actual snapping seems to work (maybe if the digitized ring was symmetrical?) and resulting feature is created as digitized.
The problem occurs only with inner rings and only if digitizing + saving is done in a specific order. So it is quite difficult to reproduce but at least the steps in the following section describe one case where this issue occurs.
Here the digitized ring also seems to be incorrect (not the using the vertices snapped).
Steps to reproduce the issue
I couldn't figure any way to reset this behaviour once it starts happening. Also, as mentioned in the steps, this only occurs if edits are saved after each step and layer is not changed before saving the first ring creation.
Versions
<style type="text/css"> p, li { white-space: pre-wrap; } </style>Active Python plugins
db_manager
0.1.20
grassprovider
2.12.99
MetaSearch
0.3.6
processing
2.12.99
Supported QGIS version
New profile
Additional context
No response
The text was updated successfully, but these errors were encountered: