TopologyException for Valid geoemtries
|Reported by:||bladeoflight16||Owned by:|
I have 2 supposedly valid geometries. When I try to take the difference between them:
WITH geom1 (g) AS (VALUES(ST_GeomFromEWKB(DECODE($$AQYAACAjaQAAAwAAAAEDAAAAAQAAAAkAAAB28/KWa9oWQSePXfN2Q1JBqrU4RG7aFkGksIr/f0NS QazxLppr2hZBGx9M/nZDUkGh1GSca9oWQffnBv52Q1JBPKwR52vaFkEY6B74dkNSQTbQvkJs2hZB 3Q0983ZDUkHFuN1EbNoWQVwaKvN2Q1JBgorsxi3bFkH9c+m5dkNSQXbz8pZr2hZBJ49d83ZDUkEB AwAAAAEAAAANAAAAKu2ZA3PaFkFrK3ILkENSQXU40QZz2hZBltlQFpBDUkGL2P81BdwWQV8rUp+P Q1JBAN7DMgXcFkFPnWOUj0NSQVoEjjAF3BZBT9OolI9DUkFzLuHlBNwWQQjTkJqPQ1JB+gw0igTc FkEqrXKfj0NSQWstFYgE3BZBW6CFn49DUkGkWbq1c9oWQVAZHRaQQ1JB1NJmsXPaFkF6uvkVkENS QVXR5lJz2hZB8+xOEZBDUkHbKskEc9oWQZUalAuQQ1JBKu2ZA3PaFkFrK3ILkENSQQEDAAAAAQAA AAcAAADqJmDJ/dsWQdMPPod2Q1JBvt4oxv3bFkHDYV98dkNSQY2/Pxf92xZBzyGTfHZDUkEbRZMb /dsWQZ2Atnx2Q1JBA0UTev3bFkE/TmGBdkNSQaHpMMj92xZBsyAch3ZDUkHqJmDJ/dsWQdMPPod2 Q1JB$$, 'base64')))), geom2 (g) AS (VALUES(ST_GeomFromEWKB(DECODE($$AQMAACAjaQAAAQAAABUAAACs/bu0c9oWQZJkHRaQQ1JBLBWdsnPaFkETWDAWkENSQcny71Zz2hZB bDISG5BDUkEaHUMMc9oWQWQy+iCQQ1JBOjoNCnPaFkGJaT8hkENSQTBygHN62hZB/7NlLqlDUkHq r690etoWQSijhy6pQ1JBQljNwnraFkFtdUI0qUNSQUVbTSF72hZB1ULtOKlDUkEY4qAle9oWQamh EDmpQ1JBc2b09wvcFkFWqHjCqENSQfNFE/oL3BZBJbVlwqhDUkHVZcBVDNwWQeXag72oQ1JB0Dlt oAzcFkET25u3qENSQVoTo6IM3BZBE6VWt6hDUkE/JDc5BdwWQW3ZMKqPQ1JB6eYHOAXcFkFN6g6q j0NSQW1A6ukE3BZB8xdUpI9DUkEAP2qLBNwWQXBKqZ+PQ1JBYrkWhwTcFkGk64Wfj0NSQaz9u7Rz 2hZBkmQdFpBDUkE=$$, 'base64')))) --SELECT ST_IsValidDetail(geom1.g), ST_IsValidDetail(geom2.g) SELECT ST_Difference(geom1.g, geom2.g) FROM geom1, geom2;
(Sorry for all the nasty base64. I wanted to make sure they come through exactly. You can leave the whitespace there in PostgreSQL.
DECODE strips it out it properly; in fact,
ENCODE is what generated it.)
I get the following error:
ERROR: GEOSDifference: TopologyException: found non-noded intersection between LINESTRING (374438 4.78778e+06, 374529 4.78777e+06) and LINESTRING (374529 4.78777e+06, 374466 4.78778e+06) at 374526.95988686144 4787774.5327140652 SQL state: XX000
You can confirm that they're reported as valid geometries by commenting/uncommenting the
SELECT lines appropriately.
Note that the
geom1 geometry is actually the output from a different, successful
ST_Difference, so it's not actually valid, there's a bug in what it outputs.
If you pull up the geometries, you'll find this is not squeaky clean data. It comes from data that is taken over several years, and for every year, I need to figure out what the most current data is. Sometimes the data is retaken, so I need to cut out old overlaps but bring in data from new locations. I've done a ton of work trying to automatically clean this data some, but I still run into these errors all the time. Expect more reports as I run into them.
I assumed this is a GEOS problem based on the error message. If not, I will happily report elsewhere.
Full PostGIS version, if it's of any help or I should look at upgrading anything:
POSTGIS="2.1.4 r12966" GEOS="3.4.2-CAPI-1.8.2 r3921" PROJ="Rel. 4.8.0, 6 March 2012" GDAL="GDAL 1.9.2, released 2012/10/08" LIBXML="2.7.6" LIBJSON="UNKNOWN" TOPOLOGY RASTER
GEOS is the latest version, in spite of PostGIS being a little bit behind. I was trying to reproduce with a newer version of PostGIS, but PostgreSQL's apt repository contains an outdated GEOS. I don't have time right now to install all that again, but it is worth noting that this issue does not reproduce on GEOS 3.3.3. (Full version of that install is
POSTGIS="2.1.7 r13414" GEOS="3.3.3-CAPI-1.7.4" PROJ="Rel. 4.7.1, 23 September 2009" GDAL="GDAL 1.9.0, released 2011/12/29" LIBXML="2.8.0" LIBJSON="UNKNOWN" RASTER.)