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.04k stars 2.92k forks source link

`Translate geometry` does not create a 3D vector from 2D if deltaZ is an expression #56495

Open nicogodet opened 4 months ago

nicogodet commented 4 months ago

What is the bug or the crash?

I try to create a PointZ vector from Point with Z attribute. For this I use native:translategeometry (maybe it's not the best way, if so, guide me 😃).

Sample data for test : Point with Z attr.zip

Steps to reproduce the issue

Execute native:translategeometry with provided data and set "Z" field as deltaZ data defined value. See, it creates a Point layer image

Set a constant value for deltaZ image

Versions

3.34.3

Supported QGIS version

New profile

Additional context

No response

lbartoletti commented 4 months ago

Can you try with native:geometrybyexpression?

nicogodet commented 4 months ago

@lbartoletti Yup that works

 processing.run(
    "native:geometrybyexpression",
    {'INPUT':'C:/Users/godet/AppData/Local/Temp/processing_XEbwJc/a62d9d34df06403fa7fecb7207b5ad68/dropmzvalues.shp',
    'OUTPUT_GEOMETRY':2,
    'WITH_Z':True,
    'WITH_M':False,
    'EXPRESSION':'make_point(x($geometry), y($geometry), "Z")',
    'OUTPUT':'TEMPORARY_OUTPUT'}
)

But the bug remains in native:translategeometry as it is supposed to create a 3D geometry if deltaZ != 0. https://github.com/qgis/QGIS/blob/a738296d6c79fddcbf450a2ed5c82bba52753e58/src/analysis/processing/qgsalgorithmtranslate.cpp#L159-L160

lbartoletti commented 4 months ago

But the bug remains in native:translategeometry as it is supposed to create a 3D geometry if deltaZ != 0.

Yes, but I think you should have a 3D geometry in input.

I tested with a 2D Point (memory layer) and a stupid expression ($y - 40) and it's ok for me.

Input: Point (6.63495238951347677 45.9354297419651445) Output: PointZ (6.63495238951347677 45.9354297419651445 5.9354297419651445)

lbartoletti commented 4 months ago

Can you try with native:geometrybyexpression?

And you can also try native:setzvalue

nicogodet commented 4 months ago

I tested with a 2D Point (memory layer) and a stupid expression ($y - 40) and it's ok for me.

Input: Point (6.63495238951347677 45.9354297419651445) Output: PointZ (6.63495238951347677 45.9354297419651445 5.9354297419651445)

image

If you output to a file (not a TEMPORARY_OUTPUT), the Z value disappear

image

And you can also try native:setzvalue

How could I miss this one... Works fine of course.

lbartoletti commented 4 months ago

If you output to a file (not a TEMPORARY_OUTPUT), the Z value disappear

Can you try with a GPKG please?

with @florentfgrs we have encountered strange behavior with processing and Z

nicogodet commented 4 months ago

Same image

agiudiceandrea commented 4 months ago

I've tested using QGIS 3.35 with the provide layer and steps, and I can confirm the described behaviour.

It looks like the QgsTranslateAlgorithm::outputWkbType function only takes in consideration the value of the DELTA_Z fixed parameter (mDeltaZ) and not also the calculated value of the data defined override expression.

https://github.com/qgis/QGIS/blob/a738296d6c79fddcbf450a2ed5c82bba52753e58/src/analysis/processing/qgsalgorithmtranslate.cpp#L156-L164

Anyway, what will be the output wkb when an input layer has some features with the calculated (via data defined override) DELTA_Z = 0 and other ones with the calculated (via data defined override) DELTA_Z <> 0? Maybe QgsTranslateAlgorithm::outputWkbType should always add Z and/or M to the wkb when the data defined override is set for the DELTA_Z and/or the DELTA_M regardless of the actual calculated value of the data defined override expression.