[英]How to get the intersection length of touching geometries with ST_Touches
I am trying to develop a query in Postgis, where it can solve this problem:我正在尝试在 Postgis 中开发一个查询,它可以解决这个问题:
I have a geometry and I wanna know which of the polygons that touches it, there is the highest contact area of this geometry.我有一个几何体,我想知道哪个多边形接触它,这个几何体的接触面积最大。 After I recognize this polygon I will take its value in a specific column and put this value in the same column but in my geometry.
在我识别出这个多边形后,我将在特定列中取其值并将该值放在同一列中但在我的几何中。
Someone know how can I do that?有人知道我该怎么做? I am a new user in postgresql/postgis.
我是 postgresql/postgis 的新用户。
As pointed out by @JGH in the comments, the overlapping area will be zero if you use ST_Touches
alone.正如@JGH 在评论中指出的那样,如果单独使用
ST_Touches
,重叠区域将为零。 What you can do is to filter out only the geometries that do touch your reference geometry and then use ST_Intersection
to get the intersection area, so that you can finally calculate the length of the intersection with ST_Length
.您可以做的是仅过滤掉与您的参考几何图形接触的几何图形,然后使用
ST_Intersection
获取相交区域,以便您最终可以使用ST_Length
计算相交的长度。
Data Sample数据样本
The geometry values depicted above are inside the CTE
:上面描述的几何值在
CTE
:
WITH j (id,geom) AS (
VALUES
(1,'POLYGON((-4.64 54.19,-4.59 54.19,-4.59 54.17,-4.64 54.17,-4.64 54.19))'),
(2,'POLYGON((-4.59 54.19,-4.56 54.19,-4.56 54.17,-4.59 54.17,-4.59 54.19))'),
(3,'LINESTRING(-4.65 54.19,-4.57 54.21)'),
(4,'POLYGON((-4.66 54.21,-4.60 54.21,-4.60 54.20,-4.66 54.20,-4.66 54.21))'),
(5,'POINT(-4.57 54.20)')
)
SELECT
id,
ST_Length(
ST_Intersection(
geom,
'POLYGON((-4.62 54.22,-4.58 54.22,-4.58 54.19,
-4.62 54.19,-4.62 54.22))')) AS touch_length
FROM j
WHERE
ST_Touches(
geom,
'POLYGON((-4.62 54.22,-4.58 54.22,-4.58 54.19,
-4.62 54.19,-4.62 54.22))')
ORDER BY touch_length DESC
LIMIT 1;
id | touch_length
----+---------------------
1 | 0.03000000000000025
(1 Zeile)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.