[QGIS-Developer] cannot import processing algorithm in 3.6

Tim Sutton tim at kartoza.com
Thu Mar 21 23:36:56 PDT 2019


Hi

> On 21 Mar 2019, at 06:43, Nyall Dawson <nyall.dawson at gmail.com> wrote:
> 
> On Thu, 21 Mar 2019 at 15:59, Raymond Nijssen <r.nijssen at terglobo.nl> wrote:
>> 
>> 
>>>     def toLines(geom):
>>>         return QgsGeometry(geom.get().boundary())
>>> 
>>> (Using https://qgis.org/pyqgis/master/core/QgsAbstractGeometry.html#qgis.core.QgsAbstractGeometry.boundary
>>> )
>>> 
>>> Nyall
>> 
>> Thanks Nyall, that works!
> 
> Great, thanks for the confirmation. And because I've got to do mapping
> all day, I'm in a good mood, and you get a free PyQGIS lesson:
> 
> geom.get() : gives you the underlying fundamental geometry object
> attached to the feature. QgsFeature.geometry() returns a QgsGeometry
> object, which is more or less a "container" for geometries. It's got
> some convenient methods which apply to ALL geometry types, but
> sometimes you need to dig down to the actual geometry primitive. In
> that case you use geometry.get(), and you get the fundamental
> QgsPoint/QgsLineString/QgsPolygon/etc object. It's actually generally
> preferable to call "geometry.constGet()", IF you are doing some
> operation which doesn't alter the geometry in place (like you are
> here). But that's a complex microoptimisation.
> 
> geom.get().boundary() gives you the topological boundary of the
> primitive. For polygons this is their exterior + interior rings, for
> lines it's their start and end point (unless it's a closed ring, in
> which case you get a null geometry). Points have no boundary. Using
> boundary() to convert polygons to lines is the most efficient method -
> it's very heavily optimised, and works perfectly with curved geometry
> types and maintains any Z or M values which may be present.
> 
> Lastly, you need to wrap the result back up into a QgsGeometry object
> - hence QgsGeometry(....boundary() ). This is because most of QGIS API
> works with QgsGeometry objects (remember, they are like "containers"
> holding a geometry), and NOT the fundamental geometry objects.
> 
> Done! A super-efficient, rock solid approach which will work with all
> input geometry types. Win!
> 
> (for reference - this is what the polygons to lines algorithm actually
> does in the background too)

Thanks for the lesson for those of us watching from the sidelines too!

Regards

Tim

> 
> Nyall
> 
> 
> 
> 
>> 
>>> 
>>> 
>>>> 
>>>> I will try tomorrow.
>>>> 
>>>> One last question, it seems to me like the old code is working again in
>>>> 3.7. Can you confirm that?
>>> 
>>> Shouldn't be -- maybe you have a leftover .py file here?
>> 
>> Indeed. I did a clean install and it is not working in my 3.7 anymore.
>> 
>> 
>> Regards,
>> Raymond
> _______________________________________________
> 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

—








Tim Sutton

Co-founder: Kartoza
Ex Project chair: QGIS.org

Visit http://kartoza.com <http://kartoza.com/> to find out about open source:

Desktop GIS programming services
Geospatial web development
GIS Training
Consulting Services

Skype: timlinux 
IRC: timlinux on #qgis at freenode.net

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20190322/3a34fbe3/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: KartozaNewLogoThumbnail.jpg
Type: image/jpeg
Size: 6122 bytes
Desc: not available
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20190322/3a34fbe3/attachment-0001.jpg>


More information about the QGIS-Developer mailing list