[QGIS-Developer] Geoprocessing Tools Fail with Memory Layers
Richard Duivenvoorde
rdmailings at duif.net
Sat Jan 6 00:19:28 PST 2018
Hi Calvin,
Confirmed here:
- creating the two memory(!) layers using Calvin's python code, and
running intersection returns one of the two polygons
- saving the same layers to gpkg and run intersection just works
(I thought that it would have something to do with OTF, but with or
without it it returns wrong).
Please create an issue for this.
I adapted your code to run in 2.99, and then with me it seems to work:
http://pix.toile-libre.org/?img=1515181793.png
The red part is the intersection?
What kind of (wrong) result do you get?
Maybe create an issue for it too, with some more screendumps with your
result and the expected result?
from qgis.core import QgsFeature, QgsVectorLayer, QgsPoint, QgsFeature
poly1 = QgsVectorLayer("Polygon?crs=epsg:4326", "Polygon 1", "memory")
dp = poly1.dataProvider()
pts = [QgsPointXY(-117.9031, 44.4169), QgsPointXY(-103.86080,
44.700146), QgsPointXY(-104.655656, 38.257599), QgsPointXY(-117.9031,
44.4169)]
f = QgsFeature()
f.setGeometry(QgsGeometry.fromPolygonXY([pts]))
dp.addFeatures([f])
poly1.updateExtents()
QgsProject.instance().addMapLayer(poly1)
poly2 = QgsVectorLayer("Polygon?crs=epsg:4326", "Polygon 2", "memory")
dp = poly2.dataProvider()
pts = [QgsPointXY(-115.27676, 40.242037), QgsPointXY(-101.32007,
41.387353), QgsPointXY(-102.1608432, 33.314810), QgsPointXY(-115.27676,
40.242037)]
f = QgsFeature()
f.setGeometry(QgsGeometry.fromPolygonXY([pts]))
dp.addFeatures([f])
poly2.updateExtents()
QgsProject.instance().addMapLayer(poly2)
Regards,
Richard
On 05-01-18 20:03, C Hamilton wrote:
> I've asked about this several time and have never gotten a real
> response. The following code creates two memory layer polygons that overlap.
>
> from qgis.core import (QgsFeature,
> QgsVectorLayer, QgsPoint, QgsFeature,
> QgsMapLayerRegistry)
>
> poly1 = QgsVectorLayer("Polygon?crs=epsg:4326", "Polygon 1", "memory")
> dp = poly1.dataProvider()
>
> pts = [QgsPoint(-117.9031, 44.4169), QgsPoint(-103.86080, 44.700146),
> QgsPoint(-104.655656, 38.257599), QgsPoint(-117.9031, 44.4169)]
> f = QgsFeature()
> f.setGeometry(QgsGeometry.fromPolygon([pts]))
> dp.addFeatures([f])
> poly1.updateExtents()
> QgsMapLayerRegistry.instance().addMapLayer(poly1)
>
> poly2 = QgsVectorLayer("Polygon?crs=epsg:4326", "Polygon 2", "memory")
> dp = poly2.dataProvider()
>
> pts = [QgsPoint(-115.27676, 40.242037), QgsPoint(-101.32007, 41.387353),
> QgsPoint(-102.1608432, 33.314810), QgsPoint(-115.27676, 40.242037)]
> f = QgsFeature()
> f.setGeometry(QgsGeometry.fromPolygon([pts]))
> dp.addFeatures([f])
> poly2.updateExtents()
> QgsMapLayerRegistry.instance().addMapLayer(poly2)
>
> From the QGIS menu if you run the Geoprocessing tools such as
> Intersection or Difference on the two polygons the algorithms fail to
> return the correct results. Are memory layers no longer supported in
> QGIS or is this a bug in the Processing code? In QGIS 14 this code works
> fine, but with QGIS 18.x and QGIS 2.99 it fails.
>
> Thanks,
>
> Calvin
>
>
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>
More information about the QGIS-Developer
mailing list