[postgis-users] Get a feature geojson from postgis

Rasmus Aveskogh rasmus at defero.se
Thu Aug 28 10:22:41 PDT 2014


Example from my own application, you should be able to modify that to fit your case.

SELECT row_to_json(f) As feature FROM (SELECT 'Feature' As type, ST_AsGeoJSON(ST_Transform(l.geometry, 4326))::json As geometry, row_to_json((SELECT l FROM (SELECT id, 'l' AS type, name, area) As l)) As properties FROM lakes As l where l.id = 123456 ) As f;

-ra

On 28 Aug 2014, at 16:55, Max Demars <burton449geo at gmail.com> wrote:

> Hi list,
> 
> 
> 
> 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 modified the feature collection query but the output is not valid:
> 
>     "SELECT row_to_json(fc) \
>                             FROM (SELECT 'Feature' As type \
>                                  , ST_AsGeoJSON(%s)::json As geometry  \
>                                  , row_to_json((id_relat,id)) As properties \
>                                 FROM shapefile_feature WHERE id=%s)As fc;" % (geometryField, feature.pk)
> 
> invalid output:
> 
>     {
>        u'geometry':{
>           u'type':u'MultiPolygon',
>           u'coordinates':[
>              [
>                 [
>                    [
>                       -309443.24253826,
>                       388111.579584133
>                    ],
>                    [
>                       -239422.232645415,
>                       395845.012821243
>                    ],
>                    [
>                       -136320.430677211,
>                       389768.695489968
>                    ]
>                 ]
>              ]
>           ]
>        },
>        u'type':u'Feature',
>        u'properties':{
>           u'f1':0,
>           u'f2':489445
>        }
>     }
> 
> Anyone can help here?
> 
> -- 
> Stack Overflow: http://stackoverflow.com/users/1914034/burton449
> GIS Overflow: http://gis.stackexchange.com/users/14426/burton449
> LastFm: http://www.lastfm.fr/user/burton449
> _______________________________________________
> postgis-users mailing list
> postgis-users at lists.osgeo.org
> http://lists.osgeo.org/cgi-bin/mailman/listinfo/postgis-users

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20140828/ab53c1cc/attachment.html>


More information about the postgis-users mailing list