Hi,<br><br>I hope someone can help, postgis appears to be silently changing invalid geometries when attempting to "clean" with buffer(geom,0).<br><br>select postgis_full_version() gives:<br>'POSTGIS="1.3.3" GEOS="3.0.0-CAPI-1.4.1" PROJ="Rel. 4.6.0, 21 Dec 2007" USE_STATS'<br>
<br>select version() gives:<br>'PostgreSQL 8.3.5 on x86_64-pc-linux-gnu, compiled by GCC gcc-4.3.real (Ubuntu 4.3.2-1ubuntu11) 4.3.2'<br><br><br>I've been trying to "clean" some invalid polygons, and the advice often seems to buffer(geom,0) which turns an invalid polygon into a valid polygon.  However, the actual shape itself seems to change:<br>
<br>select asewkt(geomfromtext('POLYGON((100 100,100 200,400 200,400 400,200 400,200 100,100 100))',27700)) gives...<br>'SRID=27700;POLYGON((100 100,100 200,400 200,400 400,200 400,200 100,100 100))' <br>...with no warning that the geometry is invalid - only when checking isvalid() is there a notice of  "Self-intersection at or near point 200 200".<br>
<br>If I do...<br>select isvalid(buffer(geomfromtext('POLYGON((100 100,100 200,400 200,400 400,200 400,200 100,100 100))',27700),0))<br>...I get...<br>'t'<br>...so I've made the polygon valid and check it is so i the way that is often recommended.<br>
<br>Except, if I look at the resulting shape as text using...<br>select asewkt(buffer(geomfromtext('POLYGON((100 100,100 200,400 200,400 400,200 400,200 100,100 100))',27700),0))<br>...I get...<br>'SRID=27700;POLYGON((200 200,200 400,400 400,400 200,200 200))'<br>
..which is a different shape, silent of errors, warnings or notices.  I've lost the smaller part of the shape.<br><br><br><br>This follows onto similar lines with donut polygons.  I had a function that was occasionally being sent malformed polygons (as text) from a client application.  Checking if they are invalid, such as ...<br>
select isvalid(geomfromtext('MULTIPOLYGON(((100 100,100 400,600 400,600 100,100 100)),((200 200,200 300,300 300,300 200,200 200)))',27700))<br>... I get a warning (NOTICE:  Holes are nested at or near point 200 200) and...<br>
'f'<br><br>Again, isvalid() is raising an error - but simply putting the string into a geometry and getting it back, as in ...<br>select asewkt(geomfromtext('MULTIPOLYGON(((100 100,100 400,600 400,600 100,100 100)),((200 200,200 300,300 300,300 200,200 200)))',27700))<br>
...raises no notices etc.<br><br>More seriously,  if I ask for the area of the polygon I don't get an error - I get...<br>select area(geomfromtext('MULTIPOLYGON(((100 100,100 400,600 400,600 100,100 100)),((200 200,200 300,300 300,300 200,200 200)))',27700))<br>
160000<br><br>If I had a properly formed donut, I get<br>select area(geomfromtext('MULTIPOLYGON(((100 100,100 400,600 400,600 100,100 100),(200 200,200 300,300 300,300 200,200 200)))',27700))<br>140000<br><br><br>
So, unless I check a polygon is valid, I could silently be getting an incorrect area measure, and perhaps more besides.  As far as this particular application goes I think I can work around he issue by assembling the (multi)polygons myself, but I'm concerned at the lack of warnings and its not just this application - some of my data providers send data with self-intersecting polygons etc..<br>
<br>Regards,<br><br>Steve<br><br>