Hi,<div><br></div><div>No, it is not a bug:</div><div>Your polygons are invalid. (at least one of them)</div><div>You should always ensure you pass valid objects before calling processing functions:</div><div><br></div><div>
<div><font face="courier new, monospace">with pg as (</font></div><div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>select 'POLYGON((-5.66666 43.53301,-5.66704 43.53335,-5.66931 43.53374,-5.66975299919511 43.533380063154,-5.66979 43.53335,-5.66971 43.53478,-5.66969091189271 43.5348058613067,-5.67026768864541 43.5374211525033,-5.67084666354158 43.5376334432986,-5.67111 43.53773,-5.67059550578171 43.53754135212,-5.66854 43.53971,-5.66854 43.53971,-5.66854 43.53971,-5.66758 43.53976,-5.6665 43.5402,-5.6665 43.5402,-5.66609712188377 43.539781395014,-5.66401 43.54013,-5.66401 43.54013,-5.66351576708437 43.5392869195307,-5.66281 43.53909,-5.6626 43.53851,-5.66159162498075 43.5369268527413,-5.66131 43.53695,-5.66196 43.53617,-5.66272791899155 43.5356642562857,-5.66378432333548 43.5344801289574,-5.66384 43.53414,-5.66452 43.53344,-5.6656 43.53337,-5.66611 43.5331,-5.66666 43.53301))'::geometry</font></div>
<div><font face="courier new, monospace"><span class="" style="white-space:pre"> </span>UNION</font></div><div><font face="courier new, monospace"> select 'POLYGON((-5.66577 43.53447,-5.66612 43.53455,-5.66675167677363 43.5349178897119,-5.66735 43.53529,-5.66811 43.5355,-5.66786 43.53678,-5.66816 43.53697,-5.66801 43.53717,-5.66729498033211 43.5375449497042,-5.6665 43.53782,-5.66634200990626 43.5386936730934,-5.66634 43.53876,-5.66554366174751 43.5384386684555,-5.66521 43.53856,-5.66457 43.53781,-5.6640744056249 43.5375662650614,-5.66341231504476 43.5372589777288,-5.66324 43.53718,-5.66334987968078 43.536344363177,-5.66304550704754 43.5357063513112,-5.66299 43.53559,-5.66358 43.53544,-5.66413 43.53529,-5.66521 43.535,-5.66577 43.53447,-5.66577 43.53447))'::geometry</font></div>
<div><font face="courier new, monospace">) </font></div><div><font face="courier new, monospace">select st_isvalid(geometry), st_isvalidReason(geometry) from pg;</font></div><div><font face="courier new, monospace"><br></font></div>
<div><div>f "Self-intersection[-5.67084227946059 43.5376318358022]"</div><div>t "Valid Geometry"</div></div><div><br></div></div><div>In addition to what Hugues said, if you are on Postgis >= 2, you can use the very handy st_makeValid to correct geoemtries.</div>
<div><br></div><div>Nicolas</div><div><br></div><div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 12 November 2012 13:57, Angel Cervera Claudio <span dir="ltr"><<a href="mailto:angelcervera@silyan.com" target="_blank">angelcervera@silyan.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div text="#000000" bgcolor="#FFFFFF">
<div>Hi Francois.<br>
<br>
This work!<br>
<br>
Could be a bug in st_difference?<br>
<br>
Thanks, Ángel<div><div class="h5"><br>
<br>
On 12/11/12 12:42, Francois Hugues wrote:<br>
</div></div></div><div><div class="h5">
<blockquote type="cite">
<div dir="ltr" align="left"><span><font color="#0000ff" face="Arial">You should try the
st_buffer tip :</font></span></div>
<div dir="ltr" align="left"><span></span> </div>
<div dir="ltr" align="left"><span>select
st_astext(<br>
st_difference(<br>
st_buffer(st_geomfromtext('POLYGON((-5.66666
43.53301,-5.66704 43.53335,-5.66931 43.53374,-5.66975299919511
43.533380063154,-5.66979 43.53335,-5.66971
43.53478,-5.66969091189271 43.5348058613067,-5.67026768864541
43.5374211525033,-5.67084666354158 43.5376334432986,-5.67111
43.53773,-5.67059550578171 43.53754135212,-5.66854
43.53971,-5.66854 43.53971,-5.66854 43.53971,-5.66758
43.53976,-5.6665 43.5402,-5.6665 43.5402,-5.66609712188377
43.539781395014,-5.66401 43.54013,-5.66401
43.54013,-5.66351576708437 43.5392869195307,-5.66281
43.53909,-5.6626 43.53851,-5.66159162498075
43.5369268527413,-5.66131 43.53695,-5.66196
43.53617,-5.66272791899155 43.5356642562857,-5.66378432333548
43.5344801289574,-5.66384 43.53414,-5.66452 43.53344,-5.6656
43.53337,-5.66611 43.5331,-5.66666 43.53301))', 4326),0),<br>
st_buffer(st_geomfromtext('POLYGON((-5.66577
43.53447,-5.66612 43.53455,-5.66675167677363
43.5349178897119,-5.66735 43.53529,-5.66811 43.5355,-5.66786
43.53678,-5.66816 43.53697,-5.66801 43.53717,-5.66729498033211
43.5375449497042,-5.6665 43.53782,-5.66634200990626
43.5386936730934,-5.66634 43.53876,-5.66554366174751
43.5384386684555,-5.66521 43.53856,-5.66457
43.53781,-5.6640744056249 43.5375662650614,-5.66341231504476
43.5372589777288,-5.66324 43.53718,-5.66334987968078
43.536344363177,-5.66304550704754 43.5357063513112,-5.66299
43.53559,-5.66358 43.53544,-5.66413 43.53529,-5.66521
43.535,-5.66577 43.53447,-5.66577 43.53447))', 4326),0)<br>
)<br>
);</span></div>
<div><span></span> </div>
<div><span><font color="#0000ff" face="Arial">Hugues.</font></span></div>
<div dir="ltr" align="left"><br>
<br>
</div>
<br>
<div dir="ltr" align="left" lang="fr">
<hr>
<font face="Tahoma"><b>De :</b>
<a href="mailto:postgis-users-bounces@lists.osgeo.org" target="_blank">postgis-users-bounces@lists.osgeo.org</a>
[<a href="mailto:postgis-users-bounces@lists.osgeo.org" target="_blank">mailto:postgis-users-bounces@lists.osgeo.org</a>] <b>De la part
de</b> Angel Cervera Claudio<br>
<b>Envoyé :</b> lundi 12 novembre 2012 12:23<br>
<b>À :</b> <a href="mailto:postgis-users@lists.osgeo.org" target="_blank">postgis-users@lists.osgeo.org</a><br>
<b>Objet :</b> [postgis-users] st_difference throws an error<br>
</font><br>
</div>
<tt>Hello.<br>
<br>
I post this problem in <a href="http://gis.stackexchange.com/questions/40872/st-difference-throws-an-error" target="_blank">http://gis.stackexchange.com/questions/40872/st-difference-throws-an-error</a>
buy i'm sure in this mailing list people can help me.<br>
<br>
I'm retrieving "</tt><code>GEOSDifference: TopologyException:
found non-noded intersection between</code><tt>" error when
executing st_difference sql.<br>
<br>
Followed an example:<br>
<br>
Error: </tt><br>
<pre><code>ERROR: GEOSDifference: TopologyException: found non-noded intersection between LINESTRING (-5.67027 43.5374, -5.67085 43.5376) and LINESTRING (-5.67111 43.5377, -5.6706 43.5375) at -5.6708422794605911 43.537631835802237
SQL:
</code><code>select st_astext(
st_difference(
st_geomfromtext('POLYGON((-5.66666 43.53301,-5.66704 43.53335,-5.66931 43.53374,-5.66975299919511 43.533380063154,-5.66979 43.53335,-5.66971 43.53478,-5.66969091189271 43.5348058613067,-5.67026768864541 43.5374211525033,-5.67084666354158 43.5376334432986,-5.67111 43.53773,-5.67059550578171 43.53754135212,-5.66854 43.53971,-5.66854 43.53971,-5.66854 43.53971,-5.66758 43.53976,-5.6665 43.5402,-5.6665 43.5402,-5.66609712188377 43.539781395014,-5.66401 43.54013,-5.66401 43.54013,-5.66351576708437 43.5392869195307,-5.66281 43.53909,-5.6626 43.53851,-5.66159162498075 43.5369268527413,-5.66131 43.53695,-5.66196 43.53617,-5.66272791899155 43.5356642562857,-5.66378432333548 43.5344801289574,-5.66384 43.53414,-5.66452 43.53344,-5.6656 43.53337,-5.66611 43.5331,-5.66666 43.53301))', 4326),
st_geomfromtext('POLYGON((-5.66577 43.53447,-5.66612 43.53455,-5.66675167677363 43.5349178897119,-5.66735 43.53529,-5.66811 43.5355,-5.66786 43.53678,-5.66816 43.53697,-5.66801 43.53717,-5.66729498033211 43.5375449497042,-5.6665 43.53782,-5.66634200990626 43.5386936730934,-5.66634 43.53876,-5.66554366174751 43.5384386684555,-5.66521 43.53856,-5.66457 43.53781,-5.6640744056249 43.5375662650614,-5.66341231504476 43.5372589777288,-5.66324 43.53718,-5.66334987968078 43.536344363177,-5.66304550704754 43.5357063513112,-5.66299 43.53559,-5.66358 43.53544,-5.66413 43.53529,-5.66521 43.535,-5.66577 43.53447,-5.66577 43.53447))', 4326)
)
);</code>
In <tt><a href="http://gis.stackexchange.com" target="_blank">gis.stackexchange.com</a> i attached images with various shapes with this problem.
</tt>All share a common pattern. Some parts of edge are near to be parallel.
How to resolve this problem? Is a bug?
Thanks!
</pre>
</blockquote>
</div></div></div>
<br>_______________________________________________<br>
postgis-users mailing list<br>
<a href="mailto:postgis-users@lists.osgeo.org">postgis-users@lists.osgeo.org</a><br>
<a href="http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users" target="_blank">http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users</a><br>
<br></blockquote></div><br></div>