全部產品
Search
文件中心

Lindorm:關係函數

更新時間:Jul 06, 2024

本文介紹時空函數中的關係函數。

引擎與版本

關係函數僅適用於寬表引擎。無版本要求。

函數列表

Lindorm Ganos支援的關係函數如下表所示。

函數

說明

ST_Contains

如果Geometry對象A包含Geometry對象B,ST_Contains函數則返回true。

ST_DWithin

如果兩個Geometry對象的二維平面距離在指定範圍內,ST_DWithin函數則返回true。

ST_DWithinSphere

如果兩個Geometry對象的球面距離在指定範圍內,ST_DWithinSphere函數則返回true。

ST_Intersects

判斷兩個Geometry對象是否相交。如果兩個Geometry對象有任意共用空間的部分,那麼兩個Geometry對象相交,ST_Intersects函數則返回true。

ST_Overlaps

如果兩個Geometry對象在空間上有重疊的部分,但不存在其中一個完全包含另一個的情況,ST_Overlaps函數則返回true。

ST_Within

如果Geometry對象A完全在Geometry對象B內,ST_Within函數則返回true。

ST_Contains

如果Geometry對象A包含Geometry對象B,ST_Contains函數則返回true。

文法

  • 判斷對象geomA是否包含對象geomB

    boolean ST_Contains(geometry geomA,geometry geomB)
  • 判斷對象geom和點座標(x,y)的內含項目關聯性

    boolean ST_Contains(geometry geom,double x,double y)

參數說明

參數

描述

geomA

指定的第一個Geometry對象。

geomB

指定的第二個Geometry對象。

geom

指定的Geometry對象。

x

座標經度x值。

y

座標緯度y值。

說明
  • geomB對象的所有點均在geomA對象的內部或者邊界上,則geomA對象包含geomB對象。

  • ST_Contains函數是ST_Within的反函數,即ST_Contains(A,B)=ST_Within(B,A)

樣本

  • 樣本1

    SELECT ST_Contains(ST_GeomFromText('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))'), ST_GeomFromText('POINT(5 5)')) AS iscontain;

    返回結果:

    +-----------+
    | iscontain |
    +-----------+
    | true      |
    +-----------+
  • 樣本2

    SELECT ST_Contains(ST_GeomFromText('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))'),5,5) AS iscontain;

    返回結果:

    +-----------+
    | iscontain |
    +-----------+
    | true      |
    +-----------+
  • 樣本3

    SELECT ST_Contains(ST_GeomFromText('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))'), ST_GeomFromText('POINT(180 23)')) AS iscontain;

    返回結果:

    +-----------+
    | iscontain |
    +-----------+
    | false     |
    +-----------+
  • 樣本4

    SELECT ST_Contains(ST_GeomFromText('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))'),180,23) AS iscontain;

    返回結果:

    +-----------+
    | iscontain |
    +-----------+
    | false     |
    +-----------+

ST_DWithin

如果兩個Geometry對象的二維平面距離在指定範圍內,ST_DWithin函數則返回true。

文法

  • 判斷對象geomA和對象geomB的二維平面距離是否在指定範圍內

    boolean ST_DWithin(geometry geomA, geometry geomB, double distanceOfSrid)
  • 判斷對象geom和點座標(x,y)的二維平面距離是否在指定範圍內

    boolean ST_DWithin(geometry geom, double x, double y, double distanceOfSrid)

參數說明

參數

描述

geomA

指定的第一個Geometry對象。

geomB

指定的第二個Geometry對象。

distanceOfSrid

在SRID 4326下的距離,單位為degree。

geom

指定的Geometry對象。

x

座標經度x值。

y

座標緯度y值。

說明

Geometry對象支援Point、LineString、Polygon、MultiPoint、MultiLineString、MultiPolygon和GeometryCollection類型。

樣本

  • 樣本1

    SELECT ST_DWithin(ST_GeomFromText('POINT(5 5)'), ST_GeomFromText('POINT(6 6)'), 10) AS iswithin;

    返回結果:

    +----------+
    | iswithin |
    +----------+
    | true     |
    +----------+
  • 樣本2

    SELECT ST_DWithin(ST_GeomFromText('POINT(5 5)'),6,6,10) AS iswithin;

    返回結果:

    +----------+
    | iswithin |
    +----------+
    | true     |
    +----------+

ST_DWithinSphere

如果兩個Geometry對象的球面距離在指定範圍內,ST_DWithinSphere函數則返回true。

文法

  • 判斷對象geomA和對象geomB的球面距離是否在指定範圍內

    boolean ST_DWithinSphere(geometry geomA, geometry geomB, double distance)
  • 判斷對象geom和點座標(x,y)的球面距離是否在指定範圍內

    boolean ST_DWithinSPhere(geometry geom, double x, double y, double distance)

參數說明

參數

描述

geomA

指定的第一個Geometry對象。

geomB

指定的第二個Geometry對象。

distance

球面距離,單位為米。球面距離的判斷存在一定的誤差,誤差為厘米層級。

geom

指定的Geometry對象。

x

座標經度x值。

y

座標緯度y值。

說明

Geometry對象支援Point、LineString、Polygon、MultiPoint、MultiLineString、MultiPolygon和GeometryCollection類型。

