[Qgis-user] extracting vertices from a multipolygon using Field Calculator Function Editor

Zoltan zoltans at geograph.co.za
Mon Oct 18 23:36:25 PDT 2021


Thank you Stefan,
I knew it would be as simple as that, but could not find it (the 'Java 
style' in the QgsGeometry class must have made me skip experimenting 
with that )
In Afrikaans (I am South African/Hungarian) there is a saying:  'As jy 
dom is, moet jy ...xxx'  -  and that was applicable to me in this case :-)

I wrote the script yesterday in a freestanding (PyCharm) environment to 
solve the issue, as I needed to 'get it done', but this info is useful 
for future.

Yesterday was the first time I was trying out the function editor and, 
just btw, a week or two back was when I first started writing QGis 
python scripts to solve work issues.

So yes, I am struggling to find 'what is where' even though I am 10's of 
years down the road picturing the algorithm needed to solve my issue.
My current challenge is also QGis Atlas with multiple sub-maps per page 
- but I am 'getting there' with some pointers received from this list.

Thanks again for your response.
Kind regards,
Zoltan

On 2021-10-19 08:14, Stefan Giese (WhereGroup) wrote:
>
> as a starting point:
>
> /from qgis.core import *//
> //from qgis.gui import *//
> //
> //@qgsfunction(args='auto', group='Custom', referenced_columns=[])//
> //def zCutBox(feature, parent)://
> //    """//
> //    Calculates vertices and return the x coordinate of the first as 
> string//
> //    """//
> //    geom = feature.geometry()//
> //    vertices = []//
> //    for v in geom.vertices()://
> //        vertices.append(v)//
> //    return str(vertices[0].x())/
>
> Am 18.10.2021 um 13:42 schrieb Zoltan:
>> Hi Listers,
>> I can't for the life of me work out the syntax/commands to use in the 
>> FieldCalculator->FunctionEditor for extracting vertices.
>>
>> I have a Polygon layer with Multipolygon rectangles at various rotations.
>> I need to extract the 4 corner points so that I can calculate (and 
>> save in a virtual layer) lines that I can later use with 
>> "Processing->Split with lines".
>>
>> I will google for opening a new virtual layer and saving lines to it, 
>> but if that is quick and easy then some help there would also be welcome.
>>
>> Please can someone point me to a sample functions covering these 
>> requirements, or just fill in the gaps below.
>> No, I'm not asking for someone to just write it for me.
>>
>> Thanks in advance,
>> Zoltan
>> [Having a brain-dead day :-(  ]
>>
>>
>>     from qgis.core import *
>>     from qgis.gui import *
>>
>>     @qgsfunction(args='auto', group='Custom', referenced_columns=[])
>>     def zCutBox(feature, parent):
>>         vertices =
>>
>>         blah blah
>>         return vertices[0][0]
>>
>>
>> -- 
>>
>> =============================================
>> Zoltan Szecsei GPrGISc 0031
>> Geograph (Pty) Ltd.
>> GIS and Photogrammetric Services
>>
>> Cape Town, South Africa.
>>
>> Mobile: +27-83-6004028 (Signal, not WhatsApp)
>> www.geograph.co.za
>> =============================================
>>
>> _______________________________________________
>> Qgis-user mailing list
>> Qgis-user at lists.osgeo.org
>> List info:https://lists.osgeo.org/mailman/listinfo/qgis-user
>> Unsubscribe:https://lists.osgeo.org/mailman/listinfo/qgis-user
> -- 
> Mit freundlichen Grüßen
> Stefan Giese
> Projektleiter/Consultant
>
> ---------------------------------------------
> Schon gewusst?
> In unserem Blog geben wir Tipps & Tricks zu
> Open-Source-GIS-Software und berichten aus unserem Experten-Alltag:
> https://wheregroup.com/blog/
> ---------------------------------------------
>
> WhereGroup GmbH
> Schwimmbadstr. 2
> 79100 Freiburg
> Germany
>
> Fon: +49 (0)761 / 519 102 - 61
> Fax: +49 (0)761 / 519 102 - 11
>
> stefan.giese at wheregroup.com
> www.wheregroup.com
> Geschäftsführer:
> Olaf Knopp, Peter Stamm
> Amtsgericht Bonn, HRB 9885

-- 

=============================================
Zoltan Szecsei GPrGISc 0031
Geograph (Pty) Ltd.
GIS and Photogrammetric Services

Cape Town, South Africa.

Mobile: +27-83-6004028 (Signal, not WhatsApp)
www.geograph.co.za
=============================================
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20211019/adae55e3/attachment.html>


More information about the Qgis-user mailing list