Skip to content

How to provide a geojson from postgrest? #1894

Answered by steve-chavez
npltr62 asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @npltr62,

I try to set accept parameter like that 'Accept: "application/geo+json" but nothing works.

Yeah, this feature is not yet merged: #1564

For now you can create a view for getting geojson, like:

create view shops_geojson as
select st_asgeojson(x) from shops x;

Then call it through PostgREST:

GET /shops_geojson


{"type": "Feature", 
 "geometry": {"type":"Point","coordinates":[-71.10044,42.373695]}, 
 "properties": {"id": 1, "address": "1369 Cambridge St"}
} 

Edit: For a feature collection

create view shops_geojson as
select json_build_object('type', 'FeatureCollection', 'features', json_agg(ST_AsGeoJSON(x)))  from shops x;

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@npltr62
Comment options

@wolfgangwalther
Comment options

@steve-chavez
Comment options

Answer selected by wolfgangwalther
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants
Converted from issue

This discussion was converted from issue #1893 on July 08, 2021 15:50.