cockroachdb / cockroachdb/cockroach

`ST_GeomFromGeoJSON` should parse CRS information from the GeoJSON string.

Open
#132,046 2 comments 0 reactions 0 assignees View on GitHub
C-enhancement O-community T-sql-queries
Dominant language
Go
Stars
32.5k
Forks
4.1k
PR merge metrics
PR metrics pending

Description

In PostGIS, Spatialite and MySQL, the SRID of a geometry created with the function `ST_GeomFromGeoJSON` is infered from the `crs` member of the GeoJSON object. This is useful because contrary to `ST_GeomFromText`, `ST_GeomFromGeoJSON` doesn't accept the `SRID` argument, so we're currently forced to use `ST_Srid(ST_GeomFromGeoJSON(json, srid))`. Furthermore, since `ST_AsGeoJSON` can return geometries with the aforementioned `crs` member, a roundtrip with these two functions will lose the geometry SRID information.

Short example:

```sql
SELECT ST_SRID(ST_GeomFromGeoJSON('{"type":"Point","coordinates":[0,0],"crs":{"type":"name","properties":{"name":"EPSG:3857"}}}'));

-- EXPECTED: 3857
-- ACTUAL: 4326
```

In PostGIS, this is the code responsible for parsing the `crs` member:

https://github.com/postgis/postgis/blob/4fcfd0fd64b9b42c8120aa2cd9a4f16733cae863/liblwgeom/lwin_geojson.c#L433-L455

And for making sure the crs name refers to a valid SRID:

https://github.com/postgis/postgis/blob/4fcfd0fd64b9b42c8120aa2cd9a4f16733cae863/libpgcommon/lwgeom_cache.c#L374-L389

Jira issue: CRDB-42804

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.