[postgis-users] Select largest polygon of a multipolygon ?

Mark Cave-Ayland m.cave-ayland at webbased.co.uk
Wed Jul 12 04:47:35 PDT 2006


> -----Original Message-----
> From: postgis-users-bounces at postgis.refractions.net [mailto:postgis-users-
> bounces at postgis.refractions.net] On Behalf Of Arnaud Lesauvage
> Sent: 12 July 2006 09:32
> To: PostGIS Users Discussion
> Subject: Re: [postgis-users] Select largest polygon of a multipolygon ?

(cut)

> I tried with dump(), but I am not familiar with set returning
> functions at all, and postgresql's documentation is not very
> expansive on this matter.
> 
> For example :
> SELECT gid, Area(geom(Dump(uu_geometry))) FROM uu
> GROUP BY gid, Area(geom(Dump(uu_geometry)));
> works fine, but
> SELECT gid, Max(Area(geom(Dump(uu_geometry)))) FROM uu
> GROUP BY gid;
> does not work : "set-valued function called in context that cannot
> accept a set"
> 
> Why is it so ?


Hi Arnauld,

Set-Returning Functions can be a little bit tricky in PostgreSQL since they
must appear in either a FROM clause or be called using 'SELECT * FROM
SRF()'. In your example, I think you can use a correlated subquery something
like this:


SELECT uu.gid, (SELECT max(polygons.area) FROM (SELECT
area(geom(dump(uu_geometry))) FROM uu WHERE gid = uu.gid) AS polygons) AS
maxarea FROM uu;



Kind regards,

Mark.

------------------------
WebBased Ltd
17 Research Way
Plymouth
PL6 8BT

T: +44 (0)1752 797131
F: +44 (0)1752 791023

http://www.webbased.co.uk   
http://www.infomapper.com
http://www.swtc.co.uk  

This email and any attachments are confidential to the intended recipient
and may also be privileged. If you are not the intended recipient please
delete it from your system and notify the sender. You should not copy it or
use it for any purpose nor disclose or distribute its contents to any other
person.





More information about the postgis-users mailing list