[QGIS-Developer] Polygon Geoprocessing Tools Fail with the attached script

C Hamilton adenaculture at gmail.com
Fri Dec 22 09:13:29 PST 2017


I have attached a script that creates two polygon layers in QGIS 2.18. Run
the script to create the polygons and then run one of the Geoprocessing
Tools such as Difference, Symmetrical Difference, or Clip and you get the
wrong results. If you do the same thing in QGIS 2.14 you get the correct
results.

I suspect that the issue is related to the fact that these algorithms have
been moved to Processing and that it is more strict on how polygons need to
be created.

The question is how do polygons need to be created so that they work with
the processing algorithms.

Next my concern is that if one has a polygon layer that does not conform to
the proper standard and the user runs one of these algorithms, then the
user may be getting back invalid results and may not know that they are
invalid.

Regards,

Calvin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20171222/028ebcd2/attachment.html>
-------------- next part --------------
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)


More information about the QGIS-Developer mailing list