如何使用 ST_Touches 获取接触几何体的交集长度
How to get the intersection length of touching geometries with ST_Touches
我正在尝试在 Postgis 中开发一个查询,它可以解决这个问题:
我有一个几何图形,我想知道哪个多边形与它接触,这个几何图形的接触面积最大。在我识别出这个多边形之后,我将在特定列中获取它的值,并将该值放在同一列中但在我的几何中。
有人知道我该怎么做吗?我是 postgresql/postgis.
的新用户
正如@JGH 在评论中指出的那样,如果您使用 ST_Touches
alone. 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
.
,重叠区域将为零
数据样本
上面描述的几何值在 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)
我正在尝试在 Postgis 中开发一个查询,它可以解决这个问题:
我有一个几何图形,我想知道哪个多边形与它接触,这个几何图形的接触面积最大。在我识别出这个多边形之后,我将在特定列中获取它的值,并将该值放在同一列中但在我的几何中。
有人知道我该怎么做吗?我是 postgresql/postgis.
的新用户正如@JGH 在评论中指出的那样,如果您使用 ST_Touches
alone. 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
.
数据样本
上面描述的几何值在 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)