GeoServer – Failed to Run GetFeatureInfo: Precision Cannot Be Greater Than 7 or Less Than -7

geoservergetfeatureinfopostgis

I have an environment consisting in Geoserver 2.20 + Postgresql 14 + Postgis 3.1.4, in which I'm trying to run the following GetFeatureInfo request on a database containing geographic information:

https://[my server]/geoserver/wms?SERVICE=WMS&VERSION=1.1.1&REQUEST=GetFeatureInfo&FORMAT=image/png&TRANSPARENT=true&QUERY_LAYERS=[datastore]:[layer]&LAYERS=[datastore]:[layer]&STYLES=population&INFO_FORMAT=application/json&X=1&Y=1&SRS=EPSG:4326&WIDTH=1&HEIGHT=1&BBOX=-0.9930238,38.02722463,-0.9930228,38.02722464&propertyName=[list of properties]

The request fails, providing the following error message:

Failed to run GetFeatureInfo on layer [datastore]:[layer] Rendering
process failed. Layers: [datastore]:[layer]
java.io.IOExceptionorg.postgresql.util.PSQLException: ERROR:
lwgeom_write_to_buffer: X/Z precision cannot be greater than 7 or less
than -7 ERROR: lwgeom_write_to_buffer: X/Z precision cannot be greater
than 7 or less than -7

No matter which layer I try to request, I always obtain the same result. If I trim the precision on the BBOX parameters up to 6 decimals, the query run smoothly and I get the expected output.

Also, if I try this very same request on a different machine running on Geoserver 2.15 + Postgresql 9.6 + Postgis 2.4 (and storing a duplicate of the same information) it always run perfectly even when using more than 6 decimals on BBOX.

Edit: Adding log output for the error:

Rendering process failed. Layers: [list of query layers] org.geoserver.wms.map.RenderedImageMapOutputFormat.produceMap(RenderedImageMapOutputFormat.java:589)
at org.geoserver.wms.map.RenderedImageMapOutputFormat.produceMap(RenderedImageMapOutputFormat.java:202)
at org.geoserver.wms.map.RenderedImageMapOutputFormat.produceMap(RenderedImageMapOutputFormat.java:82)
at org.geoserver.wms.featureinfo.VectorRenderingLayerIdentifier.identify(VectorRenderingLayerIdentifier.java:218)
at org.geoserver.wms.GetFeatureInfo.execute(GetFeatureInfo.java:76)
… 123 more
Caused by: java.lang.RuntimeException: java.io.IOException
at org.geotools.data.store.ContentFeatureCollection.features(ContentFeatureCollection.java:171)
at org.geotools.data.store.ContentFeatureCollection.features(ContentFeatureCollection.java:52)
at org.geotools.renderer.lite.StreamingRenderer.drawPlain(StreamingRenderer.java:2651)
at org.geotools.renderer.lite.StreamingRenderer.processStylers(StreamingRenderer.java:2286)
at org.geotools.renderer.lite.StreamingRenderer.paint(StreamingRenderer.java:917)
at org.geoserver.wms.map.RenderedImageMapOutputFormat.produceMap(RenderedImageMapOutputFormat.java:540)
… 127 more
Caused by: java.io.IOException
at org.geotools.jdbc.JDBCFeatureSource.getReaderInternal(JDBCFeatureSource.java:633)
at org.geotools.data.store.ContentFeatureSource.getReader(ContentFeatureSource.java:635)
at org.geotools.data.store.ContentFeatureCollection.features(ContentFeatureCollection.java:169)
… 132 more
Caused by: java.sql.SQLException: org.postgresql.util.PSQLException: ERROR: lwgeom_write_to_buffer: X/Z precision cannot be greater than 7 or less than -7
at org.geotools.jdbc.JDBCFeatureReader.runQuery(JDBCFeatureReader.java:282)
at org.geotools.jdbc.JDBCFeatureReader.(JDBCFeatureReader.java:153)
at org.geotools.jdbc.JDBCFeatureSource.getReaderInternal(JDBCFeatureSource.java:603)
… 134 more
Caused by: org.postgresql.util.PSQLException: ERROR: lwgeom_write_to_buffer: X/Z precision cannot be greater than 7 or less than -7
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2553)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2285)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:323)
at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:481)
at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:401)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:322)
at org.postgresql.jdbc.PgStatement.executeCachedSql(PgStatement.java:308)
at org.postgresql.jdbc.PgStatement.executeWithFlags(PgStatement.java:284)
at org.postgresql.jdbc.PgStatement.executeQuery(PgStatement.java:236)
at org.apache.commons.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:208)
at org.apache.commons.dbcp.DelegatingStatement.executeQuery(DelegatingStatement.java:208)
at org.geotools.jdbc.JDBCFeatureReader.lambda$new$0(JDBCFeatureReader.java:153)
at org.geotools.jdbc.JDBCFeatureReader.runQuery(JDBCFeatureReader.java:271)
… 136 more


Additional Edit:

By enabling PostgreSQL log as suggested by @user30184, I just found that the query on Postgis-3 use ST_AsTWKb to encode the retrieved geometry, which I store on attribute 'dn_geom':

SELECT [list of attributes]
,encode(ST_AsTWKB(ST_Simplify(ST_Force2D("dn_geom"),
7.999574336281513E-11, true),11), 'base64') as "dn_geom" FROM "public".[layer] WHERE "dn_geom" && ST_GeomFromText('POLYGON
((-1.56718254129 38.34939752637514, -1.56718254129 38.349397527375174,
-1.5671825402899995 38.349397527375174, -1.5671825402899995 38.34939752637514, -1.56718254129 38.34939752637514))', 4258)

While on Postgis-2.4 this is performed by ST_AsBinary:

SELECT [list of attributes]
,encode(ST_AsBinary(ST_Simplify(ST_Force2D("dn_geom"),
7.999982898354574E-11, true)),'base64') as "dn_geom" FROM "public".[layer] WHERE "dn_geom" && ST_GeomFromText('POLYGON
((-1.56718254129 38.34939752637514, -1.56718254129 38.349397527375174,
-1.5671825402899995 38.349397527375174, -1.5671825402899995 38.34939752637514, -1.56718254129 38.34939752637514))', 4258)

Looking at the documentation, looks like ST_AsTWKB is a compressed format that doesn't allow as much precision as ST_AsBinary, with the latter depending on library rtpostgis-2.4 which does not have an equivalent on Postgis-3.

Best Answer

Go to the PostGIS store configuration and disable the on-the-fly geometry simplification.