[postgis-users] Center of Points Collection

Rick graham.rick at gmail.com
Mon Sep 14 15:23:57 PDT 2009


This is why I said depending on what you want.

The average provides a weighted result, where a wild point will merely tug
like a point on a bezier frame.  A statistical result.   Putting a bounding
box around the whole thing and computing the center of that, provides an
unweighted geometric result.  Which may be desirable.  Without providing
some means, on a set of points that we have no description of, of ordering a
shape, save order of occurence, the means of computing a centroid is
indeterminate.

Interestingly enough, if the points are evenly spaced in circle with
ordinate points, all three will get the same result.  (Completely
manufactured, I know)  But I doubt that the question would have been raised
if that were the case.

The question is what is the application.

Dustin?

My question, purely out of interest, is which would be faster?  My guess is
the bounding box, with the median coming close on its heels.

Also, am I correct in assuming that a centroid strives to be the point at
which, were a line drawn through it would split the area of the shape
evenly?  If so, is this always possible, and if not, can exceptions be
easily identified?

On Mon, Sep 14, 2009 at 4:51 PM, Kevin Neufeld <kneufeld at refractions.net>wrote:

> Paul Ramsey wrote:
>
>> Faster than creating a multipoint is to recognize that ST_Centroid()
>> is just going to return the center of the bbox of the collection
>> anyways...
>>
>
> Unfortunately, Paul, ST_Centroid returns the center of mass, not the center
> of the bbox.
>
> SELECT astext(st_centroid(st_collect(column1))),
> FROM (values ('POINT(0 0)'),
>             ('POINT(0 1)'),
>             ('POINT(0 2)'),
>             ('POINT(1 0)')) as foo;
>      astext
> ------------------
>  POINT(0.25 0.75)
> (1 row)
>
> Your second post, taking the avg of the x,y does seem to be the nice
> approach, and produces the same results as ST_Centroid - the center of mass.
>
> SELECT astext(st_makepoint(avg(st_x(column1)), avg(st_y(column1))))
> FROM (values ('POINT(0 0)'),
>             ('POINT(0 1)'),
>             ('POINT(0 2)'),
>             ('POINT(1 0)')) as foo;
>      astext
> ------------------
>  POINT(0.25 0.75)
> (1 row)
>
> If Dustin is after the center of the collection, then something along your
> first suggestion might be more appropriate.
> (taking the center of the extents)
>
> Cheers,
> Kevin
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
>



-- 
Cheers!
Rick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20090914/31afd580/attachment.html>


More information about the postgis-users mailing list