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
_______________________________________________
postgis-users mailing list
[email protected]
http://postgis.refractions.net/mailman/listinfo/postgis-users

Reply via email to