检查从GEOS C函数返回的Geometry时遇到错误

时间:2015-12-02 21:26:46

标签: python django geojson geos

我在Python / Django中使用more info

我想从geoJSON创建一个MultiPolygon。 我将以下代码运行到python Shell中:

mp2 = GEOSGeometry('{"type":"MultiPolygon", "coordinates": [[[[-56.14914894104003, -33.189642368629116], [-56.14914894104003, -33.18583537264943], [-56.14185333251953, -33.18583537264943], [-56.14185333251953, -33.189642368629116]], [[-56.14743232727051, -33.18834944515198], [-56.14743232727051, -33.186769179430186], [-56.14494323730469, -33.186769179430186], [-56.14494323730469, -33.18834944515198]]], [[[-56.14957809448242, -33.19244363735929], [-56.14957809448242, -33.19000151065257], [-56.14434242248535, -33.19000151065257], [-56.14434242248535, -33.19244363735929]]]]}')

得到错误:

  

" GEOSException:检查从GEOS返回的Geometry时遇到错误   C功能" GEOSWKBReader_read_r"。"

虽然下一个示例代码效果很好。

mp2 = GEOSGeometry('{"type": "MultiPolygon","coordinates": [[[[-101.2, -1.2], [-101.8, -1.2], [-101.8, -1.8], [-101.2, -1.8], [-101.2, -1.2]],[[-101.2, -1.2], [-101.3, -1.2], [-101.3, -1.3], [-101.2, -1.3], [-101.2, -1.2]]],[[[-100.0, 0.0], [-101.0, 0.0], [-101.0, -1.0], [-100.0, -1.0], [-100.0, 0.0]]]]}')

我无法弄清楚我的数据存在哪些问题。

注意:两个示例都是带有孔的多边形。

1 个答案:

答案 0 :(得分:1)

我发现数据存在问题。

工作代码具有相同的开始和结束,但我的数据没有。

所以,这解决了问题

mp2 = GEOSGeometry('{"type":"MultiPolygon", "coordinates": [[[[-56.14914894104003, -33.189642368629116], [-56.14914894104003, -33.18583537264943], [-56.14185333251953, -33.18583537264943], [-56.14185333251953, -33.189642368629116], [-56.14914894104003, -33.189642368629116]], [[-56.14743232727051, -33.18834944515198], [-56.14743232727051, -33.186769179430186], [-56.14494323730469, -33.186769179430186], [-56.14494323730469, -33.18834944515198], [-56.14743232727051, -33.18834944515198]]], [[[-56.14957809448242, -33.19244363735929], [-56.14957809448242, -33.19000151065257], [-56.14434242248535, -33.19000151065257], [-56.14434242248535, -33.19244363735929], [-56.14957809448242, -33.19244363735929]]]]}')