[Qgis-user] polygon centroids

Alexandre Neto senhor.neto at gmail.com
Thu Aug 28 02:45:45 PDT 2014


Ups, my bad...

You can get your features centroid using the function centroid(). It will
return a point geometry, then you can get the x and y by using either x_min
or x_max and y_min or y_max. Like this:

  xmin( centroid( $geometry )) || ' , ' || ymin( centroid( $geometry ))

Alexandre Neto


On Thu, Aug 28, 2014 at 10:29 AM, Leo Kris Palao <lk.palao at gmail.com> wrote:

> Hi Alexander,
>
> Thanks for your reply. In my understanding, this only applies if I have
> point coordinates, right? If I have polygons I think I need another syntax?
>
> I can create centroids in Vector > Geometry > Polygon Centroids tool then
> apply $x and $y to extract lat lon coordinates, but in some cases I want to
> skip this process if I am dealing with more than 300 thousand features in
> my polygon layer.
>
> Thanks,
> -Leo
>
>
> On Thu, Aug 28, 2014 at 3:01 PM, Alexandre Neto <senhor.neto at gmail.com>
> wrote:
>
>> Hello Leo,
>>
>> That's quite straightforward actually. In the field calculator (or in any
>> other instance of expression builder) there are 2 geometry functions to
>> achieve what you need,  $x and $y.
>>
>> You can either put them in separate fields or create a string to populate
>> a single one. Something like this,
>>
>> $x || ' , ' || $y
>>
>> Would produce something like this:
>>
>> '1234.56 , 9876.43'
>>
>> Notice that the double pipe character || works as a string concatenator.
>> And that the result is a string therefore not useful for any arithmetic
>> operations after.
>>
>> Hope this helped.
>>
>> Best regards,
>>
>> Alexandre Neto
>> Em 27/08/2014 22:37, "Leo Kris Palao" <lk.palao at gmail.com> escreveu:
>>
>>> Hi QGIS users,
>>>
>>> I don't know if this question has been asked before.
>>>
>>> Can you help me create a syntax in field calculator to add in the
>>> attribute table the centroids coordinates for each or selected polygon
>>> features?
>>>
>>> I am using Qgis 2.2 "Valmiera" version in Windows.
>>>
>>> Thanks in advance for help,
>>> -Leo
>>>
>>> _______________________________________________
>>> Qgis-user mailing list
>>> Qgis-user at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/qgis-user
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-user/attachments/20140828/e081ce1e/attachment.html>


More information about the Qgis-user mailing list