Monday 25 April 2016

How to use the field calculator's centroid() Geometry function in qgis 2.0?


There is an option in the field calculator for centroids under geometry which when you double click gives you "centroid( ". What information is required here in order to use this function?



Answer



The centroid function returns an Point geometry object that represents the centroid of the input geometry.



You'd have to give the centroid function a geometry to chew on (most likely your feature's geometry, from $geometry), then parse that geometry out however you'd like.


One example would be getting the centroid as WKT:


 geomToWKT( centroid(  $geometry ) )

You could then stick that in a text field, or parse it further to get the X or Y.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...