[QGIS-Developer] Proper way to create polygons in PyQGIS

C Hamilton adenaculture at gmail.com
Wed Nov 1 13:15:18 PDT 2017


I put in a ticket a while back. Here it is:

https://issues.qgis.org/issues/16524#change-83842

The problem does not happen with the "New Temporary Scratch Layer". It only
occurs with other 3rd party plugins with memory layers. You can easily
reproduce it by either using using the "New Memory Layer" plugin and create
two layers with polygons that overlap then do a geoprocessing difference or
by using the Shape Tools plugin "Create Shapes" to create a polygon. Create
two polygon layers where the polygons overlap and then run difference. I
could probably write a script that does this to show it off if you want, if
this is not sufficient.

Thanks,

Calvin

On Wed, Nov 1, 2017 at 3:39 PM, Matthias Kuhn <matthias at opengis.ch> wrote:

> Hi Hamilton,
>
> It might be just me missing some context, in this case sorry.
>
> What exactly does go wrong?
>
> Would it be possible for you to generate some minimal, self-contained
> python code that shows the issue? Like generating one or two memory layers,
> plus an additional layer if required, invoke processing.runalg and provide
> expected and real results?
>
> This can then be integrated into our test-suite, so we can fix things and
> avoid this in the future.
>
> Thanks
> Matthias
>
> On 11/01/2017 08:22 PM, C Hamilton wrote:
>
> It has come to my attention that a few of the plugins that create memory
> layer polygons do not work correctly with the Geoprocessing Tools such as
> Difference. Two examples include the "New Memory Layer" plugin (which is
> being replaced by core) and my own Shape Tools plugin. I'm sure that others
> out there have the same problem. What happens is that when you create the
> polygons with these tools and you run the Geoprocessing algorithms such as
> the Difference operator, you get features back that do not contain the
> proper output polygons.
>
> My question is how do I create these polygons to be valid to the new
> Geoprocessing algorithms? Currently I do the following:
>
> polygonLayer = QgsVectorLayer("Polygon?crs=epsg:4326", "Layer Name", "
> memory")
> ppolygon = polygonLayer.dataProvider()
> ...
> featureout = QgsFeature()
>
> featureout.setGeometry(QgsGeometry.fromPolygon([pts]))
>
> # pts is an array of QgsPoints of the polygon vertices
>
> ppolygon.addFeatures([featureout])
> ...
> polygonLayer.updateExtents()
> QgsMapLayerRegistry.instance().addMapLayer(polygonLayer)
>
> What needs to be different? One of my concerns is that the geoprocessing
> algorithms takes the data, executes, fails to generate proper results, and
> doesn't give the user any warning that the results may be wrong. I sure
> hope this is only a memory layer issue and not also an issue with loading
> data from files or databases.
>
> Thanks,
>
> Calvin
>
>
> _______________________________________________
> QGIS-Developer mailing listQGIS-Developer at 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 at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20171101/d0daa327/attachment-0001.html>


More information about the QGIS-Developer mailing list