Skip to content

ST_Within

Returns true if A is completely inside B.

Usage

boolean ST_Within(geomA: geometry, geomB: geometry)
boolean ST_Within(geogA: geography, geogB: geography)

Arguments

  • geogA (geography): Input geography
  • geogB (geography): Input geography
  • geomA (geometry): Input geometry
  • geomB (geometry): Input geometry

Description

Returns true if geometry A is completely inside geometry B. This is the inverse of ST_Contains: ST_Within(A, B) is equivalent to ST_Contains(B, A).

Examples

SELECT ST_Within(
    ST_GeomFromWKT('POINT (1 1)'),
    ST_GeomFromWKT('POLYGON ((0 0, 2 0, 2 2, 0 2, 0 0))')
);
┌──────────────────────────────────────────────────────────────────────────────┐
│ st_within(st_geomfromwkt(Utf8("POINT (1 1)")),st_geomfromwkt(Utf8("POLYGON ( │
│                        (0 0, 2 0, 2 2, 0 2, 0 0))")))…                       │
╞══════════════════════════════════════════════════════════════════════════════╡
│ true                                                                         │
└──────────────────────────────────────────────────────────────────────────────┘
SELECT ST_Within(
    ST_GeogFromWKT('POINT (1 1)'),
    ST_GeogFromWKT('POLYGON ((0 0, 2 0, 2 2, 0 2, 0 0))')
);
┌──────────────────────────────────────────────────────────────────────────────┐
│ st_within(st_geogfromwkt(Utf8("POINT (1 1)")),st_geogfromwkt(Utf8("POLYGON ( │
│                        (0 0, 2 0, 2 2, 0 2, 0 0))")))…                       │
╞══════════════════════════════════════════════════════════════════════════════╡
│ true                                                                         │
└──────────────────────────────────────────────────────────────────────────────┘