樣本

  • 樣本1:球面上POINT(120 36)和POINT(116 40)之間的距離為566034.7930717631米,距離在指定的範圍內,ST_DWithinSphere函數則返回true。

    SELECT ST_DWithinSphere(ST_GeomFromText('POINT(120 36)'), ST_GeomFromText('POINT(116 40)'), 570000) AS iswithin;

    返回結果:

    +----------+
    | iswithin |
    +----------+
    | true     |
    +----------+
  • 樣本2

    SELECT ST_DWithinSphere(ST_GeomFromText('POINT(120 36)'),116,40,570000) AS iswithin;

    返回結果:

    +----------+
    | iswithin |
    +----------+
    | true     |
    +----------+

ST_Intersects

判斷兩個Geometry對象是否相交。如果兩個Geometry對象有任意共用空間的部分,那麼兩個Geometry對象相交,ST_Intersects函數則返回true。

文法

  • 判斷對象geomA和對象geomB的是否相交

    boolean ST_Intersects(geometry geomA, geometry geomB)
  • 判斷對象geom和點座標(x,y)是否相交

    boolean ST_Intersects(geometry geom, double x, double y)

參數說明

參數

描述

geomA

指定的第一個Geometry對象。

geomB

指定的第二個Geometry對象。

geom

指定的Geometry對象。

x

座標經度x值。

y

座標緯度y值。

說明

Geometry對象支援Point、LineString、Polygon、MultiPoint、MultiLineString、MultiPolygon和GeometryCollection類型。

樣本

  • 樣本1

    SELECT ST_Intersects(ST_GeomFromText('POINT(0 0)'), ST_GeomFromText('LINESTRING ( 2 0, 0 2 )')) AS isinter;

    返回結果:

    +---------+
    | isinter |
    +---------+
    | false   |
    +---------+
  • 樣本2

    SELECT ST_Intersects(ST_GeomFromText('LINESTRING ( 2 0, 0 2 )'), 0, 0) AS isinter;

    返回結果:

    +---------+
    | isinter |
    +---------+
    | false   |
    +---------+
  • 樣本3

    SELECT ST_Intersects(ST_GeomFromText('POINT(0 0)'), ST_GeomFromText('LINESTRING ( 0 0, 0 2 )')) AS isinter;

    返回結果:

    +---------+
    | isinter |
    +---------+
    | true    |
    +---------+
  • 樣本4

    SELECT ST_Intersects(ST_GeomFromText('LINESTRING ( 0 0, 0 2 )'), 0, 0) AS isinter;

    返回結果:

    +---------+
    | isinter |
    +---------+
    | true    |
    +---------+

ST_Overlaps

如果兩個Geometry對象在空間上有重疊的部分,但不存在其中一個完全包含另一個的情況,ST_Overlaps函數則返回true。

文法

  • 判斷對象geomA和對象geomB在空間上是否有重疊的部分

    boolean ST_Overlaps(geometry geomA, geometry geomB)
  • 判斷對象geom和點座標(x,y)在空間上是否有重疊的部分

    boolean ST_Overlaps(geometry geom, double x, double y)

參數說明

參數

描述

geomA

指定的第一個Geometry對象。

geomB

指定的第二個Geometry對象。

geom

指定的Geometry對象。

x

座標經度x值。

y

座標緯度y值。

說明

Geometry對象支援Point、LineString、Polygon、MultiPoint、MultiLineString、MultiPolygon和GeometryCollection類型。

樣本

  • 樣本1

    SELECT ST_Overlaps(ST_GeomFromText('LINESTRING(0 0,0 2)'),ST_GeomFromText('LINESTRING(0 1,0 3)')) as overlaps;

    返回結果:

    +----------+
    | overlaps |
    +----------+
    | true     |
    +----------+
  • 樣本2

    SELECT ST_Overlaps(ST_GeomFromText('LINESTRING(0 0,0 2)'),ST_GeomFromText('POINT(0 1)')) as overlaps;

    返回結果:

    +----------+
    | overlaps |
    +----------+
    | false    |
    +----------+
  • 樣本3

    SELECT ST_Overlaps(ST_GeomFromText('LINESTRING(0 0,0 2)'), 0, 1) as overlaps;

    返回結果:

    +----------+
    | overlaps |
    +----------+
    | false    |
    +----------+

ST_Within

如果Geometry對象A完全在Geometry對象B內,ST_Within函數則返回true。

文法

  • 判斷對象geomA和對象geomB的內含項目關聯性

    boolean ST_Within(geometry geomA, geometry geomB)
  • 判斷對象geom和點座標(x,y)的內含項目關聯性

    bboolean ST_Within(double x, double y, geometry geom)

參數說明

參數

描述

geomA

指定的第一個Geometry對象。

geomB

指定的第二個Geometry對象。

geom

指定的Geometry對象。

x

座標經度x值。

y

座標緯度y值。

說明
  • Geometry對象支援Point、LineString、Polygon、MultiPoint、MultiLineString、MultiPolygon和GeometryCollection類型。

  • 如果ST_Within(A,B)的返回結果與ST_Within(B,A)的返回結果都為true,則認為Geometry對象A和Geometry對象B在空間上相同。

樣本

  • 樣本1

    SELECT ST_Within(ST_GeomFromText('POINT(5 5)'), ST_GeomFromText('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))')) AS iswithin;

    返回結果:

    +----------+
    | iswithin |
    +----------+
    | true     |
    +----------+
  • 樣本2

    SELECT ST_Within(5, 5, ST_GeomFromText('POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))')) AS iswithin;

    返回結果:

    +----------+
    | iswithin |
    +----------+
    | true     |
    +----------+