Opened 3 years ago

Closed 3 years ago

#4799 closed enhancement (fixed)

ST_AsGeoJSON doesn't export the CRS of multiple geometry columns

Reported by: tobwen Owned by: pramsey
Priority: low Milestone: PostGIS 3.2.0
Component: postgis Version: master
Keywords: geojson, json, jsonb Cc:

Description

summary

ST_AsGeoJSON only uses the first geometry column to create the feature's geometry. The other geometry columns get stored in properties. But here, the CRS is missing. It's not in GeoJSON specs, but it might be useful to reconstruct the geometry.

example

SELECT
    ST_AsGeoJSON(data.*)
FROM
    (SELECT
        1 AS id,
        ST_Transform(geom, 3035) geom,
        ST_Transform(geom, 25832) geom
    FROM
        ST_SetSRID(ST_MakePoint(7, 51), 4326) geom
    ) data;

result

{
  "type":"Feature",
  "geometry":{
    "type":"Point",
    "crs":{
      "type":"name",
      "properties":{
        "name":"EPSG:3035"
      }
    },
    "coordinates":[
      4110471.051819585,
      3103060.820290524
    ]
  },
  "properties":{
    "id":1,
    "geom":{
      "type":"Point",
      "coordinates":[
        359666.70366028673,
        5651728.682548149
      ]
    }
  }
}

nice to have

{
  "type":"Feature",
  "geometry":{
    "type":"Point",
    "crs":{
      "type":"name",
      "properties":{
        "name":"EPSG:3035"
      }
    },
    "coordinates":[
      4110471.051819585,
      3103060.820290524
    ]
  },
  "properties":{
    "id":1,
    "geom":{
      "crs":{
        "type":"name",
        "properties":{
          "name":"EPSG:25832"
        }
      },
      "type":"Point",
      "coordinates":[
        359666.70366028673,
        5651728.682548149
      ]
    }
  }
}

Change History (2)

comment:1 by pramsey, 3 years ago

Milestone: PostGIS 3.1.0PostGIS 3.2.0
Priority: mediumlow

comment:2 by Paul Ramsey <pramsey@…>, 3 years ago

Resolution: fixed
Status: newclosed

In a9382ae/git:

Include srs in GeoJSON where it exists in spatial_ref_sys, closes #4799

Note: See TracTickets for help on using tickets.