Skip to main content
Tweeted twitter.com/StackGIS/status/1020047746856902657
Post Reopened by Below the Radar, Joseph, whyzar, Fezter
added 406 characters in body
Source Link
Below the Radar
  • 3.6k
  • 1
  • 31
  • 60

I would like to get a geojson feature with properties from PostGIS. I have found an example to have a feature collection but I can't make it works for just a feature.

SELECT row_to_json(fc)
 FROM ( SELECT 'FeatureCollection' As type, array_to_json(array_agg(f)) As features
 FROM (SELECT 'Feature' As type
    , ST_AsGeoJSON(lg.geog)::json As geometry
    , row_to_json(lp) As properties
   FROM locations As lg 
         INNER JOIN (SELECT loc_id, loc_name FROM locations) As lp 
       ON lg.loc_id = lp.loc_id  ) As f )  As fc;

so far I tryed to modify the feature collection query of the example. but the output is not valid.

I would like to get a geojson feature with properties from PostGIS. I have found an example to have a feature collection but I can't make it works for just a feature.

so far I tryed to modify the feature collection query of the example. but the output is not valid.

I would like to get a geojson feature with properties from PostGIS. I have found an example to have a feature collection but I can't make it works for just a feature.

SELECT row_to_json(fc)
 FROM ( SELECT 'FeatureCollection' As type, array_to_json(array_agg(f)) As features
 FROM (SELECT 'Feature' As type
    , ST_AsGeoJSON(lg.geog)::json As geometry
    , row_to_json(lp) As properties
   FROM locations As lg 
         INNER JOIN (SELECT loc_id, loc_name FROM locations) As lp 
       ON lg.loc_id = lp.loc_id  ) As f )  As fc;

so far I tryed to modify the feature collection query of the example. but the output is not valid.

revert tag edit
Link
dbaston
  • 13.2k
  • 3
  • 51
  • 81

Seeking SQL query to have a complete geojson feature from PostGIS?

Post Closed as "Not suitable for this site" by PolyGeo
edited title; edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

Seeking SQL query to have a complete geojson feature from PostGIS?

deleted 1031 characters in body
Source Link
Below the Radar
  • 3.6k
  • 1
  • 31
  • 60
Loading
Source Link
Below the Radar
  • 3.6k
  • 1
  • 31
  • 60
Loading