MongoDB 地理空间数据:循环无效:边 8 和 10 交叉
MongoDB GeoSpatial Data: Loop is not valid: Edges 8 and 10 cross
我正在尝试将多边形插入 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?
一些几何图形可以用 PyGEOS 修复。作为几何校正的结果,可以出现多部分多边形。
一个例子:
import pygeos
pygeos_geometry = pygeos.Geometry("POLYGON((0 0, 1 1, 1 2, 1 1, 0 0))")
result = pygeos.make_valid(pygeos_geometry)
parts = pygeos.get_parts(result)
for part in parts:
print(part)
我正在尝试将多边形插入 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?
一些几何图形可以用 PyGEOS 修复。作为几何校正的结果,可以出现多部分多边形。
一个例子:
import pygeos
pygeos_geometry = pygeos.Geometry("POLYGON((0 0, 1 1, 1 2, 1 1, 0 0))")
result = pygeos.make_valid(pygeos_geometry)
parts = pygeos.get_parts(result)
for part in parts:
print(part)