python - 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?
解决方案
推荐阅读
- postgresql - APScheduler 只更新一次数据库
- python - 为什么即使“要求已经满足”我也不能在 Jupyter 中使用 Pandas
- javascript - Jest 中的模拟类不会调用相同的方法
- html - flex inside grid - 垂直对齐中心最后一行
- user-interface - Winexe 命令返回无关信息并且不执行
- javascript - 使用javascript中的循环从一个对象创建两个对象时出错
- python - 如何在 tkinter 中更改标签的边框颜色?
- racket - dr Racket中嵌套列表的过滤功能
- python - 函数不适用于控制流或输入或变量 python 或 if 语句
- rest - 服务器如何处理 REST API 路径参数