Simon Greener | 2 Jan 2009 09:58

Re: Help with an area and hole filter query?

Regina,

> What I was thinking of was this.
>
> CREATE OR REPLACE FUNCTION upgis_filter_rings(geometry,float) RETURNS geometry AS
> $$ SELECT ST_BuildArea(ST_Collect(a.geom)) as final_geom
> 	FROM ST_DumpRings($1) AS a
>           WHERE a.path[1] = 0 OR
> 		(a.path[1] > 0 AND ST_Area(a.geom) > $2)
> $$
>   LANGUAGE 'sql' IMMUTABLE;

Oh, yes, very nice and concise.

> The main disadvantage aside from possibly speed over Simon's is that if you have 3-d polygons, I think the
above will squash them to 2d where as his approach will support 3D.

That's an advantage I didn't realise about. (My experience with PostGIS functions is fairly beginner and
there are a lot of functions to master.)

> On closer inspection -- when applying the above to the example polygon Simon provided the above returns a
multipolygon and filter_rings returns a POLYGON and that is because if you  do a validity check of the
polygon, its invalid because the holes lie outside of the exterior ring.  Buildarea just assumes
everything outside is a polygon and everything inside is hole where as ST_MakePolygon takes your
categorization of hole/vs shell as gospel.

A nice explanation.

> So better compare
>
(Continue reading)


Gmane