<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">My 02c...<br><br>If you have a table with a geometry column, you can add a second geometry column for the simplified ones. As in the script below, for a national coastline with about 10,000 polygons<br><br>You can generate the simplified ones using a series of update SQL statements, based on a variety of criteria, including neighbouring (or not) via a ST_Distance() in the where clause.<br><br>If you hand craft the update SQL's, you can just copy rather than simplify smaller polygons (ST_Area in the where clause), etc.<br><br>A slowish way, but viable for a 1-off is to have a where clause with an ST_IsValid in the where clause testing the result of the simplification. If the where clause includes a test for the target geometry being not-null, the series can apply a large simplification initially, then progressively apply a decreasing simplifcation buffer to
 features that failed previous iterations, until the last statement copies any remaining features with zero simplification.<br><br>I prefer a script with a set of SQL's rather than a function, as it is easier to tweak case requirements. <br><br>The advantage of this approach over the preserving topology simplify function is the degree of control the hand crafted SQL's provide over exactly how to simplify the dataset.<br><br>But, as always, your mileage may vary :-)<br><br>&nbsp; Cheers,<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Brent Wood<br><br><br>#! /bin/bash<br>#<br># script to simplify NZ coastline for zoom layer<br><br>DB=nzcoast<br>TAB=nz_all<br><br><br># add new geometry column<br>psql -d $DB -c "alter table nz_all drop column simple_geom;"<br><br>psql -d $DB -c "alter table nz_all add column simple_geom geometry(multipolygon,4326);"<br><br><br># populate<br># do small islands with no simplification<br>psql -d $DB -qc "update
 nz_all<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set simple_geom=geom <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where ST_Area(geom) &lt; 0.0000000001;"<br>psql -d $DB -qc "update nz_all<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set simple_geom=ST_Simplify(geom, 0.001) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where simple_geom isnull<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; and ST_IsValid(ST_Simplify(geom, 0.001));"<br>psql -d $DB -qc "update nz_all<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set simple_geom=ST_Simplify(geom, 0.0001) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where
 simple_geom isnull<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; and ST_IsValid(ST_Simplify(geom, 0.0001));"<br>psql -d $DB -qc "update nz_all<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set simple_geom=ST_Simplify(geom, 0.00001) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where simple_geom isnull<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; and ST_IsValid(ST_Simplify(geom, 0.00001));"<br>psql -d $DB -qc "update nz_all<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set simple_geom=geom <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where simple_geom isnull;"<br><br><br><br><br>--- On <b>Sat, 5/26/12, Carson Farmer
 <i>&lt;carson.farmer@gmail.com&gt;</i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Carson Farmer &lt;carson.farmer@gmail.com&gt;<br>Subject: Re: [Qgis-developer] Vector Layer Generalization<br>To: "Evgeniy Pashentsev" &lt;ugnpaul@gmail.com&gt;<br>Cc: qgis-developer@lists.osgeo.org<br>Date: Saturday, May 26, 2012, 10:11 AM<br><br><div class="plainMail">Excellent! Topology preserving simplification is something I've been<br>looking for!<br>&gt; But I want to ask your advice on one thing. Is it normal for user<br>&gt; to&nbsp;simplify all the features on a layer at once? I'm just not sure<br>&gt; which way&nbsp;is more suitable for a regular user:<br>&gt; - simplify all the features at once as it is now in my current prototype;<br>&gt; - simplify selected feature and all the corresponding vertexes of<br>&gt; the&nbsp;neighboring features;<br>&gt; - or simplify only selected
 features;<br>&gt; - or even something else.<br>&gt; Although it is not very important for current work, I want to make sure<br>&gt; I don't implement useless functionality.<br>Personally, I normally simplify an entire layer at once... for mapping<br>purposes, or simply to reduce drawing time or for computational/space<br>efficiency. It might be nice to also have the option to simplify<br>selected features only, but if this was an option, then I would expect<br>*only* those selected features to be simplified... and *not* their<br>neighbouring features...<br><br>That's my two cents anyway, looking forward to trying it out!<br><br>Carson<br><br><br>-- <br>Dr. Carson J. Q. Farmer<br>Centre for GeoInformatics (CGI)<br>School of Geography and Geosciences<br>Irvine Building, University of St Andrews<br>St Andrews, Fife, KY16 9AL<br>Scotland, UK<br>_______________________________________________<br>Qgis-developer mailing list<br><a
 ymailto="mailto:Qgis-developer@lists.osgeo.org" href="/mc/compose?to=Qgis-developer@lists.osgeo.org">Qgis-developer@lists.osgeo.org</a><br><a href="http://lists.osgeo.org/mailman/listinfo/qgis-developer" target="_blank">http://lists.osgeo.org/mailman/listinfo/qgis-developer</a><br></div></blockquote></td></tr></table>