<table cellspacing="0" cellpadding="0" border="0" ><tr><td valign="top" style="font: inherit;">I forget where I learned that... probably from Regina Obe at Boston GIS. <br><br>Also note that from the picture, it should perhaps be a multipolygon, to store a single feature comprising two polygons sharing a point... rather than a single polygon.<br><br>Cheers,<br><br>  Brent<br><br>--- On <b>Sun, 3/11/12, Puneet Kishor <i><punk.kish@gmail.com></i></b> wrote:<br><blockquote style="border-left: 2px solid rgb(16, 16, 255); margin-left: 5px; padding-left: 5px;"><br>From: Puneet Kishor <punk.kish@gmail.com><br>Subject: Re: [postgis-users] How to make this invalid polygon valid one<br>To: "pcreso@pcreso.com" <pcreso@pcreso.com>, "PostGIS Users Discussion" <postgis-users@postgis.refractions.net><br>Cc: "PostGIS Users Discussion" <postgis-users@postgis.refractions.net>, "nicolas.ribot@gmail.com"
 <nicolas.ribot@gmail.com><br>Date: Sunday, March 11, 2012, 10:37 AM<br><br><div id="yiv1352172264"><div><div><br><br>ha! Neat trick, Brent.</div><div><br>On Mar 10, 2012, at 3:26 PM, <a rel="nofollow" ymailto="mailto:pcreso@pcreso.com" target="_blank" href="/mc/compose?to=pcreso@pcreso.com">pcreso@pcreso.com</a> wrote:<br><br></div><div></div><blockquote type="cite"><div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td style="font:inherit;" valign="top">Hi Nicolas,<br><br>Change your SQL to insert a buffered version of your polygon with a buffer distance of zero. You should get a topologically correct polygon (in this particular case anyway), which is a tracing of the perimeter with any duplicate vertices resolved.<br><span style="font-style:italic;"><span style="font-weight:bold;"><br></span></span>eg: <span style="font-style:italic;"><span style="font-weight:bold;"><br><br>insert into test_polygon (id,geometry) values
 (1,ST_buffer(ST_GeomFromText(<br>'POLYGON((...))'),0.0));</span></span><br><br>Cheers,<br><br>  Brent Wood<br><br>--- On <b>Sun, 3/11/12, Nicolas Ribot <i><<a rel="nofollow" ymailto="mailto:nicolas.ribot@gmail.com" target="_blank" href="/mc/compose?to=nicolas.ribot@gmail.com">nicolas.ribot@gmail.com</a>></i></b> wrote:<br><blockquote style="border-left:2px solid rgb(16, 16, 255);margin-left:5px;padding-left:5px;"><br>From: Nicolas Ribot <<a rel="nofollow" ymailto="mailto:nicolas.ribot@gmail.com" target="_blank" href="/mc/compose?to=nicolas.ribot@gmail.com">nicolas.ribot@gmail.com</a>><br>Subject: Re:
 [postgis-users] How to make this invalid polygon valid one<br>To: "PostGIS Users Discussion" <<a rel="nofollow" ymailto="mailto:postgis-users@postgis.refractions.net" target="_blank" href="/mc/compose?to=postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a>><br>Date: Sunday, March 11, 2012, 9:45 AM<br><br><div id="yiv1352172264"><div class="yiv1352172264gmail_quote"><blockquote class="yiv1352172264gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Hello<br>
<br>
I am trying to create a buffer around my polygon, which unfortunately is not<br>
a valid one.<br>
(reason: "Self-intersection[......]").<br>
<br>
This polygon is the output of my calculation that creates from a set of<br>
connected edges an area, consisting of all edges located on the border.<br>
<br>
<a rel="nofollow" target="_blank" href="http://postgis.17.n6.nabble.com/file/n4564623/Screen_Shot_2012-03-09_at_10.02.41_PM.png">http://postgis.17.n6.nabble.com/file/n4564623/Screen_Shot_2012-03-09_at_10.02.41_PM.png</a><br>
Polygon image<br>
<br>
can someone tell me, what can I do, to remedy this behavior and to make this<br>
geometry valid<br>
<br>
this are the sql statements to reproduce my problem:<br>
<a rel="nofollow" target="_blank" href="http://postgis.17.n6.nabble.com/file/n4564623/testPolygon.sql">http://postgis.17.n6.nabble.com/file/n4564623/testPolygon.sql</a><br>
testPolygon.sql<br>
<br>
thanks<br>
<br>
Markus<br>
<br><br></blockquote><div><br></div><div>Hi Markus,</div><div><br></div><div>An attempt with Pgis 1.5.3:</div><div><br></div><div>I saw in a Paul's presentation the power of unioning linestrings together, in order to generated several line where they intersects (<a rel="nofollow" target="_blank" href="http://2010.foss4g.org/presentations_show.php?id=3369">http://2010.foss4g.org/presentations_show.php?id=3369</a>)</div>
<div><br></div><div>The goal is to use duplicate points from the initial polygon to allow us to make the difference between these points and the exterior ring of the polygon, to generates several linestrings that can be passed to st_buildArea:</div>
<div><div><br></div><div>The first part (with...) extracts duplicate points (cf img1)</div><div><br></div><div>with duplicates as (</div><div>      select st_collect((st_dumppoints(geometry)).geom) as point</div><div><span class="yiv1352172264Apple-tab-span" style="white-space:pre;">       </span> from test_polygon </div>
<div><span class="yiv1352172264Apple-tab-span" style="white-space:pre;">        </span> group by (st_dumppoints(geometry)).geom</div><div><span class="yiv1352172264Apple-tab-span" style="white-space:pre;">       </span> having count((st_dumppoints(geometry)).geom)>1</div>
<div> ) </div><div> select st_buildarea (</div><div>      st_union(st_difference(st_exteriorRing(t.geometry), point))  </div><div> ) from duplicates, test_polygon t;</div></div><div><br></div><div>The result (img2) is a multipolygon that can be dumped to extract individual parts, or directly buffered.</div>
<div>(the query is not at all optimized ;) )</div><div><br></div><div>Nicolas</div></div>
</div><br>-----Inline Attachment Follows-----<br><br><div class="yiv1352172264plainMail">_______________________________________________<br>postgis-users mailing list<br><a rel="nofollow">postgis-users@postgis.refractions.net</a><br><a rel="nofollow" target="_blank" href="http://postgis.refractions.net/mailman/listinfo/postgis-users">http://postgis.refractions.net/mailman/listinfo/postgis-users</a><br></div></blockquote></td></tr></tbody></table></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>postgis-users mailing list</span><br><span><a rel="nofollow" ymailto="mailto:postgis-users@postgis.refractions.net" target="_blank" href="/mc/compose?to=postgis-users@postgis.refractions.net">postgis-users@postgis.refractions.net</a></span><br><span><a rel="nofollow" target="_blank"
 href="http://postgis.refractions.net/mailman/listinfo/postgis-users">http://postgis.refractions.net/mailman/listinfo/postgis-users</a></span><br></div></blockquote></div></div></blockquote></td></tr></table>