简体   繁体   English

是否有 ST_Intersects 替代方案允许两个(或更多)多边形共享边

[英]Is there ST_Intersects alternative that allows two(or more) polygons to share sides

I am using ST_Intersects to check if two polygons intersect.我正在使用 ST_Intersects 检查两个多边形是否相交。 Relevant part of my query is:我查询的相关部分是:

SELECT entity_number
FROM coordinates
WHERE ST_INTERSECTS($1, location)

It works well to determine if one polygon crosses the other's surface:它可以很好地确定一个多边形是否与另一个多边形的表面相交:

在此处输入图像描述

I expected ST_Intersects to return false when two polygons share sides, but it does not:当两个多边形共享边时,我希望 ST_Intersects 返回 false,但它不会:

在此处输入图像描述

I read about other methods like ST_Covers, ST_Contains, ST_ContainsProperly, ST_Within,ST_DWithin .我阅读了其他方法,例如ST_Covers, ST_Contains, ST_ContainsProperly, ST_Within,ST_DWithin But i am not sure which one suits my needs.但我不确定哪一个适合我的需要。

Is there any method that allows two polygons to share sides?有什么方法可以让两个多边形共享边吗?

You want ST_Overlaps :你想要ST_Overlaps

Returns TRUE if geometry A and B "spatially overlap".如果几何 A 和 B“空间重叠”,则返回 TRUE。 Two geometries overlap if they have the same dimension, each has at least one point not shared by the other (or equivalently neither covers the other), and the intersection of their interiors has the same dimension.如果两个几何具有相同的维度,则它们重叠,每个几何至少有一个点不被另一个共享(或者等效地不覆盖另一个),并且它们内部的交集具有相同的维度。 The overlaps relationship is symmetrical.重叠关系是对称的。

As pointed out by Laurenz, ST_Overlaps is what you're looking for.正如 Laurenz 所指出的, ST_Overlaps就是您要找的。 However, quite often it does not suffice to simply check if polygons do overlap, but also "how much" they overlap.然而,通常仅仅检查多边形是否重叠是不够的,还要检查它们重叠“多少”。 In other words, how much of geometry a overlaps with geometry b ?换句话说,有多少几何 a几何 b重叠? ST_Intersection returns a polygon that is the result of the intersection of two geometries, so you can ST_Area this generated polygon and compare it with one of the polygons given to the function, eg given these polygons.. ST_Intersection返回一个多边形,它是两个几何图形相交的结果,因此您可以ST_Area这个生成的多边形并将其与给定的多边形之一进行比较 function,例如给定这些多边形..

在此处输入图像描述

... this would be the result of ST_Intersection ...这将是ST_Intersection的结果

在此处输入图像描述

And this is how you could calculate the percentage of the overlap这就是你如何计算重叠的百分比

SELECT 
  ST_Area(ST_Intersection(g1,g2))/ST_Area(g1)*100 AS perc_g1_overlap,
  ST_Intersection(g1,g2)
FROM t;

  perc_g1_overlap   |                                                                                          st_intersection                                                                                           
--------------------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 16.555309365086124 | 0103000020E6100000010000000500000054435ACF861E12C02068AC4B11214B4054435ACFD60A12C02068AC4B11214B4054435ACFD60A12C04B266CCD791F4B4054435ACF861E12C04B266CCD791F4B4054435ACF861E12C02068AC4B11214B40
(1 row)

Demo: db<>fiddle演示: db<>fiddle

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 st_intersects与st_overlaps - st_intersects Vs st_overlaps 有没有办法获得带有 ST_INTERSECTS 限制的 select SUM ? - Is there a way to select SUM with a ST_INTERSECTS restriction? Postgres更喜欢昂贵的ST_Intersects()而不是便宜的索引 - Postgres preferring costly ST_Intersects() over cheap index ST_Intersects 上的 Full Outer Join 会出错,但有时会起作用 - Full Outer Join on ST_Intersects gives error but worked sometimes Presto SQL left joining using ST_intersects, ST_crosses 产生意想不到的结果 - Presto SQL left joining using ST_intersects, ST_crosses yield unexpected results 为什么我的Postgis ST_Intersects和基于ST_Azimuth的查询速度慢? - Why my postgis ST_Intersects and ST_Azimuth based query is slow? 如何强制ST_Intersects使用空间索引而不是普通btree索引? - How to force ST_Intersects to use spatial index instead of normal btree index? 在rails或sql中克服“ ActiveRecord :: StatementInvalid:PG :: AmbiguousFunction”的方法。 (st_intersects不是唯一的函数名称) - Methods of overcoming “ActiveRecord::StatementInvalid: PG::AmbiguousFunction” in rails or sql. (st_intersects is not a unique function name) 如何返回与线串相交的所有多边形? - How to return all polygons that intersects a linestring? 检查一个多边形是否与每个集群中的其他多边形相交 - Check if a polygon intersects other polygons within each cluster
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM