我在Python / Django中使用GEOS API

我想从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返回的几何时遇到错误
  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]]]]}')


我不知道我的数据出了什么问题。

注意:这两个示例都是带孔的Multipolygon。

最佳答案

我发现我的数据有问题。

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

所以,这解决了问题

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]]]]}')

08-24 23:39