| 1 | = Compute Multi Centroid = |
| 2 | |
| 3 | |
| 4 | |
| 5 | {{{ |
| 6 | -- Function: st_multicentroid(geometry) |
| 7 | -- Returns a MULTIPOINT obtained from collecting all |
| 8 | -- centroids in the supplied MULTI* geometry. |
| 9 | -- by: Mike Toews |
| 10 | -- |
| 11 | -- Usage: |
| 12 | -- postgis=# select [ST_AsText|http://postgis.refractions.net/documentation/manual-svn/ST_AsText.html](ST_!MultiCentroid( |
| 13 | -- postgis(# 'MULTIPOLYGON ( |
| 14 | -- postgis'# (( 0 0, 0 1, 1 1, 1 0, 0 0 )), |
| 15 | -- postgis'# (( 2 2, 2 3, 3 3, 3 2, 2 2 )) |
| 16 | -- postgis'# )'::geometry)); |
| 17 | -- st_astext |
| 18 | -- ----------------------------- |
| 19 | -- MULTIPOINT(0.5 0.5,2.5 2.5) |
| 20 | --( 1 row) |
| 21 | -- |
| 22 | -- DROP FUNCTION ST_!MultiCentroid(geometry); |
| 23 | |
| 24 | CREATE OR REPLACE FUNCTION ST_!MultiCentroid(geometry) |
| 25 | RETURNS geometry AS |
| 26 | $BODY$SELECT [ST_Collect|http://postgis.refractions.net/documentation/manual-svn/ST_Collect.html](the_geom) |
| 27 | FROM ( |
| 28 | SELECT [ST_Centroid|http://postgis.refractions.net/documentation/manual-svn/ST_Centroid.html](([ST_Dump|http://postgis.refractions.net/documentation/manual-svn/ST_Dump.html]([ST_Multi|http://postgis.refractions.net/documentation/manual-svn/ST_Multi.html]($1))).geom) AS the_geom |
| 29 | ) AS foo;$BODY$ |
| 30 | LANGUAGE 'sql' IMMUTABLE |
| 31 | COST 100; |
| 32 | |
| 33 | }}} |