Repository navigation
Conversation
PostgreSQLGeoJSONProvider.query now selects ST_AsGeoJSON(t.*, geom, max_decimal_digits, false, id) over a subquery that applies the core filters, sort, offset and limit, so PostGIS writes the whole feature as text. The provider returns those strings as GeoJSONFeature objects without parsing them, and JSONFormatter writes each one into the collection verbatim as an orjson.Fragment. The id column is selected a second time under an alias that ST_AsGeoJSON moves to the feature id, so id stays in properties as with the core provider. Requests with a CRS transform or skipGeometry take the core provider's ORM path. get() is unchanged. GeoJSONGeometry's lazy parsing moves to a base class, _LazyJSON, shared with the new GeoJSONFeature. A feature that is read (HTML, JSON-LD, JSON-FG with a time field) parses on first access and serializes from its contents, as GeoJSONGeometry already did. At 100,000 flowlines from a national hydrofabric table, uvicorn with one worker, the response takes 1.04 s against 2.11 s before this change and 7.28 s for the core PostgreSQL provider, 1.28 times a direct psycopg2 fetch of the same ST_AsGeoJSON rows. Peak server memory is 490 MB against 555 MB and 1,035 MB. The response matches the core provider's ids, order and properties, with coordinates rounded to 9 decimals. Assisted-by: Claude Opus-5.5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Have PostGIS write each whole feature as GeoJSON in
PostgreSQLGeoJSONProvider, usingST_AsGeoJSON(record, ..., id_column), for every items request, includingcrsandskipGeometry.This supersedes #84 and includes its two commits from @dblodgett-usgs (44578b0, a1028d2) unchanged, plus a follow-up commit (b995d6e) that:
id_columnargument ofST_AsGeoJSON(record)only exists from PostGIS 3.5, while CI ran PostGIS 3.2crsandskipGeometryin PostGIS instead of falling back to the core provider. The fallback ignored the CRS transform, socrs=returned untransformed coordinates.Changes Made
postgis/postgis:14-3.2topostgis/postgis:17-3.5, and the README says so.crs: the geometry goes throughST_Transform, and throughST_FlipCoordinateswherever pyproj would read or write northing first (for example EPSG:4326 withoutalways_xy). The output matches the core provider.skipGeometry: a NULL geometry column, which PostGIS 3.5 writes as"geometry": null.ProviderQueryErrorwith the message "PostgreSQLGeoJSONProvider requires PostGIS 3.5+", instead of failing with an unhandled SQL error._GEOJSON,_geojson,_select_properties_clause, and the_sqlalchemy_to_featureoverride).get()still uses the core provider.always_xy).Benchmark
Run with a local pygeoapi server (uvicorn, one worker) on 118,208 features (the test waterways copied 8 times), with the plugin JSON formatter and PostGIS 3.5.
limit=1000skipGeometry=truecrs=EPSG:3857crs=EPSG:4326The PostGIS container ran under amd64 emulation on Apple Silicon, so database-side times are inflated, and repeat runs varied by 10–15%.
The features match the core provider's ids, order and properties, with coordinates within 1e-8.
I also benchmarked approaches that work on PostGIS 3.2:
concatof the partsjson_build_objectThey were no faster, so this PR requires 3.5 instead.
Related Issues
Supersedes #84.
Additional Notes
Deployments on PostGIS older than 3.5 need to upgrade before using
PostgreSQLGeoJSONProvider. PostGIS 3.5 supports PostgreSQL 12–17. Other providers are unaffected.🤖 Generated with Claude Code