检查从GEOS C函数返回的几何时出错
问题描述
我将GEOS API与Python/Django一起使用。
我想从GeoJSON创建一个MultiPolygon。 我正在将以下代码运行到一个python外壳中:
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]]]]}')
我找不出哪一个是我的数据的问题。
注意:这两个示例都是带孔的多重多边形。
解决方案
我发现我的数据有问题。
工作代码具有相同的开始和结束,但我的数据不相同。
这样,问题就解决了
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]]]]}')
相关文章