lizmap-web-client
lizmap-web-client copied to clipboard
Editing same layer with two different geometry columns and type fails
What is the bug?
I have a layer to draw objects that can be points or polygon. I created 2 different geometry columns in my PostGIS table :
- centroide for points (-> geometry(POINT,2154))
- geometrie for polygons (-> geometry(POLYGON,2154))
Everything's fine in my QGIS project. But once in Lizmap, when I try to save a new POLYGON, it fails and I get an error about geometry type. Lizmap tries to save my polygon into the "centroide" column. As if lizmap was looking into the geometry_columns view and take the first row for the table I edit...
Steps to reproduce the issue
Create a POSTGIS table with two geometry columns, one for points and one for polygon :
CREATE TABLE ponds (
id serial NOT NULL PRIMARY KEY,
name text,
centroide geometry(POINT, 2154),
geometrie geometry(POLYGON,2154)
);
Create a project that calls the same table twice, first time with centroide
as the geo column, second time with the geometrie
one.
Add try to insert a new polygon
Versions
QGIS 3.22 LIZMAP 3.5.14 QGIS serveur 3.22.16
Check Lizmap plugin
- [ ] I have done the step just before in the Lizmap QGIS desktop plugin before opening this ticket. Otherwise, my ticket is not considered valid and might get closed.
QGIS server version, only if the section above doesn't mention the QGIS Server version
No response
Operating system
? celui de 3Liz
Browsers
Firefox
Browsers version
116.0.2
Relevant log output
No response
I forgot to mention my actual workaround : I defined 2 views in PostGIS and I use it for Editing. As they are simple views, they can be used as tables and accept insert, update and delete statements..
quick code analysis : the geometry column is guessed (check if field is kind of geometry), https://github.com/3liz/lizmap-web-client/blob/c4fb911add7c571618a88bc2cb6b6b55e1927d98/lizmap/modules/lizmap/classes/qgisVectorLayer.class.php#L397
So when multiple geometry fields in table, the last one will be always be detected as geometry field, maybe we can check the geom type provided by qgis project (is it reliable ?)
I think @nworr is right.
To have two or more geometry column is not frequent, but could be useful in may cases IMHO. The only information about geometry column in the qgs
project file is on the datasource
xml tag. Take for instance this line in form_edition_snap.qgs
test project :
https://github.com/3liz/lizmap-web-client/blob/3a4f56122a3ba7b6084a8144b6cc3fc09418dae8/tests/qgis-projects/tests/form_edition_snap.qgs#L127
The information about geometry column is "stored" as (geom)
at the end of the string.
I couldn't find documentation on this.
@Gustry, @mdouchin, @nboisteault do you think that this information is reliable? If so, this information could be stored as a property in the qgisVectorLayer
class and could be used to get the correct geometry column.
@mind84 @nworr They are some unittests about geom column in datasource :
https://github.com/3liz/lizmap-web-client/blob/master/tests/units/edition/qgisVectorLayerDatasourceTest.php#L36
In these tests getDatasourceParameter('geocol')
they are a lot of occurences.
Maybe the function is not fully used ?
Maybe the function is not fully used ?
@Gustry thanks for the pointer, I'll check this function
@Gustry that's it !
$dbInfo->geometryColumn = $dtParams->geocol
could be used instead of
$dbInfo->geometryColumn = $fieldName;
Fixed by #4460