-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Postgis mixed geometry data table causes QGIS > 3.8 issues as more recent QGIS versions see all records instead of those of the right type #34629
Comments
Can you please attach an SQL dump? |
Can't make that database public, sorry. But I'll try to create a sample I can share. |
OK, here's a small test case that triggers the bug on the point layer (not on the others, but as it's small I suppose that will help in debugging already.
When looking at the attribute table of the point layer after adding all 3 of them: (in this case the line and area are ok, but that's obviously not always the case, just don't trigger it with this data) The geometry WKT data comes from a postgis manual: https://postgis.net/docs/ST_GeomFromText.html |
Interesting finding, I wonder what the postgres provider does here ... Out of curiosity, what is expected to happen with NULL geometries? |
What I used to recreate the problem was adding from In the example above I didn't use the DB manager at all. Also: in saved projects that work perfectly fine in 3.8 show the bug in 3.10 and 3.12 so it's not just while adding the layers. I tried it again from a new project: So I can confirm that it seems adding layers through DB Manager makes it happen more often, but it DOES happen without using DB Manager as well. That difference in behaviour depending on how the layer was added triggered me to write out the project files as XML so that I could compare them. When adding via the Add Layer: they are respectively:
While when adding via DB manager they end up being:
And the same repeats for the type attribute on |
I looked into those: from what I can tell at least one was a real entry, made manually in QGIS. that somehow managed to not end up with geometry data. No clue how, when or why. |
@swa66 sorry, I did not mean to question or criticize your data. Let me explain: I don't normally work with mixed geometry types often. And for the record, I am not aware what the source of this issue here is. In our projects, we do have features with NULL geometries and we are expected to deal with them. On such features we can use the add part tool to set the geometry. These features are listed in the attribute table for a long time (since before QGIS 2.0). This is on plain Polygon tables (no mixed geometry involved so far). If we solve this issue by filtering features by geometry types (only show points if the layer type is point etc.) we will also lose NULL geometries, which we cannot do - because it breaks a long-supported workflow. We could show NULL geometry features on all geometry type layers. This would work for me, but I am not sure if you want that. And it seems not that consistent within the filtering approach. After all - I wonder if this filter should be an option on the layer. "Show all records" or "Show only matching geometry type records". Actually one can already do this now by setting a |
no worries, I had already criticised it myself. When I saw it as I found it rather odd. As removing them didn't solve the issue, I didn't mention it earlier here, that's all.
I fully understand the issue of how to deal with things that don't have a type if you have to split it up by type, no worries. Your explanation might also show how those NULL entries got created: deletion of the last point in a multipoint object e.g.
I'm seeing inconsistencies in the names used for the geometry types not just between postgis and QGIS (that's understandable, no reason to have an exact match there), but also between how layers got added to a project within QGIS. -> might be a starting point to find the cause for somebody with a far better understanding of the internals than I have.
Interesting! I had looked at filtering, but from my limited experience with it, I didn't see the geom column as an option that could be used. Will look again at it as it might be a (start of a) workaround, as these phantom labels start to be really annoying, and having to fall back to 3.8 to be able to export an offline ESRI shapefile is also far from a handy way of working. |
The feature filter in the layer properties is sent directly to the database as |
@gioman I didn't test this case yet, but maybe DB manager creates a "query layer" while adding the layer from the data source manager does not. You should be able to print |
@swa66 well... that is not what I observe here on a clean testing machine with the dataset ypu provided. the layer with 6 features was added via DB manager and shows the issues you report, the other two where added from the browser and the "add postgis layer" dialog. So it is either that the dataset you provided is not enough to fully replicate the issue or that is just a DB manager problem, IMHO. |
That's not the sample I provided. The table I provided only has 5 rows, not 6. And there is point, 2 lines and 2 polygons in it, yours only shows polygons. |
@swa66 it is, it was me that added another manually (from QGIS) another polygon. |
this is loaded from browser:
this is loaded from DB Manager:
|
I see what you did: no the sample does not trigger on the polygon variant of the data, add the point variant (there should be only 1 there, and it shows all 5 rows) On more complex examples it triggers in more of the variants as well, that somehow is lost in the shorter example, no idea why. But I did note it with the sample when I provided it "(in this case the line and area are ok, but that's obviously not always the case, just don't trigger it with this data)" |
@swa66 confirmed. So my observation is now: with the polygon and line layers the issue arises only if loaded from DB Manager with the point layer the issue arises regardless the way the layer is loaded |
@swa66 if this statement means that on 3.8 it worked as expected then I cannot confirm it. In fact I just installed 3.8 and in the QGIS browser and the "add postgis layer" dialog the only layer that shows in the line one, and in DB manager the layer only shows once with the "?" icon (because this was the case when the geometry column was not declared as point,line or polygon). Adding this layer always results in a table with 5 records where it should be 2. |
1 similar comment
@swa66 if this statement means that on 3.8 it worked as expected then I cannot confirm it. In fact I just installed 3.8 and in the QGIS browser and the "add postgis layer" dialog the only layer that shows in the line one, and in DB manager the layer only shows once with the "?" icon (because this was the case when the geometry column was not declared as point,line or polygon). Adding this layer always results in a table with 5 records where it should be 2. |
QGIS 3.8 works as expected with real data, I don't have a machine with 3.8 handy to redo the short sample with. And again: I do not use DB Manager. |
@swa66 ok but we have to figure all the possible issues, not just yours. Thanks for understanding.
then please paste a (even small) sample of your data. |
For reference, this was introduced by #32292 |
For the record, this should be solved (and tested) with #35367 . The issue explained in #34629 (comment) remains: It's not possible to "fix" NULL geometries on "geometry" layers through QGIS. This is an inconsistency with correctly typed layers/db columns, but IMO an acceptable one for now. |
Describe the bug
In QGIS more recent than 3.8 a postgis database that has (multi)points, lines and (multi)polygons into one table causes issues as QGIS sees all rows in the database in each of the layers.
In QGIS 3.8 (and earlier), this problem was not present. QGIS 3.10 and 3.12 both have the issue.
FWIW: the database is not used by QGIS alone, so splitting the table into 3 tables it is simply not an option (need for unique identifiers and other tables not even used in QGIS that refer to this data)
This causes problems when viewing the table data in QGIS, when rendering labels ( a layer will generate labels for data of the wrong geometry type), and when exporting shape files for that layer.
How to Reproduce
Have a postgis database table containing in a single table multipoint, point, multipolygon,
multilinestring, and linestring data.
e.g.:
Create a new project in QGIS 3.10 , connect to the postgis database to add a vector layer and see the database there 3 times (as expected), once for (multi)points, once for lines and once for (multi)polygons:
Add either the 3 layers to the project (one by one or all in one go doesn't matter)
Click open Attributes table for each of the layers and see the counts:
E.g. for the points one:
compare that 9075 to the rows in the database above, and confirm data for known polygon data is included as well.
e.g. for the polygon layer:
Doing the same in QGIS 3.12 yields exactly the same results as in 3.10
Doing the same in QGIS 3.8 works without a problem:
polygons:
lines:
points:
Once these rows get seen in multiple layers, at least the following additional problems get triggered:
Labels get shown for elements that have the wrong Geometry type. (to
Green labels on the points, red labels on the polygons, placement set so they don't overlap:
zoomed in to a single point, no overlapping polygon anywhere near:
exporting to shapefiles fails with errors
e.g. exporting to an ESRI shapefile of the points layer gives
Instructions don't work on a mac.
Tested versions:
QGIS 3.8.2 - macOS Catalina 10.15.3 - works as expected
QGIS 3.10.2 - macOS Catalina 10.15.3 - bug
QGIS 3.12.0 - macOS Catalina 10.15.3 - bug
Additional context
The text was updated successfully, but these errors were encountered: