如何将此oracle空间掩码转换为st_relate postgis

问题描述

我正在尝试将 oracle 空间查询转换为我的工作的 postgis 查询,但我不明白如何将此 sdo_relate 子句转换为 st_relate close :

OracleSpatial 代码

[FromUri]

我可以在 st_relate 函数中放入 3 个以上的参数吗?

我已经试过了:

WHERE sdo_relate (a.geometry,b.GEOMETRY,'mask=contains+inside+covers+coveredby+overlapbdyintersect+equal+overlapbdydisjoint'
                 ) = 'TRUE'

但它不起作用

解决方法

  • 在您的查询中,您要检查 st_contains(a.geometrie,b.geometrie) 三次,这显然没有必要。
  • WHERE 子句中的某些组合永远不会起作用。例如,st_disjoint(a.geometrie,b.geometrie) AND st_equals(a.geometrie,b.geometrie) 永远不会带来任何结果,因为两个几何不能相等 AND 同时不相交——也许是 薛定谔几何? ;-).
  • 为了避免自相交错误,您可能需要使用 ST_MakeValid 来包装几何图形(请参阅评论)。
  • 与其简单地将 Oracle Spatial 掩码转换为 PostGIS 函数,我建议您重新评估您的用例并仅使用您实际需要的函数。正如您在评论中提到的,一个简单的 ST_Intersects 可能就足够了。
  • 如果您想坚持使用 ST_Relate,请检查 these examples 的字符串代码并构建您自己的代码。

您可以让 ST_Relate 为您计算矩阵,以便您可以在 WHERE 子句中使用它。将其与您知道应该适用的几何图形一起使用,例如

数据样本

CREATE TABLE a (geom geometry(polygon,4326));
CREATE TABLE b (geom geometry(polygon,4326));

INSERT INTO a VALUES ('SRID=4326;POLYGON((-4.5412382957234065 54.216850443917195,-4.506219374824969 54.216850443917195,-4.506219374824969 54.19677082652654,-4.5412382957234065 54.19677082652654,-4.5412382957234065 54.216850443917195))');
INSERT INTO b VALUES ('SRID=4326;POLYGON((-4.5233855125202815 54.20681185515958,-4.484246718574969 54.20681185515958,-4.484246718574969 54.185923774806604,-4.5233855125202815 54.185923774806604,-4.5233855125202815 54.20681185515958))');

enter image description here

SELECT ST_Relate(a.geom,b.geom) FROM a,b;

 st_relate 
-----------
 212101212

在 where 子句中使用它:

SELECT count(*) FROM a 
JOIN b ON ST_Relate(a.geom,b.geom,'212101212');

 count 
-------
     1
(1 row)

演示:db<>fiddle