[postgis-users] Center of Points Collection
Kevin Neufeld
kneufeld at refractions.net
Mon Sep 14 13:51:11 PDT 2009
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
More information about the postgis-users
mailing list