Version 3 (modified by 13 years ago) ( diff ) | ,
---|
Compute Multi Centroid
-- Function: ST_MultiCentroid(geometry) -- Returns a MULTIPOINT obtained from collecting all -- centroids in the supplied MULTI* geometry. -- by: Mike Toews -- -- Usage: -- postgis=# select ST_AsText(ST_MultiCentroid( -- postgis(# 'MULTIPOLYGON ( -- postgis'# (( 0 0, 0 1, 1 1, 1 0, 0 0 )), -- postgis'# (( 2 2, 2 3, 3 3, 3 2, 2 2 )) -- postgis'# )'::geometry)); -- st_astext -- ----------------------------- -- MULTIPOINT(0.5 0.5,2.5 2.5) --( 1 row) -- -- DROP FUNCTION ST_MultiCentroid(geometry); CREATE OR REPLACE FUNCTION ST_MultiCentroid(geometry) RETURNS geometry AS $BODY$SELECT ST_Collect(the_geom) FROM ( SELECT ST_Centroid((ST_Dump(ST_Multi($1))).geom) AS the_geom ) AS foo;$BODY$ LANGUAGE 'sql' IMMUTABLE COST 100;
Note:
See TracWiki
for help on using the wiki.