Skip to content
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

wkbType of geometries is not same as the layer with z and with geopackage #50218

Closed
2 tasks done
Koyaani opened this issue Sep 15, 2022 · 4 comments · Fixed by #50233
Closed
2 tasks done

wkbType of geometries is not same as the layer with z and with geopackage #50218

Koyaani opened this issue Sep 15, 2022 · 4 comments · Fixed by #50233
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter!

Comments

@Koyaani
Copy link
Contributor

Koyaani commented Sep 15, 2022

What is the bug or the crash?

When geometries are fetch from a Geopackage table with Z, the wkbType of geometries are 25D type (0x80000001) while the wkbType of the layer is Z (10XX). The problem is not present with other providers like shapefile or PostGis, nor when there is no Z or when there is ZM.

Steps to reproduce the issue

  1. Create a new table in a Geopackage with Z (but without M)
  2. Create a new geometry, but without save the layer
  3. Open the python console and execute [f.geometry().wkbType() for f in iface.activeLayer().getFeatures()]
    -> The print displays : [1003]
  4. Save the layer
  5. Execute [f.geometry().wkbType() for f in iface.activeLayer().getFeatures()]
    -> The print displays : [-2147483645]
  6. Execute iface.activeLayer().wkbType()
    -> The print displays : 1003
Peek.15-09-2022.15-11.webm

Versions

3.22, 3.26 and master

Supported QGIS version

  • I'm running a supported QGIS version according to the roadmap.

New profile

  • I tried with a new QGIS profile

Additional context

No response

@Koyaani Koyaani added the Bug Either a bug report, or a bug fix. Let's hope for the latter! label Sep 15, 2022
@lbartoletti
Copy link
Member

I guess there is a problem with the cast to the Qgs Wkb Type from the OGR one.

Something like this, works for me:

diff --git a/src/core/qgsogrutils.cpp b/src/core/qgsogrutils.cpp
index 3ff54b3e52a..d024be52356 100644
--- a/src/core/qgsogrutils.cpp
+++ b/src/core/qgsogrutils.cpp
@@ -628,7 +628,7 @@ std::unique_ptr< QgsMultiPoint > ogrGeometryToQgsMultiPoint( OGRGeometryH geom )

 std::unique_ptr< QgsLineString > ogrGeometryToQgsLineString( OGRGeometryH geom )
 {
-  QgsWkbTypes::Type wkbType = static_cast<QgsWkbTypes::Type>( OGR_G_GetGeometryType( geom ) );
+  QgsWkbTypes::Type wkbType = QgsOgrUtils::ogrGeometryTypeToQgsWkbType( OGR_G_GetGeometryType( geom ) );

   int count = OGR_G_GetPointCount( geom );
   QVector< double > x( count );

@lbartoletti
Copy link
Member

@rouault I wonder why it works for shapefile and the geopackage needs a “better” cast?

@rouault
Copy link
Contributor

rouault commented Sep 16, 2022

@rouault I wonder why it works for shapefile and the geopackage needs a “better” cast?

I'm not sure either, but your fix looks good to me

@lbartoletti
Copy link
Member

@rouault I wonder why it works for shapefile and the geopackage needs a “better” cast?

Because Shapefile use ZM and not only Z.

lbartoletti added a commit to lbartoletti/QGIS that referenced this issue Sep 16, 2022
As mentionned by @Koyaani a PolygonZ is opened as a Polygon25D and
can cause problems.

This fix use the QgsOgrUtils method to return the true QGIS wkbType.

Fixes qgis#50218
qgis-bot pushed a commit that referenced this issue Sep 19, 2022
As mentionned by @Koyaani a PolygonZ is opened as a Polygon25D and
can cause problems.

This fix use the QgsOgrUtils method to return the true QGIS wkbType.

Fixes #50218
qgis-bot pushed a commit that referenced this issue Sep 19, 2022
As mentionned by @Koyaani a PolygonZ is opened as a Polygon25D and
can cause problems.

This fix use the QgsOgrUtils method to return the true QGIS wkbType.

Fixes #50218
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter!
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants