[postgis-users] Multi centroids
Kevin Neufeld
kneufeld at refractions.net
Fri Dec 5 14:15:57 PST 2008
Yes. Use ST_Dump to explode your MULTI* object, take the ST_Centroid of each, and ST_Collect them together again.
SELECT ST_AsText(ST_Collect(the_geom))
FROM (
SELECT ST_Centroid((ST_Dump(the_geom)).geom) AS the_geom
FROM (
SELECT
'MULTIPOLYGON (
(( 0 0, 0 1, 1 1, 1 0, 0 0 )),
(( 2 2, 2 3, 3 3, 3 2, 2 2 ))
)'::geometry AS the_geom
) AS foo
) AS foo2;
st_astext
-----------------------------
MULTIPOINT(0.5 0.5,2.5 2.5)
(1 row)
Cheers,
Kevin
Mike Toews wrote:
> Hi,
>
> Is there a simple way to extract the multiple centroids as MULTIPOINT
> geometries from MULTI* objects (i.e., ST_MULTICENTROID(geometry) )? The
> ST_CENTROID function only returns POINT geometries.
>
> (An example application of this is to initially place CAD labels for
> MULTIPOLYGON features, since it appears that AutoCAD is not smart enough
> to place these properly, and need manual adjustment to avoid label
> conflicts. I have always been baffled by the purpose of multipoints
> until now.)
>
> I'm guessing this isn't a built-in function and the solution will be a
> custom SQL or PL/pgSQL function. Thanks for any help/ideas.
>
> -Mike
>
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users
More information about the postgis-users
mailing list