From 47c741ccfc82ed48832cd089855d9bcde856f8f7 Mon Sep 17 00:00:00 2001 From: yy <736262857@qq.com> Date: Sun, 19 Jul 2026 06:54:28 +0000 Subject: [PATCH 1/2] add ST_Within spatial function docs Signed-off-by: yy <736262857@qq.com> --- .../spatial-functions/st-within.md | 169 ++++++++++++++++ .../spatial-functions/st-within.md | 190 ++++++++++++++++++ .../spatial-functions/st-within.md | 168 ++++++++++++++++ sidebars.ts | 1 + .../spatial-functions/st-within.md | 57 ++++++ .../spatial-functions/st-within.md | 169 ++++++++++++++++ .../spatial-functions/st-within.md | 169 ++++++++++++++++ versioned_sidebars/version-2.1-sidebars.json | 1 + versioned_sidebars/version-3.x-sidebars.json | 1 + versioned_sidebars/version-4.x-sidebars.json | 1 + 10 files changed, 926 insertions(+) create mode 100644 docs/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md create mode 100644 i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md create mode 100644 ja-source/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md create mode 100644 versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md create mode 100644 versioned_docs/version-3.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md create mode 100644 versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md diff --git a/docs/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md b/docs/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md new file mode 100644 index 0000000000000..324278dca00d9 --- /dev/null +++ b/docs/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md @@ -0,0 +1,169 @@ +--- +{ + "title": "ST_WITHIN", + "language": "en", + "description": "Determines whether one geometric shape (shape1) is completely inside another geometric shape (shape2)." +} +--- + +## Description + +Determines whether one geometric shape (shape1) is completely inside another geometric shape (shape2). Returns 1 if shape1 is entirely within shape2; otherwise, returns 0. + +`ST_WITHIN(shape1, shape2)` is logically equivalent to `ST_CONTAINS(shape2, shape1)`. + +- For points: The point must lie inside or on the boundary of the polygon. +- For lines: All points of the line must lie inside or on the boundary of the polygon. +- For polygons: The inner polygon must be entirely inside the outer polygon (boundaries can overlap). + +## Syntax + +```sql +ST_WITHIN( , ) +``` + +## Parameters + +| Parameters | Description | +|----------|------------------------| +| `` | The geometric shape to check if it is inside the other shape, supporting types such as Point, Line, Polygon, etc. | +| `` | The geometric shape used to check if it contains shape1, supporting the Polygon type. | + +## Return Value + +- 1: Indicates that shape1 is completely inside shape2. +- 0: Indicates that shape1 is not inside shape2. + +ST_WITHIN has the following edge cases: + +- Returns NULL if either input parameter is NULL. +- Returns NULL if the input geometric shape is invalid (e.g., a self-intersecting polygon). +- Returns 0 if shape1 lies partially on the boundary but also partially outside shape2. + +## Example + +Point inside polygon + +```sql +SELECT ST_Within(ST_Point(5, 5), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-------------------------------------------------------------------------------------+ +| st_within(st_point(5.0, 5.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-------------------------------------------------------------------------------------+ +| 1 | ++-------------------------------------------------------------------------------------+ +``` + +Point outside polygon + +```sql +SELECT ST_Within(ST_Point(50, 50), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++---------------------------------------------------------------------------------------+ +| st_within(st_point(50.0, 50.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++---------------------------------------------------------------------------------------+ +| 0 | ++---------------------------------------------------------------------------------------+ +``` + +Line completely inside polygon + +```sql +SELECT ST_Within(ST_LineFromText("LINESTRING (2 2, 8 8)"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------------------------------+ +| st_within(st_linefromtext('LINESTRING (2 2, 8 8)'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------------------------------+ +``` + +Line partially outside polygon + +```sql +SELECT ST_Within(ST_LineFromText("LINESTRING (5 5, 15 15)"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-------------------------------------------------------------------------------------------------------------+ +| st_within(st_linefromtext('LINESTRING (5 5, 15 15)'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-------------------------------------------------------------------------------------------------------------+ +| 0 | ++-------------------------------------------------------------------------------------------------------------+ +``` + +Polygon completely inside polygon + +```sql +SELECT ST_Within(ST_Polygon("POLYGON ((2 2, 8 2, 8 8, 2 8, 2 2))"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------------------------------------------+ +| st_within(st_polygon('POLYGON ((2 2, 8 2, 8 8, 2 8, 2 2))'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------------------------------------------+ +``` + +Polygon partially outside polygon + +```sql +SELECT ST_Within(ST_Polygon("POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++---------------------------------------------------------------------------------------------------------------------------+ +| st_within(st_polygon('POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++---------------------------------------------------------------------------------------------------------------------------+ +| 0 | ++---------------------------------------------------------------------------------------------------------------------------+ +``` + +Point on polygon boundary + +```sql +SELECT ST_Within(ST_Point(0, 5), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------+ +| st_within(st_point(0.0, 5.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------+ +``` + +NULL parameter (returns NULL) + +```sql +SELECT ST_Within(ST_Point(5, 5), NULL); +``` + +```text ++-----------------------------------+ +| ST_Within(ST_Point(5, 5), NULL) | ++-----------------------------------+ +| NULL | ++-----------------------------------+ +``` + +Self-intersecting polygon as parameter + +```sql +SELECT ST_Within(ST_Point(0.5, 0.5), ST_Polygon("POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------+ +| st_within(st_point(0.5, 0.5), st_polygon('POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))')) | ++-----------------------------------------------------------------------------------+ +| NULL | ++-----------------------------------------------------------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md new file mode 100644 index 0000000000000..13213c030a19b --- /dev/null +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md @@ -0,0 +1,190 @@ +--- +{ + "title": "ST_WITHIN", + "language": "zh-CN", + "description": "判断一个几何图形(shape1)是否完全位于另一个几何图形(shape2)的内部。若 shape1 的所有点都位于 shape2 内部,则返回 1;否则返回 0。" +} +--- + + + + +## 描述 + +判断一个几何图形(shape1)是否完全位于另一个几何图形(shape2)的内部。若 shape1 的所有点都位于 shape2 内部,则返回 1;否则返回 0。 + +`ST_WITHIN(shape1, shape2)` 在逻辑上等价于 `ST_CONTAINS(shape2, shape1)`。 + +- 对于点:点必须位于多边形内部或边界上。 +- 对于线:线的所有点必须位于多边形内部或边界上。 +- 对于多边形:内部多边形必须完全位于外部多边形的内部(边界可以重叠)。 + +## 语法 + +```sql +ST_WITHIN( , ) +``` + +## 参数 + +| 参数 | 说明 | +|----------|------------------------| +| `` | 用于判断是否在另一个图形内部的几何图形,支持 Point、Line、Polygon 等类型。 | +| `` | 用于判断是否包含 shape1 的几何图形,支持 Polygon 类型。 | + +## 返回值 + +返回 1:shape1 完全位于 shape2 内部。 + +返回 0:shape1 不位于 shape2 内部。 + +ST_WITHIN 存在以下边缘情况: + +- 若任一输入参数为 NULL,返回 NULL。 +- 若输入的几何图形无效(如自相交的多边形),返回 NULL。 +- 若 shape1 部分位于 shape2 的边界上,但部分在 shape2 外部,返回 0。 + +## 举例 + +点在多边形内部 + +```sql +SELECT ST_Within(ST_Point(5, 5), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-------------------------------------------------------------------------------------+ +| st_within(st_point(5.0, 5.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-------------------------------------------------------------------------------------+ +| 1 | ++-------------------------------------------------------------------------------------+ +``` + +点在多边形外部 + +```sql +SELECT ST_Within(ST_Point(50, 50), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++---------------------------------------------------------------------------------------+ +| st_within(st_point(50.0, 50.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++---------------------------------------------------------------------------------------+ +| 0 | ++---------------------------------------------------------------------------------------+ +``` + +线完全在多边形内部 + +```sql +SELECT ST_Within(ST_LineFromText("LINESTRING (2 2, 8 8)"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------------------------------+ +| st_within(st_linefromtext('LINESTRING (2 2, 8 8)'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------------------------------+ +``` + +线部分在多边形外部 + +```sql +SELECT ST_Within(ST_LineFromText("LINESTRING (5 5, 15 15)"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-------------------------------------------------------------------------------------------------------------+ +| st_within(st_linefromtext('LINESTRING (5 5, 15 15)'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-------------------------------------------------------------------------------------------------------------+ +| 0 | ++-------------------------------------------------------------------------------------------------------------+ +``` + +多边形完全在另一个多边形内部 + +```sql +SELECT ST_Within(ST_Polygon("POLYGON ((2 2, 8 2, 8 8, 2 8, 2 2))"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------------------------------------------+ +| st_within(st_polygon('POLYGON ((2 2, 8 2, 8 8, 2 8, 2 2))'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------------------------------------------+ +``` + +多边形部分在外部 + +```sql +SELECT ST_Within(ST_Polygon("POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++---------------------------------------------------------------------------------------------------------------------------+ +| st_within(st_polygon('POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++---------------------------------------------------------------------------------------------------------------------------+ +| 0 | ++---------------------------------------------------------------------------------------------------------------------------+ +``` + +点在多边形边界上 + +```sql +SELECT ST_Within(ST_Point(0, 5), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------+ +| st_within(st_point(0.0, 5.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------+ +``` + +参数为 NULL(返回 NULL) + +```sql +SELECT ST_Within(ST_Point(5, 5), NULL); +``` + +```text ++-----------------------------------+ +| ST_Within(ST_Point(5, 5), NULL) | ++-----------------------------------+ +| NULL | ++-----------------------------------+ +``` + +自相交多边形作为参数 + +```sql +SELECT ST_Within(ST_Point(0.5, 0.5), ST_Polygon("POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------+ +| st_within(st_point(0.5, 0.5), st_polygon('POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))')) | ++-----------------------------------------------------------------------------------+ +| NULL | ++-----------------------------------------------------------------------------------+ +``` diff --git a/ja-source/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md b/ja-source/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md new file mode 100644 index 0000000000000..9d575180473e8 --- /dev/null +++ b/ja-source/docusaurus-plugin-content-docs/current/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md @@ -0,0 +1,168 @@ +--- +{ + "title": "ST_WITHIN", + "language": "ja", + "description": "ある幾何学的図形(shape1)が別の幾何学的図形(shape2)の完全に内側にあるかどうかを判定します。" +} +--- +## 詳細 + +ある幾何学的図形(shape1)が別の幾何学的図形(shape2)の完全に内側にあるかどうかを判定します。shape1 のすべての点が shape2 の内側にある場合は 1 を返し、そうでない場合は 0 を返します。 + +`ST_WITHIN(shape1, shape2)` は論理的に `ST_CONTAINS(shape2, shape1)` と等価です。 + +- 点の場合:点はポリゴンの内側または境界上に位置している必要があります。 +- 線の場合:線のすべての点がポリゴンの内側または境界上に位置している必要があります。 +- ポリゴンの場合:内側のポリゴンは外側のポリゴンの完全に内側に位置している必要があります(境界は重複可能です)。 + +## Syntax + +```sql +ST_WITHIN( , ) +``` + +## パラメータ + +| パラメータ | 説明 | +|----------|------------------------| +| `` | 別の図形の内側にあるかどうかをチェックする幾何学的図形。Point、Line、Polygon などのタイプをサポートします。 | +| `` | shape1 を含むかどうかをチェックする幾何学的図形。Polygon タイプをサポートします。 | + +## 戻り値 + +- 1:shape1 が shape2 の完全に内側にあることを示します。 +- 0:shape1 が shape2 の内側にないことを示します。 + +ST_WITHIN には以下のエッジケースがあります: + +- いずれかの入力パラメータが NULL の場合は NULL を返します。 +- 入力された幾何学的図形が無効な場合(例:自己交差するポリゴン)は NULL を返します。 +- shape1 の一部が shape2 の境界上にあるが、一部が shape2 の外側にある場合は 0 を返します。 + +## 例 + +点がポリゴンの内側にある + +```sql +SELECT ST_Within(ST_Point(5, 5), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-------------------------------------------------------------------------------------+ +| st_within(st_point(5.0, 5.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-------------------------------------------------------------------------------------+ +| 1 | ++-------------------------------------------------------------------------------------+ +``` + +点がポリゴンの外側にある + +```sql +SELECT ST_Within(ST_Point(50, 50), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++---------------------------------------------------------------------------------------+ +| st_within(st_point(50.0, 50.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++---------------------------------------------------------------------------------------+ +| 0 | ++---------------------------------------------------------------------------------------+ +``` + +線が完全にポリゴンの内側にある + +```sql +SELECT ST_Within(ST_LineFromText("LINESTRING (2 2, 8 8)"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------------------------------+ +| st_within(st_linefromtext('LINESTRING (2 2, 8 8)'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------------------------------+ +``` + +線の一部がポリゴンの外側にある + +```sql +SELECT ST_Within(ST_LineFromText("LINESTRING (5 5, 15 15)"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-------------------------------------------------------------------------------------------------------------+ +| st_within(st_linefromtext('LINESTRING (5 5, 15 15)'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-------------------------------------------------------------------------------------------------------------+ +| 0 | ++-------------------------------------------------------------------------------------------------------------+ +``` + +ポリゴンが完全に別のポリゴンの内側にある + +```sql +SELECT ST_Within(ST_Polygon("POLYGON ((2 2, 8 2, 8 8, 2 8, 2 2))"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------------------------------------------+ +| st_within(st_polygon('POLYGON ((2 2, 8 2, 8 8, 2 8, 2 2))'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------------------------------------------+ +``` + +ポリゴンの一部が外側にある + +```sql +SELECT ST_Within(ST_Polygon("POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++---------------------------------------------------------------------------------------------------------------------------+ +| st_within(st_polygon('POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++---------------------------------------------------------------------------------------------------------------------------+ +| 0 | ++---------------------------------------------------------------------------------------------------------------------------+ +``` + +点がポリゴンの境界上にある + +```sql +SELECT ST_Within(ST_Point(0, 5), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------+ +| st_within(st_point(0.0, 5.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------+ +``` + +NULL パラメータ(NULL を返す) + +```sql +SELECT ST_Within(ST_Point(5, 5), NULL); +``` + +```text ++-----------------------------------+ +| ST_Within(ST_Point(5, 5), NULL) | ++-----------------------------------+ +| NULL | ++-----------------------------------+ +``` + +自己交差するポリゴンをパラメータとして使用 + +```sql +SELECT ST_Within(ST_Point(0.5, 0.5), ST_Polygon("POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------+ +| st_within(st_point(0.5, 0.5), st_polygon('POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))')) | ++-----------------------------------------------------------------------------------+ +| NULL | ++-----------------------------------------------------------------------------------+ +``` diff --git a/sidebars.ts b/sidebars.ts index 0a53243f2dd9a..12d39e0b7b1db 100644 --- a/sidebars.ts +++ b/sidebars.ts @@ -1694,6 +1694,7 @@ const sidebars: SidebarsConfig = { 'sql-manual/sql-functions/scalar-functions/spatial-functions/st-point', 'sql-manual/sql-functions/scalar-functions/spatial-functions/st-polygon', 'sql-manual/sql-functions/scalar-functions/spatial-functions/st-touches', + 'sql-manual/sql-functions/scalar-functions/spatial-functions/st-within', 'sql-manual/sql-functions/scalar-functions/spatial-functions/st-x', 'sql-manual/sql-functions/scalar-functions/spatial-functions/st-y', ], diff --git a/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md new file mode 100644 index 0000000000000..7ec064f0d570a --- /dev/null +++ b/versioned_docs/version-2.1/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md @@ -0,0 +1,57 @@ +--- +{ + "title": "ST_WITHIN", + "language": "en", + "description": "Determines whether the geometry shape1 is fully inside the geometry shape2" +} +--- + +## Description + +Determines whether the geometry shape1 is fully inside the geometry shape2 + +## Syntax + +```sql +ST_WITHIN( , ) +``` + +## Parameters + +| Parameters | Instructions | +|----------|------------------------| +| `` | The passed geometry used to determine whether it is inside shape2 | +| `` | The passed geometry used to determine whether it contains shape1 | + +## Return Value + +Return 1:shape1 is fully inside shape2 + +Return 0:shape1 is not inside shape2 + + +## Examples + +```sql +SELECT ST_Within(ST_Point(5, 5), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-------------------------------------------------------------------------------------+ +| st_within(st_point(5.0, 5.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-------------------------------------------------------------------------------------+ +| 1 | ++-------------------------------------------------------------------------------------+ +``` + +```sql +SELECT ST_Within(ST_Point(50, 50), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++---------------------------------------------------------------------------------------+ +| st_within(st_point(50.0, 50.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++---------------------------------------------------------------------------------------+ +| 0 | ++---------------------------------------------------------------------------------------+ +``` diff --git a/versioned_docs/version-3.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md b/versioned_docs/version-3.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md new file mode 100644 index 0000000000000..324278dca00d9 --- /dev/null +++ b/versioned_docs/version-3.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md @@ -0,0 +1,169 @@ +--- +{ + "title": "ST_WITHIN", + "language": "en", + "description": "Determines whether one geometric shape (shape1) is completely inside another geometric shape (shape2)." +} +--- + +## Description + +Determines whether one geometric shape (shape1) is completely inside another geometric shape (shape2). Returns 1 if shape1 is entirely within shape2; otherwise, returns 0. + +`ST_WITHIN(shape1, shape2)` is logically equivalent to `ST_CONTAINS(shape2, shape1)`. + +- For points: The point must lie inside or on the boundary of the polygon. +- For lines: All points of the line must lie inside or on the boundary of the polygon. +- For polygons: The inner polygon must be entirely inside the outer polygon (boundaries can overlap). + +## Syntax + +```sql +ST_WITHIN( , ) +``` + +## Parameters + +| Parameters | Description | +|----------|------------------------| +| `` | The geometric shape to check if it is inside the other shape, supporting types such as Point, Line, Polygon, etc. | +| `` | The geometric shape used to check if it contains shape1, supporting the Polygon type. | + +## Return Value + +- 1: Indicates that shape1 is completely inside shape2. +- 0: Indicates that shape1 is not inside shape2. + +ST_WITHIN has the following edge cases: + +- Returns NULL if either input parameter is NULL. +- Returns NULL if the input geometric shape is invalid (e.g., a self-intersecting polygon). +- Returns 0 if shape1 lies partially on the boundary but also partially outside shape2. + +## Example + +Point inside polygon + +```sql +SELECT ST_Within(ST_Point(5, 5), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-------------------------------------------------------------------------------------+ +| st_within(st_point(5.0, 5.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-------------------------------------------------------------------------------------+ +| 1 | ++-------------------------------------------------------------------------------------+ +``` + +Point outside polygon + +```sql +SELECT ST_Within(ST_Point(50, 50), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++---------------------------------------------------------------------------------------+ +| st_within(st_point(50.0, 50.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++---------------------------------------------------------------------------------------+ +| 0 | ++---------------------------------------------------------------------------------------+ +``` + +Line completely inside polygon + +```sql +SELECT ST_Within(ST_LineFromText("LINESTRING (2 2, 8 8)"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------------------------------+ +| st_within(st_linefromtext('LINESTRING (2 2, 8 8)'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------------------------------+ +``` + +Line partially outside polygon + +```sql +SELECT ST_Within(ST_LineFromText("LINESTRING (5 5, 15 15)"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-------------------------------------------------------------------------------------------------------------+ +| st_within(st_linefromtext('LINESTRING (5 5, 15 15)'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-------------------------------------------------------------------------------------------------------------+ +| 0 | ++-------------------------------------------------------------------------------------------------------------+ +``` + +Polygon completely inside polygon + +```sql +SELECT ST_Within(ST_Polygon("POLYGON ((2 2, 8 2, 8 8, 2 8, 2 2))"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------------------------------------------+ +| st_within(st_polygon('POLYGON ((2 2, 8 2, 8 8, 2 8, 2 2))'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------------------------------------------+ +``` + +Polygon partially outside polygon + +```sql +SELECT ST_Within(ST_Polygon("POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++---------------------------------------------------------------------------------------------------------------------------+ +| st_within(st_polygon('POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++---------------------------------------------------------------------------------------------------------------------------+ +| 0 | ++---------------------------------------------------------------------------------------------------------------------------+ +``` + +Point on polygon boundary + +```sql +SELECT ST_Within(ST_Point(0, 5), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------+ +| st_within(st_point(0.0, 5.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------+ +``` + +NULL parameter (returns NULL) + +```sql +SELECT ST_Within(ST_Point(5, 5), NULL); +``` + +```text ++-----------------------------------+ +| ST_Within(ST_Point(5, 5), NULL) | ++-----------------------------------+ +| NULL | ++-----------------------------------+ +``` + +Self-intersecting polygon as parameter + +```sql +SELECT ST_Within(ST_Point(0.5, 0.5), ST_Polygon("POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------+ +| st_within(st_point(0.5, 0.5), st_polygon('POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))')) | ++-----------------------------------------------------------------------------------+ +| NULL | ++-----------------------------------------------------------------------------------+ +``` diff --git a/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md new file mode 100644 index 0000000000000..324278dca00d9 --- /dev/null +++ b/versioned_docs/version-4.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md @@ -0,0 +1,169 @@ +--- +{ + "title": "ST_WITHIN", + "language": "en", + "description": "Determines whether one geometric shape (shape1) is completely inside another geometric shape (shape2)." +} +--- + +## Description + +Determines whether one geometric shape (shape1) is completely inside another geometric shape (shape2). Returns 1 if shape1 is entirely within shape2; otherwise, returns 0. + +`ST_WITHIN(shape1, shape2)` is logically equivalent to `ST_CONTAINS(shape2, shape1)`. + +- For points: The point must lie inside or on the boundary of the polygon. +- For lines: All points of the line must lie inside or on the boundary of the polygon. +- For polygons: The inner polygon must be entirely inside the outer polygon (boundaries can overlap). + +## Syntax + +```sql +ST_WITHIN( , ) +``` + +## Parameters + +| Parameters | Description | +|----------|------------------------| +| `` | The geometric shape to check if it is inside the other shape, supporting types such as Point, Line, Polygon, etc. | +| `` | The geometric shape used to check if it contains shape1, supporting the Polygon type. | + +## Return Value + +- 1: Indicates that shape1 is completely inside shape2. +- 0: Indicates that shape1 is not inside shape2. + +ST_WITHIN has the following edge cases: + +- Returns NULL if either input parameter is NULL. +- Returns NULL if the input geometric shape is invalid (e.g., a self-intersecting polygon). +- Returns 0 if shape1 lies partially on the boundary but also partially outside shape2. + +## Example + +Point inside polygon + +```sql +SELECT ST_Within(ST_Point(5, 5), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-------------------------------------------------------------------------------------+ +| st_within(st_point(5.0, 5.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-------------------------------------------------------------------------------------+ +| 1 | ++-------------------------------------------------------------------------------------+ +``` + +Point outside polygon + +```sql +SELECT ST_Within(ST_Point(50, 50), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++---------------------------------------------------------------------------------------+ +| st_within(st_point(50.0, 50.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++---------------------------------------------------------------------------------------+ +| 0 | ++---------------------------------------------------------------------------------------+ +``` + +Line completely inside polygon + +```sql +SELECT ST_Within(ST_LineFromText("LINESTRING (2 2, 8 8)"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------------------------------+ +| st_within(st_linefromtext('LINESTRING (2 2, 8 8)'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------------------------------+ +``` + +Line partially outside polygon + +```sql +SELECT ST_Within(ST_LineFromText("LINESTRING (5 5, 15 15)"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-------------------------------------------------------------------------------------------------------------+ +| st_within(st_linefromtext('LINESTRING (5 5, 15 15)'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-------------------------------------------------------------------------------------------------------------+ +| 0 | ++-------------------------------------------------------------------------------------------------------------+ +``` + +Polygon completely inside polygon + +```sql +SELECT ST_Within(ST_Polygon("POLYGON ((2 2, 8 2, 8 8, 2 8, 2 2))"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------------------------------------------+ +| st_within(st_polygon('POLYGON ((2 2, 8 2, 8 8, 2 8, 2 2))'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------------------------------------------+ +``` + +Polygon partially outside polygon + +```sql +SELECT ST_Within(ST_Polygon("POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++---------------------------------------------------------------------------------------------------------------------------+ +| st_within(st_polygon('POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++---------------------------------------------------------------------------------------------------------------------------+ +| 0 | ++---------------------------------------------------------------------------------------------------------------------------+ +``` + +Point on polygon boundary + +```sql +SELECT ST_Within(ST_Point(0, 5), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------+ +| st_within(st_point(0.0, 5.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------+ +``` + +NULL parameter (returns NULL) + +```sql +SELECT ST_Within(ST_Point(5, 5), NULL); +``` + +```text ++-----------------------------------+ +| ST_Within(ST_Point(5, 5), NULL) | ++-----------------------------------+ +| NULL | ++-----------------------------------+ +``` + +Self-intersecting polygon as parameter + +```sql +SELECT ST_Within(ST_Point(0.5, 0.5), ST_Polygon("POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------+ +| st_within(st_point(0.5, 0.5), st_polygon('POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))')) | ++-----------------------------------------------------------------------------------+ +| NULL | ++-----------------------------------------------------------------------------------+ +``` diff --git a/versioned_sidebars/version-2.1-sidebars.json b/versioned_sidebars/version-2.1-sidebars.json index 27d5d68906cf4..136b7cd156bf1 100644 --- a/versioned_sidebars/version-2.1-sidebars.json +++ b/versioned_sidebars/version-2.1-sidebars.json @@ -1277,6 +1277,7 @@ "sql-manual/sql-functions/scalar-functions/spatial-functions/st-point", "sql-manual/sql-functions/scalar-functions/spatial-functions/st-polygon", "sql-manual/sql-functions/scalar-functions/spatial-functions/st-touches", + "sql-manual/sql-functions/scalar-functions/spatial-functions/st-within", "sql-manual/sql-functions/scalar-functions/spatial-functions/st-x", "sql-manual/sql-functions/scalar-functions/spatial-functions/st-y" ] diff --git a/versioned_sidebars/version-3.x-sidebars.json b/versioned_sidebars/version-3.x-sidebars.json index d4de0ce6f0e26..f44e337dc3176 100644 --- a/versioned_sidebars/version-3.x-sidebars.json +++ b/versioned_sidebars/version-3.x-sidebars.json @@ -1452,6 +1452,7 @@ "sql-manual/sql-functions/scalar-functions/spatial-functions/st-point", "sql-manual/sql-functions/scalar-functions/spatial-functions/st-polygon", "sql-manual/sql-functions/scalar-functions/spatial-functions/st-touches", + "sql-manual/sql-functions/scalar-functions/spatial-functions/st-within", "sql-manual/sql-functions/scalar-functions/spatial-functions/st-x", "sql-manual/sql-functions/scalar-functions/spatial-functions/st-y" ] diff --git a/versioned_sidebars/version-4.x-sidebars.json b/versioned_sidebars/version-4.x-sidebars.json index 1e31cb0f28e01..7a50a22901c5b 100644 --- a/versioned_sidebars/version-4.x-sidebars.json +++ b/versioned_sidebars/version-4.x-sidebars.json @@ -1873,6 +1873,7 @@ "sql-manual/sql-functions/scalar-functions/spatial-functions/st-point", "sql-manual/sql-functions/scalar-functions/spatial-functions/st-polygon", "sql-manual/sql-functions/scalar-functions/spatial-functions/st-touches", + "sql-manual/sql-functions/scalar-functions/spatial-functions/st-within", "sql-manual/sql-functions/scalar-functions/spatial-functions/st-x", "sql-manual/sql-functions/scalar-functions/spatial-functions/st-y" ] From e86ce554a20d0e1aa754dc198c8f9dd224c3c519 Mon Sep 17 00:00:00 2001 From: yy <736262857@qq.com> Date: Sun, 19 Jul 2026 07:07:06 +0000 Subject: [PATCH 2/2] add ST_Within i18n docs for zh-CN and ja Signed-off-by: yy <736262857@qq.com> --- .../spatial-functions/st-within.md | 77 +++++++ .../spatial-functions/st-within.md | 190 ++++++++++++++++++ .../spatial-functions/st-within.md | 190 ++++++++++++++++++ .../spatial-functions/st-within.md | 51 +++++ .../spatial-functions/st-within.md | 168 ++++++++++++++++ .../spatial-functions/st-within.md | 168 ++++++++++++++++ 6 files changed, 844 insertions(+) create mode 100644 i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md create mode 100644 i18n/zh-CN/docusaurus-plugin-content-docs/version-3.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md create mode 100644 i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md create mode 100644 ja-source/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md create mode 100644 ja-source/docusaurus-plugin-content-docs/version-3.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md create mode 100644 ja-source/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md new file mode 100644 index 0000000000000..3dcbe5b43508f --- /dev/null +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md @@ -0,0 +1,77 @@ +--- +{ + "title": "ST_WITHIN", + "language": "zh-CN", + "description": "判断几何图形 shape1 是否完全位于几何图形 shape2 的内部" +} +--- + + + + +## 描述 + +判断几何图形 shape1 是否完全位于几何图形 shape2 的内部 + +## 语法 + +```sql +ST_WITHIN( , ) +``` + +## 参数 + +| 参数 | 说明 | +|----------|------------------------| +| `` | 传入的几何图形,用于判断是否在 shape2 内部 | +| `` | 传入的几何图形,用于判断是否包含 shape1 | + +## 返回值 + +返回 1:shape1 完全位于 shape2 内部 + +返回 0:shape1 不完全位于 shape2 内部 + + +## 举例 + +```sql +SELECT ST_Within(ST_Point(5, 5), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-------------------------------------------------------------------------------------+ +| st_within(st_point(5.0, 5.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-------------------------------------------------------------------------------------+ +| 1 | ++-------------------------------------------------------------------------------------+ +``` + +```sql +SELECT ST_Within(ST_Point(50, 50), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++---------------------------------------------------------------------------------------+ +| st_within(st_point(50.0, 50.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++---------------------------------------------------------------------------------------+ +| 0 | ++---------------------------------------------------------------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md new file mode 100644 index 0000000000000..13213c030a19b --- /dev/null +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-3.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md @@ -0,0 +1,190 @@ +--- +{ + "title": "ST_WITHIN", + "language": "zh-CN", + "description": "判断一个几何图形(shape1)是否完全位于另一个几何图形(shape2)的内部。若 shape1 的所有点都位于 shape2 内部,则返回 1;否则返回 0。" +} +--- + + + + +## 描述 + +判断一个几何图形(shape1)是否完全位于另一个几何图形(shape2)的内部。若 shape1 的所有点都位于 shape2 内部,则返回 1;否则返回 0。 + +`ST_WITHIN(shape1, shape2)` 在逻辑上等价于 `ST_CONTAINS(shape2, shape1)`。 + +- 对于点:点必须位于多边形内部或边界上。 +- 对于线:线的所有点必须位于多边形内部或边界上。 +- 对于多边形:内部多边形必须完全位于外部多边形的内部(边界可以重叠)。 + +## 语法 + +```sql +ST_WITHIN( , ) +``` + +## 参数 + +| 参数 | 说明 | +|----------|------------------------| +| `` | 用于判断是否在另一个图形内部的几何图形,支持 Point、Line、Polygon 等类型。 | +| `` | 用于判断是否包含 shape1 的几何图形,支持 Polygon 类型。 | + +## 返回值 + +返回 1:shape1 完全位于 shape2 内部。 + +返回 0:shape1 不位于 shape2 内部。 + +ST_WITHIN 存在以下边缘情况: + +- 若任一输入参数为 NULL,返回 NULL。 +- 若输入的几何图形无效(如自相交的多边形),返回 NULL。 +- 若 shape1 部分位于 shape2 的边界上,但部分在 shape2 外部,返回 0。 + +## 举例 + +点在多边形内部 + +```sql +SELECT ST_Within(ST_Point(5, 5), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-------------------------------------------------------------------------------------+ +| st_within(st_point(5.0, 5.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-------------------------------------------------------------------------------------+ +| 1 | ++-------------------------------------------------------------------------------------+ +``` + +点在多边形外部 + +```sql +SELECT ST_Within(ST_Point(50, 50), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++---------------------------------------------------------------------------------------+ +| st_within(st_point(50.0, 50.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++---------------------------------------------------------------------------------------+ +| 0 | ++---------------------------------------------------------------------------------------+ +``` + +线完全在多边形内部 + +```sql +SELECT ST_Within(ST_LineFromText("LINESTRING (2 2, 8 8)"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------------------------------+ +| st_within(st_linefromtext('LINESTRING (2 2, 8 8)'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------------------------------+ +``` + +线部分在多边形外部 + +```sql +SELECT ST_Within(ST_LineFromText("LINESTRING (5 5, 15 15)"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-------------------------------------------------------------------------------------------------------------+ +| st_within(st_linefromtext('LINESTRING (5 5, 15 15)'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-------------------------------------------------------------------------------------------------------------+ +| 0 | ++-------------------------------------------------------------------------------------------------------------+ +``` + +多边形完全在另一个多边形内部 + +```sql +SELECT ST_Within(ST_Polygon("POLYGON ((2 2, 8 2, 8 8, 2 8, 2 2))"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------------------------------------------+ +| st_within(st_polygon('POLYGON ((2 2, 8 2, 8 8, 2 8, 2 2))'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------------------------------------------+ +``` + +多边形部分在外部 + +```sql +SELECT ST_Within(ST_Polygon("POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++---------------------------------------------------------------------------------------------------------------------------+ +| st_within(st_polygon('POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++---------------------------------------------------------------------------------------------------------------------------+ +| 0 | ++---------------------------------------------------------------------------------------------------------------------------+ +``` + +点在多边形边界上 + +```sql +SELECT ST_Within(ST_Point(0, 5), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------+ +| st_within(st_point(0.0, 5.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------+ +``` + +参数为 NULL(返回 NULL) + +```sql +SELECT ST_Within(ST_Point(5, 5), NULL); +``` + +```text ++-----------------------------------+ +| ST_Within(ST_Point(5, 5), NULL) | ++-----------------------------------+ +| NULL | ++-----------------------------------+ +``` + +自相交多边形作为参数 + +```sql +SELECT ST_Within(ST_Point(0.5, 0.5), ST_Polygon("POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------+ +| st_within(st_point(0.5, 0.5), st_polygon('POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))')) | ++-----------------------------------------------------------------------------------+ +| NULL | ++-----------------------------------------------------------------------------------+ +``` diff --git a/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md new file mode 100644 index 0000000000000..13213c030a19b --- /dev/null +++ b/i18n/zh-CN/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md @@ -0,0 +1,190 @@ +--- +{ + "title": "ST_WITHIN", + "language": "zh-CN", + "description": "判断一个几何图形(shape1)是否完全位于另一个几何图形(shape2)的内部。若 shape1 的所有点都位于 shape2 内部,则返回 1;否则返回 0。" +} +--- + + + + +## 描述 + +判断一个几何图形(shape1)是否完全位于另一个几何图形(shape2)的内部。若 shape1 的所有点都位于 shape2 内部,则返回 1;否则返回 0。 + +`ST_WITHIN(shape1, shape2)` 在逻辑上等价于 `ST_CONTAINS(shape2, shape1)`。 + +- 对于点:点必须位于多边形内部或边界上。 +- 对于线:线的所有点必须位于多边形内部或边界上。 +- 对于多边形:内部多边形必须完全位于外部多边形的内部(边界可以重叠)。 + +## 语法 + +```sql +ST_WITHIN( , ) +``` + +## 参数 + +| 参数 | 说明 | +|----------|------------------------| +| `` | 用于判断是否在另一个图形内部的几何图形,支持 Point、Line、Polygon 等类型。 | +| `` | 用于判断是否包含 shape1 的几何图形,支持 Polygon 类型。 | + +## 返回值 + +返回 1:shape1 完全位于 shape2 内部。 + +返回 0:shape1 不位于 shape2 内部。 + +ST_WITHIN 存在以下边缘情况: + +- 若任一输入参数为 NULL,返回 NULL。 +- 若输入的几何图形无效(如自相交的多边形),返回 NULL。 +- 若 shape1 部分位于 shape2 的边界上,但部分在 shape2 外部,返回 0。 + +## 举例 + +点在多边形内部 + +```sql +SELECT ST_Within(ST_Point(5, 5), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-------------------------------------------------------------------------------------+ +| st_within(st_point(5.0, 5.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-------------------------------------------------------------------------------------+ +| 1 | ++-------------------------------------------------------------------------------------+ +``` + +点在多边形外部 + +```sql +SELECT ST_Within(ST_Point(50, 50), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++---------------------------------------------------------------------------------------+ +| st_within(st_point(50.0, 50.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++---------------------------------------------------------------------------------------+ +| 0 | ++---------------------------------------------------------------------------------------+ +``` + +线完全在多边形内部 + +```sql +SELECT ST_Within(ST_LineFromText("LINESTRING (2 2, 8 8)"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------------------------------+ +| st_within(st_linefromtext('LINESTRING (2 2, 8 8)'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------------------------------+ +``` + +线部分在多边形外部 + +```sql +SELECT ST_Within(ST_LineFromText("LINESTRING (5 5, 15 15)"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-------------------------------------------------------------------------------------------------------------+ +| st_within(st_linefromtext('LINESTRING (5 5, 15 15)'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-------------------------------------------------------------------------------------------------------------+ +| 0 | ++-------------------------------------------------------------------------------------------------------------+ +``` + +多边形完全在另一个多边形内部 + +```sql +SELECT ST_Within(ST_Polygon("POLYGON ((2 2, 8 2, 8 8, 2 8, 2 2))"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------------------------------------------+ +| st_within(st_polygon('POLYGON ((2 2, 8 2, 8 8, 2 8, 2 2))'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------------------------------------------+ +``` + +多边形部分在外部 + +```sql +SELECT ST_Within(ST_Polygon("POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++---------------------------------------------------------------------------------------------------------------------------+ +| st_within(st_polygon('POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++---------------------------------------------------------------------------------------------------------------------------+ +| 0 | ++---------------------------------------------------------------------------------------------------------------------------+ +``` + +点在多边形边界上 + +```sql +SELECT ST_Within(ST_Point(0, 5), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------+ +| st_within(st_point(0.0, 5.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------+ +``` + +参数为 NULL(返回 NULL) + +```sql +SELECT ST_Within(ST_Point(5, 5), NULL); +``` + +```text ++-----------------------------------+ +| ST_Within(ST_Point(5, 5), NULL) | ++-----------------------------------+ +| NULL | ++-----------------------------------+ +``` + +自相交多边形作为参数 + +```sql +SELECT ST_Within(ST_Point(0.5, 0.5), ST_Polygon("POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------+ +| st_within(st_point(0.5, 0.5), st_polygon('POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))')) | ++-----------------------------------------------------------------------------------+ +| NULL | ++-----------------------------------------------------------------------------------+ +``` diff --git a/ja-source/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md b/ja-source/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md new file mode 100644 index 0000000000000..280a7cb9db83b --- /dev/null +++ b/ja-source/docusaurus-plugin-content-docs/version-2.1/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md @@ -0,0 +1,51 @@ +--- +{ + "title": "ST_WITHIN", + "language": "ja", + "description": "ジオメトリshape1がジオメトリshape2の完全に内側にあるかどうかを判定する" +} +--- +## 説明 + +ジオメトリshape1がジオメトリshape2の完全に内側にあるかどうかを判定します + +## 構文 + +```sql +ST_WITHIN( , ) +``` +## パラメータ + +| パラメータ | 説明 | +|----------|------------------------| +| `` | shape2の内側にあるかどうかを判定するために渡されるジオメトリ | +| `` | shape1が含まれるかどうかを判定するために渡されるジオメトリ | + +## 戻り値 + +1を返す:shape1がshape2の完全に内側にある + +0を返す:shape1がshape2の内側にない + +## 例 + +```sql +SELECT ST_Within(ST_Point(5, 5), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` +```text ++-------------------------------------------------------------------------------------+ +| st_within(st_point(5.0, 5.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-------------------------------------------------------------------------------------+ +| 1 | ++-------------------------------------------------------------------------------------+ +``` +```sql +SELECT ST_Within(ST_Point(50, 50), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` +```text ++---------------------------------------------------------------------------------------+ +| st_within(st_point(50.0, 50.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++---------------------------------------------------------------------------------------+ +| 0 | ++---------------------------------------------------------------------------------------+ +``` diff --git a/ja-source/docusaurus-plugin-content-docs/version-3.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md b/ja-source/docusaurus-plugin-content-docs/version-3.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md new file mode 100644 index 0000000000000..9d575180473e8 --- /dev/null +++ b/ja-source/docusaurus-plugin-content-docs/version-3.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md @@ -0,0 +1,168 @@ +--- +{ + "title": "ST_WITHIN", + "language": "ja", + "description": "ある幾何学的図形(shape1)が別の幾何学的図形(shape2)の完全に内側にあるかどうかを判定します。" +} +--- +## 詳細 + +ある幾何学的図形(shape1)が別の幾何学的図形(shape2)の完全に内側にあるかどうかを判定します。shape1 のすべての点が shape2 の内側にある場合は 1 を返し、そうでない場合は 0 を返します。 + +`ST_WITHIN(shape1, shape2)` は論理的に `ST_CONTAINS(shape2, shape1)` と等価です。 + +- 点の場合:点はポリゴンの内側または境界上に位置している必要があります。 +- 線の場合:線のすべての点がポリゴンの内側または境界上に位置している必要があります。 +- ポリゴンの場合:内側のポリゴンは外側のポリゴンの完全に内側に位置している必要があります(境界は重複可能です)。 + +## Syntax + +```sql +ST_WITHIN( , ) +``` + +## パラメータ + +| パラメータ | 説明 | +|----------|------------------------| +| `` | 別の図形の内側にあるかどうかをチェックする幾何学的図形。Point、Line、Polygon などのタイプをサポートします。 | +| `` | shape1 を含むかどうかをチェックする幾何学的図形。Polygon タイプをサポートします。 | + +## 戻り値 + +- 1:shape1 が shape2 の完全に内側にあることを示します。 +- 0:shape1 が shape2 の内側にないことを示します。 + +ST_WITHIN には以下のエッジケースがあります: + +- いずれかの入力パラメータが NULL の場合は NULL を返します。 +- 入力された幾何学的図形が無効な場合(例:自己交差するポリゴン)は NULL を返します。 +- shape1 の一部が shape2 の境界上にあるが、一部が shape2 の外側にある場合は 0 を返します。 + +## 例 + +点がポリゴンの内側にある + +```sql +SELECT ST_Within(ST_Point(5, 5), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-------------------------------------------------------------------------------------+ +| st_within(st_point(5.0, 5.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-------------------------------------------------------------------------------------+ +| 1 | ++-------------------------------------------------------------------------------------+ +``` + +点がポリゴンの外側にある + +```sql +SELECT ST_Within(ST_Point(50, 50), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++---------------------------------------------------------------------------------------+ +| st_within(st_point(50.0, 50.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++---------------------------------------------------------------------------------------+ +| 0 | ++---------------------------------------------------------------------------------------+ +``` + +線が完全にポリゴンの内側にある + +```sql +SELECT ST_Within(ST_LineFromText("LINESTRING (2 2, 8 8)"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------------------------------+ +| st_within(st_linefromtext('LINESTRING (2 2, 8 8)'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------------------------------+ +``` + +線の一部がポリゴンの外側にある + +```sql +SELECT ST_Within(ST_LineFromText("LINESTRING (5 5, 15 15)"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-------------------------------------------------------------------------------------------------------------+ +| st_within(st_linefromtext('LINESTRING (5 5, 15 15)'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-------------------------------------------------------------------------------------------------------------+ +| 0 | ++-------------------------------------------------------------------------------------------------------------+ +``` + +ポリゴンが完全に別のポリゴンの内側にある + +```sql +SELECT ST_Within(ST_Polygon("POLYGON ((2 2, 8 2, 8 8, 2 8, 2 2))"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------------------------------------------+ +| st_within(st_polygon('POLYGON ((2 2, 8 2, 8 8, 2 8, 2 2))'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------------------------------------------+ +``` + +ポリゴンの一部が外側にある + +```sql +SELECT ST_Within(ST_Polygon("POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++---------------------------------------------------------------------------------------------------------------------------+ +| st_within(st_polygon('POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++---------------------------------------------------------------------------------------------------------------------------+ +| 0 | ++---------------------------------------------------------------------------------------------------------------------------+ +``` + +点がポリゴンの境界上にある + +```sql +SELECT ST_Within(ST_Point(0, 5), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------+ +| st_within(st_point(0.0, 5.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------+ +``` + +NULL パラメータ(NULL を返す) + +```sql +SELECT ST_Within(ST_Point(5, 5), NULL); +``` + +```text ++-----------------------------------+ +| ST_Within(ST_Point(5, 5), NULL) | ++-----------------------------------+ +| NULL | ++-----------------------------------+ +``` + +自己交差するポリゴンをパラメータとして使用 + +```sql +SELECT ST_Within(ST_Point(0.5, 0.5), ST_Polygon("POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------+ +| st_within(st_point(0.5, 0.5), st_polygon('POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))')) | ++-----------------------------------------------------------------------------------+ +| NULL | ++-----------------------------------------------------------------------------------+ +``` diff --git a/ja-source/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md b/ja-source/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md new file mode 100644 index 0000000000000..9d575180473e8 --- /dev/null +++ b/ja-source/docusaurus-plugin-content-docs/version-4.x/sql-manual/sql-functions/scalar-functions/spatial-functions/st-within.md @@ -0,0 +1,168 @@ +--- +{ + "title": "ST_WITHIN", + "language": "ja", + "description": "ある幾何学的図形(shape1)が別の幾何学的図形(shape2)の完全に内側にあるかどうかを判定します。" +} +--- +## 詳細 + +ある幾何学的図形(shape1)が別の幾何学的図形(shape2)の完全に内側にあるかどうかを判定します。shape1 のすべての点が shape2 の内側にある場合は 1 を返し、そうでない場合は 0 を返します。 + +`ST_WITHIN(shape1, shape2)` は論理的に `ST_CONTAINS(shape2, shape1)` と等価です。 + +- 点の場合:点はポリゴンの内側または境界上に位置している必要があります。 +- 線の場合:線のすべての点がポリゴンの内側または境界上に位置している必要があります。 +- ポリゴンの場合:内側のポリゴンは外側のポリゴンの完全に内側に位置している必要があります(境界は重複可能です)。 + +## Syntax + +```sql +ST_WITHIN( , ) +``` + +## パラメータ + +| パラメータ | 説明 | +|----------|------------------------| +| `` | 別の図形の内側にあるかどうかをチェックする幾何学的図形。Point、Line、Polygon などのタイプをサポートします。 | +| `` | shape1 を含むかどうかをチェックする幾何学的図形。Polygon タイプをサポートします。 | + +## 戻り値 + +- 1:shape1 が shape2 の完全に内側にあることを示します。 +- 0:shape1 が shape2 の内側にないことを示します。 + +ST_WITHIN には以下のエッジケースがあります: + +- いずれかの入力パラメータが NULL の場合は NULL を返します。 +- 入力された幾何学的図形が無効な場合(例:自己交差するポリゴン)は NULL を返します。 +- shape1 の一部が shape2 の境界上にあるが、一部が shape2 の外側にある場合は 0 を返します。 + +## 例 + +点がポリゴンの内側にある + +```sql +SELECT ST_Within(ST_Point(5, 5), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-------------------------------------------------------------------------------------+ +| st_within(st_point(5.0, 5.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-------------------------------------------------------------------------------------+ +| 1 | ++-------------------------------------------------------------------------------------+ +``` + +点がポリゴンの外側にある + +```sql +SELECT ST_Within(ST_Point(50, 50), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++---------------------------------------------------------------------------------------+ +| st_within(st_point(50.0, 50.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++---------------------------------------------------------------------------------------+ +| 0 | ++---------------------------------------------------------------------------------------+ +``` + +線が完全にポリゴンの内側にある + +```sql +SELECT ST_Within(ST_LineFromText("LINESTRING (2 2, 8 8)"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------------------------------+ +| st_within(st_linefromtext('LINESTRING (2 2, 8 8)'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------------------------------+ +``` + +線の一部がポリゴンの外側にある + +```sql +SELECT ST_Within(ST_LineFromText("LINESTRING (5 5, 15 15)"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-------------------------------------------------------------------------------------------------------------+ +| st_within(st_linefromtext('LINESTRING (5 5, 15 15)'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-------------------------------------------------------------------------------------------------------------+ +| 0 | ++-------------------------------------------------------------------------------------------------------------+ +``` + +ポリゴンが完全に別のポリゴンの内側にある + +```sql +SELECT ST_Within(ST_Polygon("POLYGON ((2 2, 8 2, 8 8, 2 8, 2 2))"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------------------------------------------+ +| st_within(st_polygon('POLYGON ((2 2, 8 2, 8 8, 2 8, 2 2))'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------------------------------------------+ +``` + +ポリゴンの一部が外側にある + +```sql +SELECT ST_Within(ST_Polygon("POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))"), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++---------------------------------------------------------------------------------------------------------------------------+ +| st_within(st_polygon('POLYGON ((5 5, 15 5, 15 15, 5 15, 5 5))'), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++---------------------------------------------------------------------------------------------------------------------------+ +| 0 | ++---------------------------------------------------------------------------------------------------------------------------+ +``` + +点がポリゴンの境界上にある + +```sql +SELECT ST_Within(ST_Point(0, 5), ST_Polygon("POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------+ +| st_within(st_point(0.0, 5.0), st_polygon('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')) | ++-----------------------------------------------------------------------------------+ +| 1 | ++-----------------------------------------------------------------------------------+ +``` + +NULL パラメータ(NULL を返す) + +```sql +SELECT ST_Within(ST_Point(5, 5), NULL); +``` + +```text ++-----------------------------------+ +| ST_Within(ST_Point(5, 5), NULL) | ++-----------------------------------+ +| NULL | ++-----------------------------------+ +``` + +自己交差するポリゴンをパラメータとして使用 + +```sql +SELECT ST_Within(ST_Point(0.5, 0.5), ST_Polygon("POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))")); +``` + +```text ++-----------------------------------------------------------------------------------+ +| st_within(st_point(0.5, 0.5), st_polygon('POLYGON ((0 0, 1 1, 0 1, 1 0, 0 0))')) | ++-----------------------------------------------------------------------------------+ +| NULL | ++-----------------------------------------------------------------------------------+ +```