-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Open
Labels
BugEither a bug report, or a bug fix. Let's hope for the latter!Either a bug report, or a bug fix. Let's hope for the latter!ProcessingRelating to QGIS Processing framework or individual Processing algorithmsRelating to QGIS Processing framework or individual Processing algorithms
Description
What is the bug or the crash?
Using points as an input layer and a polygon as an overlay layer with the "Difference" processing tool produces an incorrect result which is that points inside the polygon aren't shown on the map but are still present in the attribute table.
Probably related to:
- Union fails when using a point and a polygon layer #44801
- Algorithm "Difference" failing to execute properly #49291
- Fix difference algorithm when differencing a point results in a null geometry #49300
Steps to reproduce the issue
# Create point layer
pts = QgsVectorLayer("Point?crs=EPSG:3857", "pts", "memory")
for wkt in ('Point (0 0)', 'Point (0 2)'):
geom = QgsGeometry.fromWkt(wkt)
fet = QgsFeature()
fet.setGeometry(geom)
pts.dataProvider().addFeature(fet)
# Create polygon layer
poly = QgsVectorLayer("Polygon?crs=EPSG:3857", "polygon", "memory")
wkt = 'Polygon ((-1 1, 1 1, 1 -1, -1 -1, -1 1))'
geom = QgsGeometry.fromWkt(wkt)
fet = QgsFeature()
fet.setGeometry(geom)
poly.dataProvider().addFeature(fet)
# Keep point outside polygon using "Difference"
pts_diff = processing.run("native:difference", {
'INPUT':pts,
'OVERLAY':poly,
'OUTPUT':'TEMPORARY_OUTPUT'
})["OUTPUT"]
# Keep point outside polygon using "Extract by Location" with "disjoint" predicate
pts_extract = processing.run("native:extractbylocation", {
'INPUT':pts,
'PREDICATE':[2],
'INTERSECT':poly,
'OUTPUT':'TEMPORARY_OUTPUT'
})["OUTPUT"]
# Check remaining points
pts_diff.dataProvider().featureCount() # 2 (bad)
pts_extract.dataProvider().featureCount() # 1 (ok)
QgsProject.instance().addMapLayer(poly)
QgsProject.instance().addMapLayer(pts_diff) # show one point on map but two points in attribute table
QgsProject.instance().addMapLayer(pts_extract) # show one point on map and in attribute tableVersions
QGIS 3.40.4
GEOS 3.13.0-CAPI-1.19.0
Windows 11 Enterprise 23H2
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
BugEither a bug report, or a bug fix. Let's hope for the latter!Either a bug report, or a bug fix. Let's hope for the latter!ProcessingRelating to QGIS Processing framework or individual Processing algorithmsRelating to QGIS Processing framework or individual Processing algorithms