Re: [QGIS-Developer] geom.isValid() does not work in python
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 ___ QGIS-Developer mailing list QGIS-Developer@lists.osgeo.org List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Re: [QGIS-Developer] geom.isValid() does not work in python
Thank you Andrea! I also asked this on the QGIS Community Telegram group and got a few answers. Still a bit confusing though. Here's a test script: wkt = 'MULTIPOLYGON(((-9 0, 0 9, 9 0, 0 -9, -9 0),(-8 0, 0 8, 8 0, 0 -8, -8 0)),((-7 0, 0 7, 7 0, 0 -7, -7 0)))' geom = QgsGeometry.fromWkt(wkt) print(geom) print( geom.validateGeometry() ) # 0 = QGIS (Returns an error) print( geom.validateGeometry(0) ) # 0 = QGIS (Returns an error) print( geom.validateGeometry(1) ) # 1 = GEOS print( geom.isGeosValid() ) # Why does this one even exist??? geom2 = geom.constGet() print(geom2) print( geom2.isValid() ) print( geom2.isValid(0) ) print( geom2.isValid(1) ) geom3 = geom.get() print(geom3) print( geom2.isValid() ) print( geom3.isValid(0) ) print( geom3.isValid(1) ) 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. (BTW I'm doing this cause QGIS validation raises an error for multipolygons having a polygon within an inner of another polygon, which should be fixed. That's also the example wkt here.) On 18-07-2021 13:49, Andrea Giudiceandrea wrote: Il 18/07/2021 11:46, Raymond Nijssen ha scritto: How can I run ths isValid() function on a geometry. I would think my Polygon Geometry would inherit all functions from the QgsAbstractGeometry base class, but it seems it doesn't. I get: AttributeError: 'QgsGeometry' object has no attribute 'isValid' Hi Raymond, the QGIS Python API documentation clarify that: "The actual geometry representation is stored as a QgsAbstractGeometry within the container, and can be accessed via the get() method"[1]. So, I think geom.get().isValid() will work without errors. Best regards. Andrea [1] https://qgis.org/pyqgis/3.16/core/QgsGeometry.html#module-QgsGeometry ___ QGIS-Developer mailing list QGIS-Developer@lists.osgeo.org List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer ___ QGIS-Developer mailing list QGIS-Developer@lists.osgeo.org List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
Re: [QGIS-Developer] geom.isValid() does not work in python
Il 18/07/2021 11:46, Raymond Nijssen ha scritto: How can I run ths isValid() function on a geometry. I would think my Polygon Geometry would inherit all functions from the QgsAbstractGeometry base class, but it seems it doesn't. I get: AttributeError: 'QgsGeometry' object has no attribute 'isValid' Hi Raymond, the QGIS Python API documentation clarify that: "The actual geometry representation is stored as a QgsAbstractGeometry within the container, and can be accessed via the get() method"[1]. So, I think geom.get().isValid() will work without errors. Best regards. Andrea [1] https://qgis.org/pyqgis/3.16/core/QgsGeometry.html#module-QgsGeometry ___ QGIS-Developer mailing list QGIS-Developer@lists.osgeo.org List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer