Opened 11 months ago

Closed 11 months ago

Last modified 10 months ago

#5528 closed defect (fixed)

IsValid XX000: GEOS isvalid() threw an error!

Reported by: Lars Aksel Opsahl Owned by: pramsey
Priority: medium Milestone: PostGIS GEOS
Component: postgis Version: 3.4.x
Keywords: Cc:

Description (last modified by Lars Aksel Opsahl)

When running on later geos versions I get an exception and the call returns

Here are there result from 3 different systems, where the one with latest geos fails first.

The file /tmp/testIsValid.sql that we test with will be uploaded.

psql:/tmp/testIsValid.sql:5: ERROR:  XX000: GEOS isvalid() threw an error!
LOCATION:  isvalid, lwgeom_geos.c:1677
                                                                                                                                                    postgis_full_version                                                                                                                                                    
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 POSTGIS="3.4.0 0874ea3" [EXTENSION] PGSQL="120" GEOS="3.10.1-CAPI-1.16.0" SFCGAL="1.3.7" PROJ="8.2.0 NETWORK_ENABLED=OFF URL_ENDPOINT=https://cdn.proj.org USER_WRITABLE_DIRECTORY=/tmp/proj DATABASE_PATH=/usr/share/proj/proj.db" LIBXML="2.9.10" LIBJSON="0.13.1" LIBPROTOBUF="1.3.3" WAGYU="0.5.0 (Internal)" TOPOLOGY
(1 row)

 postgis_geos_version 
----------------------
 3.10.1-CAPI-1.16.0
(1 row)


 st_isvalid 
------------
 t
(1 row)
                                                                                              postgis_full_version                                                                                              
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 POSTGIS="3.4.0dev 3.3.0rc2-958-g4c776d418" [EXTENSION] PGSQL="120" GEOS="3.9.1-CAPI-1.14.2" SFCGAL="1.3.7" PROJ="7.2.1" LIBXML="2.9.10" LIBJSON="0.13.1" LIBPROTOBUF="1.3.3" WAGYU="0.5.0 (Internal)" TOPOLOGY
(1 row)

 postgis_geos_version 
----------------------
 3.9.1-CAPI-1.14.2
(1 row)


 st_isvalid 
------------
 t
(1 row)
                                                                                                           postgis_full_version                                                                                                            
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 POSTGIS="3.1.1 aaf4c79" [EXTENSION] PGSQL="120" GEOS="3.9.0-CAPI-1.16.2" SFCGAL="1.3.7" PROJ="7.2.1" GDAL="GDAL 3.2.1, released 2020/12/29" LIBXML="2.9.10" LIBJSON="0.13.1" LIBPROTOBUF="1.3.3" WAGYU="0.5.0 (Internal)" TOPOLOGY RASTER
(1 row)

 postgis_geos_version 
----------------------
 3.9.0-CAPI-1.16.2
(1 row) 

Attachments (2)

testIsValid.sql (122.8 KB ) - added by Lars Aksel Opsahl 11 months ago.
/tmp/testIsValid.sql
geos_is_valid_error.png (135.6 KB ) - added by Lars Aksel Opsahl 11 months ago.
Can display the geometetry in geos

Download all attachments as: .zip

Change History (13)

by Lars Aksel Opsahl, 11 months ago

Attachment: testIsValid.sql added

/tmp/testIsValid.sql

by Lars Aksel Opsahl, 11 months ago

Attachment: geos_is_valid_error.png added

Can display the geometetry in geos

comment:1 by Lars Aksel Opsahl, 11 months ago

Description: modified (diff)

comment:2 by Lars Aksel Opsahl, 11 months ago

Description: modified (diff)

comment:3 by Lars Aksel Opsahl, 11 months ago

Cc: Lars Aksel Opsahl added

comment:4 by strk, 11 months ago

Cc: Lars Aksel Opsahl removed

When I try the query against POSTGIS="3.4.0 3.4.0" on PostgreSQL 12.16 I get:

ERROR: Pointarray length (-1132134400) is too large

But it works against POSTGIS="3.5.0dev 3.4.0rc1-191-g57c5dad0f" on PostgreSQL 13.5:

$ psql -tAf testIsValid.sql 
t
POSTGIS="3.5.0dev 3.4.0rc1-191-g57c5dad0f" [EXTENSION] PGSQL="130" GEOS="3.12.0dev-CAPI-1.18.0" PROJ="9.1.1 NETWORK_ENABLED=OFF URL_ENDPOINT=https://cdn.proj.org USER_WRITABLE_DIRECTORY=/tmp/proj DATABASE_PATH=/opt/proj-9.1/share/proj/proj.db" LIBXML="2.9.13" LIBJSON="0.15" LIBPROTOBUF="1.3.3" WAGYU="0.5.0 (Internal)" TOPOLOGY
3.12.0dev-CAPI-1.18.0

GEOS-3.10.1 is pretty old as the latest release of the 3.10 series is 3.10.5, releases on March 2023

comment:5 by strk, 11 months ago

The subject polygon is a 77 rings polygon. Dumping all rings and checking ST_IsValid against each of them works fine. The biggest ring has 2124 points.

Something in ring number 11 confuses PostGIS:

postgis_ticket_5528=# select st_isvalid( ST_MakePolygon( ( SELECT ST_ExteriorRing(g) from t5528 ), ( SELECT array_agg( ST_ExteriorRing(geom) ORDER BY path[1] ) FROM t5528_rings where path[1] > 0 and path[1] < 11 ) ) );
 st_isvalid 
------------
 t
(1 row)

postgis_ticket_5528=# select st_isvalid( ST_MakePolygon( ( SELECT ST_ExteriorRing(g) from t5528 ), ( SELECT array_agg( ST_ExteriorRing(geom) ORDER BY path[1] ) FROM t5528_rings where path[1] > 0 and path[1] < 12 ) ) );
ERROR:  GEOS isvalid() threw an error!

comment:6 by strk, 11 months ago

This can be reproduced also against GEOS-3.10.2, and both with ST_IsValid and ST_IsValidDetail:

postgis_ticket_5528=# select postgis_geos_compiled_version();
 postgis_geos_compiled_version 
-------------------------------
 3.10.2
(1 row)

postgis_ticket_5528=# select postgis_geos_version();
 postgis_geos_version 
----------------------
 3.10.2-CAPI-1.16.0
(1 row)

postgis_ticket_5528=# select st_isvaliddetail(g, 0) from t5528.original_input ;
ERROR:  GEOS isvaliddetail() threw an exception!

comment:7 by strk, 11 months ago

Simplifying the exterior ring, even with a tolerance of 0, removes the problem, so maybe this is related to this change in 3.10.3:

  • Fix IsValidOp to handle repeated node points (JTS-845, Martin Davis)

That's https://github.com/locationtech/jts/issues/845 which seem to result in an IllegalArgumentException thrown when input contains repeated points.

comment:8 by strk, 11 months ago

Resolution: fixed
Status: newclosed

Confirmed: this is fixed upstream by GEOS-3.10.3, with no need to recompile postgis.

comment:9 by strk, 11 months ago

GEOS-3.11.2 is also ok

comment:11 by robe, 10 months ago

Milestone: PostGIS 3.4.1PostGIS GEOS
Note: See TracTickets for help on using tickets.