[postgis-users] Multi centroids

Kevin Neufeld kneufeld at refractions.net
Fri Dec 5 15:48:25 PST 2008


Very nice Mike.  I added your function to the wiki here:
http://postgis.refractions.net/support/wiki/index.php?ComputeMultiCentroid

I don't see why it won't make it into PostGIS some time ... seems like something useful.
Cheers,
Kevin

Mike Toews wrote:
> Hi Kevin,
> 
> That was exactly what I was after, thanks! Here is my modified function 
> which I've tested to some degree with MULTIPOLYGONs only:
> 
> CREATE OR REPLACE FUNCTION ST_MultiCentroid(geometry)
>  RETURNS geometry AS
> $BODY$SELECT ST_Collect(the_geom)
> FROM (
>  SELECT ST_Centroid((ST_Dump($1)).geom) AS the_geom
> ) AS foo;$BODY$
>  LANGUAGE 'sql' IMMUTABLE
>  COST 100;
> 
> -Mike
> 
> Kevin Neufeld wrote:
>> 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
> 
> _______________________________________________
> 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