def testInvalidGeomCheck(self): req = QgsFeatureRequest().setFilterFids( [5, 6]).setInvalidGeometryCheck(QgsFeatureRequest.GeometrySkipInvalid) self.assertEqual(req.filterType(), QgsFeatureRequest.FilterFids) self.assertEqual(req.filterFid(), -1) self.assertCountEqual(req.filterFids(), [5, 6]) self.assertEqual(req.invalidGeometryCheck(), QgsFeatureRequest.GeometrySkipInvalid) req.setInvalidGeometryCheck(QgsFeatureRequest.GeometryNoCheck) self.assertEqual(req.invalidGeometryCheck(), QgsFeatureRequest.GeometryNoCheck)
def testAssignment(self): req = QgsFeatureRequest().setFilterFids([8, 9]).setFilterRect( QgsRectangle(1, 2, 3, 4)).setInvalidGeometryCheck( QgsFeatureRequest.GeometrySkipInvalid).setLimit(6).setFlags( QgsFeatureRequest.ExactIntersect).setSubsetOfAttributes( [1, 4]).setTimeout(6).setRequestMayBeNested(True) context = QgsExpressionContext() scope = QgsExpressionContextScope() scope.setVariable('a', 6) context.appendScope(scope) req.setExpressionContext(context) method = QgsSimplifyMethod() method.setMethodType(QgsSimplifyMethod.PreserveTopology) req.setSimplifyMethod(method) context = QgsCoordinateTransformContext() req.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:3857'), context) req2 = QgsFeatureRequest(req) self.assertEqual(req2.limit(), 6) self.assertCountEqual(req2.filterFids(), [8, 9]) self.assertEqual(req2.filterRect(), QgsRectangle(1, 2, 3, 4)) self.assertEqual(req2.spatialFilterType(), Qgis.SpatialFilterType.BoundingBox) self.assertEqual(req2.invalidGeometryCheck(), QgsFeatureRequest.GeometrySkipInvalid) self.assertEqual(req2.expressionContext().scopeCount(), 1) self.assertEqual(req2.expressionContext().variable('a'), 6) self.assertEqual( req2.flags(), QgsFeatureRequest.ExactIntersect | QgsFeatureRequest.SubsetOfAttributes) self.assertEqual(req2.subsetOfAttributes(), [1, 4]) self.assertEqual(req2.simplifyMethod().methodType(), QgsSimplifyMethod.PreserveTopology) self.assertEqual(req2.destinationCrs().authid(), 'EPSG:3857') self.assertEqual(req2.timeout(), 6) self.assertTrue(req2.requestMayBeNested()) # copy distance within request req = QgsFeatureRequest().setDistanceWithin( QgsGeometry.fromWkt('LineString( 0 0, 10 0, 11 2)'), 1.2) req2 = QgsFeatureRequest(req) self.assertEqual(req2.spatialFilterType(), Qgis.SpatialFilterType.DistanceWithin) self.assertEqual(req2.referenceGeometry().asWkt(), 'LineString (0 0, 10 0, 11 2)') self.assertEqual(req2.distanceWithin(), 1.2) self.assertEqual(req2.filterRect(), QgsRectangle(-1.2, -1.2, 12.2, 3.2))