qgis / QGIS

QGIS is a free, open source, cross platform (lin/win/mac) geographical information system (GIS)
https://qgis.org
GNU General Public License v2.0
10.52k stars 2.99k forks source link

Layers added by QGIS are not correct if datasource is a collection #47610

Closed pathmapper closed 2 years ago

pathmapper commented 2 years ago

What is the bug or the crash?

GML import - Layers created by QGS are not correct:

Steps to reproduce the issue

  1. Drag'n'drop test.zip in GIS.
  2. Select all layers and click "Add Layers". image
  3. Show feature count for all layers.
  4. See error:
    • two polygon layers were added (and no line layer)
    • the attributes of all three GML features are included for both layers

image

Versions

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">

QGIS version | 3.24.0-Tisler | QGIS code revision | 6b44a42058 -- | -- | -- | -- Qt version | 5.15.2 Python version | 3.9.2 GDAL/OGR version | 3.2.2 PROJ version | 7.2.1 EPSG Registry database version | v10.008 (2020-12-16) GEOS version | 3.9.0-CAPI-1.16.2 SQLite version | 3.34.1 PDAL version | 2.2.0 PostgreSQL client version | 13.5 (Debian 13.5-0+deb11u1) SpatiaLite version | 5.0.1 QWT version | 6.1.4 QScintilla2 version | 2.11.6 OS version | Debian GNU/Linux 11 (bullseye)   |   |   |   Active Python plugins db_manager | 0.1.20 grassprovider | 2.12.99 processing | 2.12.99 sagaprovider | 2.12.99 MetaSearch | 0.3.6 ### Supported QGIS version - [X] I'm running a supported QGIS version according to the roadmap. ### New profile - [X] I tried with a new QGIS profile ### Additional context Test data is NAS ALKIS GML which should be loaded using https://gdal.org/drivers/vector/nas.html. **ogrinfo result:** ``` ogrinfo test.xml AX_SonstigesBauwerkOderSonstigeEinrichtung INFO: Open of `test.xml' using driver `NAS' successful. Layer name: AX_SonstigesBauwerkOderSonstigeEinrichtung Geometry: Unknown (any) Feature Count: 3 Extent: (307471.977000, 5686045.318000) - (321435.899000, 5692558.598050) Layer SRS WKT: (unknown) gml_id: String (16.0) identifier: String (28.0) beginnt: String (20.0) advStandardModell: String (4.0) sonstigesModell: String (5.0) anlass: Integer (0.0) art: String (37.0) uri: String (28.0) AX_Datenerhebung: Integer (0.0) bauwerksfunktion: Integer (0.0) gehoertZu: String (16.0) OGRFeature(AX_SonstigesBauwerkOderSonstigeEinrichtung):1 gml_id (String) = DENW33AL0000QtU2 identifier (String) = urn:adv:oid:DENW33AL0000QtU2 beginnt (String) = 2019-10-07T12:27:16Z advStandardModell (String) = DLKM sonstigesModell (String) = NWABK anlass (Integer) = 300200 art (String) = urn:adv:fachdatenverbindung:AA_Antrag uri (String) = urn:adv:oid:DENW33AL0000QtJh AX_Datenerhebung (Integer) = 4300 bauwerksfunktion (Integer) = 1610 gehoertZu (String) = DENW33AL0000bhpZ CURVEPOLYGON (COMPOUNDCURVE (CIRCULARSTRING (307480.693 5686050.835,307479.981 5686051.451,307479.493 5686052.256),CIRCULARSTRING (307479.493 5686052.256,307479.275 5686053.166,307479.345 5686054.1),(307479.345 5686054.1,307475.965 5686055.954,307477.888 5686059.46,307479.142 5686059.88,307478.27 5686062.72,307471.977 5686051.561,307474.199 5686046.442,307476.422 5686045.318,307478.145 5686046.142,307480.454 5686050.397,307480.693 5686050.835))) OGRFeature(AX_SonstigesBauwerkOderSonstigeEinrichtung):2 gml_id (String) = DENW33AL0000Mhmc identifier (String) = urn:adv:oid:DENW33AL0000Mhmc beginnt (String) = 2018-04-30T07:22:23Z advStandardModell (String) = DLKM sonstigesModell (String) = NWABK anlass (Integer) = 300200 art (String) = urn:adv:fachdatenverbindung:AA_Antrag uri (String) = urn:adv:oid:DENW33AL0000MhkJ AX_Datenerhebung (Integer) = 4300 bauwerksfunktion (Integer) = 1702 COMPOUNDCURVE (CIRCULARSTRING (321351.892 5692556.046,321353.013 5692557.408,321354.538 5692558.295),CIRCULARSTRING (321354.538 5692558.295,321356.275 5692558.598,321358.01 5692558.279),CIRCULARSTRING (321358.01 5692558.279,321359.616 5692557.64,321361.194 5692556.936),CIRCULARSTRING (321361.194 5692556.936,321362.742 5692556.168,321364.257 5692555.338),CIRCULARSTRING (321364.257 5692555.338,321367.777 5692553.433,321371.255 5692551.452),CIRCULARSTRING (321371.255 5692551.452,321374.689 5692549.395,321378.078 5692547.264),CIRCULARSTRING (321378.078 5692547.264,321378.221 5692547.174,321378.364 5692547.083),CIRCULARSTRING (321378.364 5692547.083,321382.966 5692544.049,321387.462 5692540.859),CIRCULARSTRING (321387.462 5692540.859,321391.478 5692537.808,321395.396 5692534.634),CIRCULARSTRING (321395.396 5692534.634,321399.252 5692531.303,321403.001 5692527.853),CIRCULARSTRING (321403.001 5692527.853,321406.692 5692524.234,321410.266 5692520.498),CIRCULARSTRING (321410.266 5692520.498,321411.342 5692519.325,321412.406 5692518.141),(321412.406 5692518.141,321418.736 5692520.308),CIRCULARSTRING (321418.736 5692520.308,321419.682 5692519.34,321420.635 5692518.38),CIRCULARSTRING (321420.635 5692518.38,321424.316 5692514.818,321428.105 5692511.371),CIRCULARSTRING (321428.105 5692511.371,321431.953 5692508.08,321435.899 5692504.909)) OGRFeature(AX_SonstigesBauwerkOderSonstigeEinrichtung):3 gml_id (String) = DENW33AL0000NOOc identifier (String) = urn:adv:oid:DENW33AL0000NOOc beginnt (String) = 2018-11-07T10:50:58Z advStandardModell (String) = DLKM sonstigesModell (String) = NWABK anlass (Integer) = 300200 art (String) = urn:adv:fachdatenverbindung:AA_Antrag uri (String) = urn:adv:oid:DENW33AL0000NOL1 AX_Datenerhebung (Integer) = 4300 bauwerksfunktion (Integer) = 1701 LINESTRING (312064.691 5687679.855,312114.636 5687714.502) ``` --- The import dialog (Select Items to add) shows correct layer types and feature counts. --- If you change the order of features in GML (moving a linestring feature to 1st position, [test_2.zip](https://github.com/qgis/QGIS/files/8169910/test_2.zip)), two line layers will be created (and no polygon layer). So it looks like QGIS is choosing the layer type only based on the first GML feature. ![image](https://user-images.githubusercontent.com/20856381/156374505-36038731-e6cb-4ffa-a70e-c81d8725175a.png)
gioman commented 2 years ago

