Sql POSTGIS拓扑异常:侧位置冲突
我正在尝试执行一个简单的st_相交查询:Sql POSTGIS拓扑异常:侧位置冲突,sql,postgresql,polygon,postgis,intersect,Sql,Postgresql,Polygon,Postgis,Intersect,我正在尝试执行一个简单的st_相交查询: select st_intersects('MULTIPOLYGON(((1 5,4 8,7 5,4 2,1 5)),((5 5,8 8,11 5,8 2,5 5)))','POLYGON((3 4.5,3 5,4 5,4 4,3 4.5))'); 这会压碎控制台并返回以下错误: 错误:GEOSIntersects:TopologyException:边位置冲突位于:6 4 这是非常奇怪的,因为以下查询有效: select st_intersects(
select st_intersects('MULTIPOLYGON(((1 5,4 8,7 5,4 2,1 5)),((5 5,8 8,11 5,8 2,5 5)))','POLYGON((3 4.5,3 5,4 5,4 4,3 4.5))');
这会压碎控制台并返回以下错误:
错误:GEOSIntersects:TopologyException:边位置冲突位于:6 4
这是非常奇怪的,因为以下查询有效:
select st_intersects('MULTIPOLYGON(((1 5,4 8,7 5,4 2,1 5)),((5 5,8 8,11 5,8 2,5 5)))','POLYGON((3 4,3 5,4 5,4 4,3 4))');
两者之间的唯一区别是最后一个多边形中的4/4.5
我使用POSTGIS版本2.2.1
我在这里遗漏了什么?您可以检查查询中的多多边形几何体是否不是有效的多多边形:
=> select st_isvalid(
st_geomfromtext(
'MULTIPOLYGON(((1 5,4 8,7 5,4 2,1 5)),((5 5,8 8,11 5,8 2,5 5)))'
));
NOTICE: Self-intersection at or near point 6 6
st_isvalid
------------
f
(1 row)
原因是定义“孔”(内圈)的多边形(55,88,115,82,55)
与外圈相交(15,48,75,42,15)
可能需要手动修复输入,或者可以使用ST_MakeValid
执行此操作(它会自动检测和处理重叠部分):
我找到了解决我问题的相关方法
select st_intersects(st_buffer('MULTIPOLYGON(((1 5,4 8,7 5,4 2,1 5)),((5 5,8 8,11 5,8 2,5 5)))',0),'POLYGON((3 4.5,3 5,4 5,4 4,3 4.5))');
当我添加
st_buffer
时,它将多边形的两个多边形合并为一个,并解决了这个问题。谢谢你的回答,但它仍然没有解释为什么第二个多边形相交没有返回任何错误谢谢。你帮我省了很多搜索时间!
select st_intersects(st_buffer('MULTIPOLYGON(((1 5,4 8,7 5,4 2,1 5)),((5 5,8 8,11 5,8 2,5 5)))',0),'POLYGON((3 4.5,3 5,4 5,4 4,3 4.5))');