首页 > 解决方案 > MongoDB 地理空间数据:循环无效:边缘 8 和 10 交叉

问题描述

我正在尝试将多边形插入 MongoDB DBMS。多边形在一点上自相交。多边形如下:

{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [{"type": "Feature",
"geometry": {"type": "Polygon", "coordinates": [[
[ -42.03130138154889, -22.89385998377782 ], 
[ -42.03130138154889, -22.89385528258293 ], 
[ -42.03129903095147, -22.89385528258293 ], 
[ -42.031296680354, -22.89385058138791 ], 
[ -42.03129197915909, -22.89384117899809 ], 
[ -42.031296680354, -22.89384588019297 ], 
[ -42.031296680354, -22.89384588019298 ], // Duplicated
[ -42.031296680354, -22.89384588019298 ], // Duplicated
[ -42.03130138154889, -22.89385058138791 ], 
[ -42.0313154851337, -22.89386468497268 ], 
[ -42.03131078393879, -22.89386311790775 ], 
[ -42.03131078393879, -22.89385998377782 ], 
[ -42.0313060827439, -22.89385998377782 ], 
[ -42.03130138154889, -22.89385998377782 ]
]]}}] }

我得到的错误是:

Loop is not valid: [ 
[ -42.03130138154889, -22.89385998377782 ], 
[ -42.03130138154889, -22.89385528258293 ], 
[ -42.03129903095147, -22.89385528258293 ], 
[ -42.031296680354, -22.89385058138791 ], 
[ -42.03129197915909, -22.89384117899809 ], 
[ -42.031296680354, -22.89384588019297 ], 
[ -42.031296680354, -22.89384588019298 ], 
[ -42.031296680354, -22.89384588019298 ], 
[ -42.03130138154889, -22.89385058138791 ], 
[ -42.0313154851337, -22.89386468497268 ], 
[ -42.03131078393879, -22.89386311790775 ], 
[ -42.03131078393879, -22.89385998377782 ], 
[ -42.0313060827439, -22.89385998377782 ], 
[ -42.03130138154889, -22.89385998377782 ] ] 
Edges 8 and 10 cross. Edge locations in degrees: 
[-42.0313014, -22.8938506]-[-42.0313155, -22.8938647] 
and [-42.0313108, -22.8938631]-[-42.0313108, -22.8938600]', 
details={ 
    }}]. ","path":"/bla"}

所以我删除了重复的点,但像这样关闭循环:

import json
from collections import OrderedDict

def remove_duplicated_vertices(feature):
    coords_list = feature["geometry"]["coordinates"]
    coords_tuples = map(tuple, coords_list[0]) # Transform into tuples, they are serializable
    processed_coords = OrderedDict.fromkeys(coords_tuples) # Remove duplicated points
    new_list = list(map(list,processed_coords)) # Transform back into lists
    new_list.append(new_list[0]) # Close the loop
    coords_list[0] = new_list
    return feature

但我得到和以前一样的错误。如何将此几何图形插入 MongoDB?

标签: pythonmongodbgisgeojsonmongodb-geospatial

解决方案


推荐阅读