[postgis-users] Help with a multipolygon filtering function
Ross Lawley
ross.lawley at gmail.com
Wed Jan 19 13:56:46 PST 2011
I want to clean up some multipolygons and remove any polygons over a certain
distance by using a postgis function.
This is the closest I've come:
CREATE OR REPLACE FUNCTION filter_polygons_within(geometry, double
precision)
RETURNS geometry AS
$BODY$
SELECT ST_Multi(ST_Collect(final_geom.poly)) AS filtered_geom
FROM (
SELECT DISTINCT a.poly
FROM (
SELECT ST_GeometryN(ST_Multi($1), generate_series(1,
ST_NumGeometries(ST_Multi($1)))) AS poly,
(SELECT ST_GeometryN(ST_Multi($1), generate_series(1,
ST_NumGeometries(ST_Multi($1))))) as poly_b
) AS a
WHERE a.poly != a.poly_b
AND ST_DWithin(a.poly, a.poly_b, $1)
) as final_geom
$BODY$
LANGUAGE 'sql' IMMUTABLE;
However, the where clause isn't working for me - any ideas on how to achieve
this? I'm not sure on how to compare all polygons with each other, I know
how to get a list of polygons;
ST_GeometryN(ST_Multi($1), generate_series(1,
ST_NumGeometries(ST_Multi($1))))
I'm just not sure how to compare each one with another and return the
distinct polygon results.
Thanks in advance,
Ross
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20110119/c491c5ae/attachment.html>
More information about the postgis-users
mailing list