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

Error encountered checking Geometry returned from GEOS C function

我正在使用 GEOS API 和 Python/Django。

我想从 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: Error encountered checking Geometry returned from GEOS C function "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]]]]}')

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

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

我发现我的数据有问题。

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

所以,这解决了问题

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