[QGIS-Developer] geom.isValid() does not work in python

Andrea Giudiceandrea andreaerdna at libero.it
Sun Jul 18 23:38:09 PDT 2021


Il 19/07/2021 07:47, Raymond Nijssen ha scritto:

 > print( geom.isGeosValid() )

> geom2 = geom.constGet()
 > print( geom2.isValid() )

> geom3 = geom.get()
 > print( geom3.isValid() )

> I think geom2 and geom3 are the exact same thing. And the parameter 0 or 
> 1 (or none at all) don't seem to change anything to the validation type, 
> since they don't raise errors.

Hi Raymond,
for some insight of get() and constGet() in PyQGIS, please read a 
previous thread [1] on the same argument.

The flags used in isValid() "indicates optional flags which control the 
type of validity checking performed (corresponding to 
QgsGeometry.ValidityFlags)" [2].
The only flag available is "FlagAllowSelfTouchingHoles: Indicates that 
self-touching holes are permitted" [3].
isValid() was introduced in 3.8 [4] and uses GEOS to perform the 
validity check.
isGeosValid(), which uses the same QgsGeometry.ValidityFlags, actaully 
relies on isValid() and thus on GEOS to perform the validity check, so 
they act in the same way AFAIK.

Maybe Nyall Dawson could share more light on this...

With validateGeometry() you could specify the validity check method to 
use (QGIS or GEOS) beside the ValidityFlags.

Best regards.

Andrea Giudiceandrea


[1] 
http://osgeo-org.1560.x6.nabble.com/QGIS-Developer-Do-QgsGeometry-constGet-e-constParts-return-non-modifiable-or-modifiable-reference-in-td5457143.html
[2] 
https://qgis.org/pyqgis/3.16/core/QgsAbstractGeometry.html?highlight=isvalid#qgis.core.QgsAbstractGeometry.isValid
[3] 
https://qgis.org/api/classQgsGeometry.html#a9079690dc8d58af969fae36d16499923
[4] https://github.com/qgis/QGIS/pull/9293


More information about the QGIS-Developer mailing list