Le mercredi 05 novembre 2014 à 10:39 -0800,
cesa...@gmail.com a
écrit :
> Hi,
>
> I am trying to create a geometry from a Geojson string:
>
> polygonstr = u'{"type":
> "Feature","geometry":{"type":"Polygon","coordinates":[[[-6.0,
> 40.0],[-5.0, 40.0],[-5.0, 38.0],[-7.0, 37.0],[-6.0,
> 40.0]]]},"properties": {"id": 0} }'
> polygon = GEOSGeometry(polygonstr)
>
> This should work, according to Geodjango documentation [1], but it
> fails.
> raise OGRException('Invalid geometry pointer returned from "%s".'
> % func.__name__)
> OGRException: Invalid geometry pointer returned from
> "OGR_G_CreateGeometryFromJson".
>
> Note that I can correctly create the geometry using WKT:
> polygonwkt = "POLYGON((-6.0 40.0, -5.0 40.0, -5.0 38.0, -7.0 37.0,
> -6.0 40.0))"
> polygon = GEOSGeometry(polygonwkt)
>
> What am I doing wrong?
Hi César,
You should only feed the 'geometry' part of the GeoJSON to the
GEOSGeometry constructor:
polygon = GEOSGeometry('{"type":"Polygon","coordinates":[[[-6.0,
40.0],[-5.0, 40.0],[-5.0, 38.0],[-7.0, 37.0],[-6.0, 40.0]]]}')
Cheers,
Claude
--
www.2xlibre.net