<div>I want to clean up some multipolygons and remove any polygons over a certain distance by using a postgis function.</div><div><br></div><div>This is the closest I've come: </div><div><br></div><div> CREATE OR REPLACE FUNCTION filter_polygons_within(geometry, double precision)</div>
<div> RETURNS geometry AS</div><div> $BODY$</div><div> SELECT ST_Multi(ST_Collect(final_geom.poly)) AS filtered_geom</div><div> FROM (</div><div> SELECT DISTINCT a.poly</div><div> FROM ( </div>
<div> SELECT ST_GeometryN(ST_Multi($1), generate_series(1, ST_NumGeometries(ST_Multi($1)))) AS poly,</div><div> (SELECT ST_GeometryN(ST_Multi($1), generate_series(1, ST_NumGeometries(ST_Multi($1))))) as poly_b </div>
<div> ) AS a</div><div> WHERE a.poly != a.poly_b</div><div> AND ST_DWithin(a.poly, a.poly_b, $1)</div><div> ) as final_geom</div><div> $BODY$</div><div> LANGUAGE 'sql' IMMUTABLE;</div>
<div><br></div><div>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;</div><div>
</div><div> ST_GeometryN(ST_Multi($1), generate_series(1, ST_NumGeometries(ST_Multi($1))))</div><div><br></div><div><meta charset="utf-8">I'm just not sure how to compare each one with another and return the distinct polygon results.</div>
<div><br></div><div>Thanks in advance,</div><div><br>Ross</div><div><br></div><meta charset="utf-8">