[GRASS-user] add a centroid in the center of polygon

Markus Neteler neteler at osgeo.org
Sat Jan 25 02:41:07 PST 2014


On Sat, Jan 25, 2014 at 12:10 AM, Milton Ribeiro
<miltinho.astronauta at gmail.com> wrote:
> Dear all,
>
> I have a polygon vector, and need to add point in the center of mass of each
> one.
> I used v.centroid, but it adds just a centroid, but not in the central
> position of the polygon area.
>
> any hint are welcome!


I take liberty to cite a previous email here which is somewhat related:


On Tue, Feb 28, 2012 at 8:48 PM, Hamish <hamish_b at yahoo.com> wrote:
> Vishal wrote:
>> i'm interested in estimating the centre of population of a city
>> and how it might have changed in 10 years. i have a vector
>> polygon layer for each year, which is the ward population.
>> each layer has 198 polygons(wards) with population attributes
>> for each polygon(ward). The distribution of population within
>> a ward is not known, hence assumed uniform for now.
>>
>> is there a module in GRASS for calculating this. i know we can
>> calculate geographic centroids, but was'nt sure if there was
>> one for this kind of thing.
>>
>> Otherwise i could do it manually by extracting the geographic
>> centroid of each polygon, then the coordinates of the
>> population centre would be:
>>
>> xhat = sum(Pi Xi) /(sum(Pi)
>> yhat = sum(Pi Yi) / sum(Pi)
>>
>> where Xi, Yi are each polygon i's geographic centroids; and
>> Pi are each polygon's population coordinates are in UTM.
>
> Hi,
>
> This won't really answer your question, but fyi the centroid
> position is calculated by Vect_find_poly_centroid() like this:
>
> http://trac.osgeo.org/grass/browser/grass/trunk/lib/vector/Vlib/poly.c#L309
>
> but then tested to see if the point is within the polygon.
> beware of "C" or "O" shaped wards, where the center of mass
> (or the more simple center of the bounding box) may not be.
>
> and if you did have population data instead of polygons there
> is an addon script for that:
>    http://grass.osgeo.org/wiki/AddOns#v.points.cog
>
> "v.points.cog is a shell script which will create a new point at
> the center of gravity of each cluster of input points or
> centroids, grouped by attribute. Among other things this is
> useful for labeling swarms of points."

(actual link:
 http://grasswiki.osgeo.org/wiki/AddOns/GRASS_6#v.points.cog
)

> maybe it helps one day..
>
> Hamish

Due to the shape issue there is no general solution, it depends on the data.

Maybe other list members have further suggestions.

Markus


More information about the grass-user mailing list