[postgis-users] Get a feature geojson from postgis

Tonis Kardi Tonis.Kardi at kemit.ee
Mon Sep 1 00:53:40 PDT 2014


Hi,


I think Your output is ok, it's just that the last vertex of a linear
ring should be the same as the first: 


select st_isvalid(g), st_isvalidreason(g) from 
	(select 
		st_geomfromgeojson('{"type": "MultiPolygon",
"coordinates": [[[[-309443.24253826, 388111.579584133],
[-239422.232645415, 395845.012821243], 
			[-136320.430677211, 389768.695489968]]]]}') as
g) g;



"is_valid";"st_isvalidreason" 
f;"IllegalArgumentException: Points of LinearRing do not form a closed
linestring"


I'd guess that the problem is with input polygon geometries.


All the best,
Tõnis Kärdi



>>> Max Demars  08/28/14 5:55 PM >>>
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







More information about the postgis-users mailing list