It seems there is something fishy going on, not sure if is QGIS or OGR.

ogrinfo shows only 2 tables in the XML:


ogrinfo -so test.xml
INFO: Open of `test.xml'
      using driver `NAS' successful.
1: AX_SonstigesBauwerkOderSonstigeEinrichtung
2: ALKIS_beziehungen (None)

one of geom unknown


ogrinfo -so test.xml AX_SonstigesBauwerkOderSonstigeEinrichtung
INFO: Open of `test.xml'
      using driver `NAS' successful.

Layer name: AX_SonstigesBauwerkOderSonstigeEinrichtung
Geometry: Unknown (any)
Feature Count: 3
Extent: (307471.977000, 5686045.318000) - (321435.899000, 5692558.598050)
Layer SRS WKT:
(unknown)
gml_id: String (16.0)
identifier: String (28.0)
beginnt: String (20.0)
advStandardModell: String (4.0)
sonstigesModell: String (5.0)
anlass: Integer (0.0)
art: String (37.0)
uri: String (28.0)
AX_Datenerhebung: Integer (0.0)
bauwerksfunktion: Integer (0.0)
gehoertZu: String (16.0)

the other with no geom

ogrinfo -so test.xml ALKIS_beziehungen
INFO: Open of `test.xml'
      using driver `NAS' successful.

Layer name: ALKIS_beziehungen
Geometry: None
Feature Count: 1
Layer SRS WKT:
(unknown)
beziehung_von: String (0.0)
beziehungsart: String (0.0)
beziehung_zu: String (0.0)

Translating to GPKG

ogr2ogr -f GPKG test.gpkg test.xml

gives the same results both from the CLI


ogrinfo -so test.gpkg
INFO: Open of `test.gpkg'
      using driver `GPKG' successful.
1: AX_SonstigesBauwerkOderSonstigeEinrichtung
2: ALKIS_beziehungen (None)

as also in QGIS

image

pathmapper commented 2 years ago

I think OGR returns Geometry: Unknown (any) because the layer contains a mix of geometries:

1 x CURVEPOLYGON 1 x COMPOUNDCURVE 1 x LINESTRING

So I would expect that this results in

1 x Polygon layer in QGIS with the CURVEPOLYGON feature 1 x Line layer in QGIS with the COMPOUNDCURVE and LINESTRING features

This is also what the QGIS import dialog shows, but the layers added in QGIS are different compared to this.

gioman commented 2 years ago

So I would expect that this results in

@pathmapper sure, but first you have to check what ogr returns when it reads that datasource. And from what you say it seems to be wrong too (so QGIS cannot get it right anyway).

pathmapper commented 2 years ago

@gioman where do you think the result of ogrinfo is wrong? Do you would expect three layers in total instead of two?

Why is the import dialog correct? What is shown in the dialog is also based on what ogr returns, right?

gioman commented 2 years ago

Why is the import dialog correct?

@pathmapper you are right, problem seems to be in QGIS when it loads the layers, but is not specific to this driver/format, it happens also if you translate that datasource to gpkg (see attached file)

test.zip .

pathmapper commented 2 years ago

Thanks @gioman, you're right, too :-)

Confirmed the same problem exists also with your test gpkg.