Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ST_ANGLE( <point1>, <point2>, <point3>)
|----------|--------------------------|
| `<point1>` | The first endpoint of the first line, of type `GeoPoint` |
| `<point2>` | The second endpoint of the first line and the first endpoint of the second line, of type `GeoPoint` |
| `<point3>` | The second endpoint of the second line, of type `GeoPint` |
| `<point3>` | The second endpoint of the second line, of type `GeoPoint` |

## Retuen Value

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
---
{
"title": "ST_DISTANCE",
"language": "en",
"description": "Calculates the shortest distance on the sphere between two geometry objects, in meters."
}
---

## Description

Calculates the shortest distance on the sphere between two geometry objects, in meters. This function uses a spherical Earth model for calculation.

Unlike `ST_DISTANCE_SPHERE`, which accepts longitude and latitude coordinates, `ST_DISTANCE` accepts geometry objects (points, lines, polygons, circles, etc.) as parameters and calculates the shortest distance between their boundaries. If the two shapes intersect (including touching or containing each other), it returns 0.

## Syntax

```sql
ST_DISTANCE( <shape1>, <shape2> )
```

## Parameters

| Parameter | Description |
| :--- | :--- |
| `<shape1>` | The first geometry, supporting Point, Line, Polygon, Circle, MultiPolygon. |
| `<shape2>` | The second geometry, supporting Point, Line, Polygon, Circle, MultiPolygon. |

## Return Value

Returns the shortest spherical distance between the boundaries of the two geometry objects, in meters (DOUBLE type).

`ST_DISTANCE` has the following edge cases:
- If any input parameter is `NULL`, returns `NULL`.
- If any input parameter cannot be parsed into a valid geometry object, returns `NULL`.
- If the two geometry objects intersect (including one containing the other), returns `0.0`.
- Supported geometry types include: `POINT`, `LINESTRING`, `POLYGON`, `CIRCLE`, etc.

## Example

**Distance Between Points**
```sql
-- Calculate the distance between two points with a 1-degree longitude difference on the equator
SELECT ST_DISTANCE(ST_GeometryFromText('POINT(0 0)'), ST_GeometryFromText('POINT(1 0)'));
```
```text
+---------------------------------------------+
| ST_Distance(ST_Point(0, 0), ST_Point(1, 0)) |
+---------------------------------------------+
| 111195.1011774839 |
+---------------------------------------------+
```

**Distance Between a Point and a Line**
```sql
-- Calculate the shortest distance from a point to a line
SELECT ST_DISTANCE(ST_GeometryFromText('POINT(2 2)'), ST_GeometryFromText('LINESTRING(0 0, 10 0)'));
```
```text
+----------------------------------------------------------------------------------------------+
| ST_DISTANCE(ST_GeometryFromText('POINT(2 2)'), ST_GeometryFromText('LINESTRING(0 0, 10 0)')) |
+----------------------------------------------------------------------------------------------+
| 222390.2023549678 |
+----------------------------------------------------------------------------------------------+
```

**Polygon and Circle Intersect (Distance 0)**
```sql
-- Circle intersects polygon; the center is outside but the circle covers part of the polygon's boundary
SELECT ST_DISTANCE(
ST_GeometryFromText('POLYGON ((-0.00045 -0.00045, 0.00045 -0.00045, 0.00045 0.00045, -0.00045 0.00045, -0.00045 -0.00045))'),
ST_Circle(0.0006, 0, 50)
);
```
```text
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| ST_DISTANCE(
ST_GeometryFromText('POLYGON ((-0.00045 -0.00045, 0.00045 -0.00045, 0.00045 0.00045, -0.00045 0.00045, -0.00045 -0.00045))'),
ST_Circle(0.0006, 0, 50)
) |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| 0 |
+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
```

**Invalid Parameter (Returns NULL)**
```sql
-- Invalid WKT string
SELECT ST_DISTANCE(ST_GeometryFromText('NOT_A_GEOMETRY'), ST_GeometryFromText('POINT(1 1)'));
```
```text
+---------------------------------------------------------------------------------------+
| ST_DISTANCE(ST_GeometryFromText('NOT_A_GEOMETRY'), ST_GeometryFromText('POINT(1 1)')) |
+---------------------------------------------------------------------------------------+
| NULL |
+---------------------------------------------------------------------------------------+
```

**NULL Parameter**
```sql
SELECT ST_DISTANCE(NULL, ST_GeometryFromText('POINT(1 1)'));
```
```text
+------------------------------------------------------+
| ST_DISTANCE(NULL, ST_GeometryFromText('POINT(1 1)')) |
+------------------------------------------------------+
| NULL |
+------------------------------------------------------+
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
---
{
"title": "ST_GEOMETRYTYPE",
"language": "en",
"description": "Returns the type name of a geometry object."
}
---

## Description

Returns the type name (in uppercase) of a given geometry object. Used to identify the specific type of a geometric shape.

## Syntax

```sql
ST_GEOMETRYTYPE( <shape> )
```

## Parameters

| Parameter | Description |
| :--- | :--- |
| `<shape>` | The input geometry, of type GEOMETRY or VARCHAR (in WKT format) that can be converted to GEOMETRY. |

## Return Value

Returns a VARCHAR type uppercase string representing the geometry object's type.

`ST_GEOMETRYTYPE` has the following edge cases:
- If the input parameter is `NULL`, returns `NULL`.
- If the input parameter cannot be parsed into a valid geometry object, returns `NULL`.
- Supported geometry types and their return value examples are as follows:
- `POINT`: `"ST_POINT"`
- `LINESTRING`: `"ST_LINESTRING"`
- `POLYGON`: `"ST_POLYGON"`
- `MULTIPOLYGON`: `"ST_MULTIPOLYGON"`
- `CIRCLE` : `"ST_CIRCLE"`

## Example

**Type of a Point**
```sql
SELECT ST_GEOMETRYTYPE(ST_GeometryFromText('POINT(1 1)'));
```
```text
+----------------------------------------------------+
| ST_GEOMETRYTYPE(ST_GeometryFromText('POINT(1 1)')) |
+----------------------------------------------------+
| ST_POINT |
+----------------------------------------------------+
```

**Type of a Line**
```sql
SELECT ST_GEOMETRYTYPE(ST_LineFromText("LINESTRING (1 1,2 2,3 3)"));
```
```text
+--------------------------------------------------------------+
| ST_GEOMETRYTYPE(ST_LineFromText("LINESTRING (1 1,2 2,3 3)")) |
+--------------------------------------------------------------+
| ST_LINESTRING |
+--------------------------------------------------------------+
```

**Type of a Polygon**
```sql
SELECT ST_GEOMETRYTYPE(ST_GeometryFromText('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))'));
```
```text
+--------------------------------------------------------------------------------+
| ST_GEOMETRYTYPE(ST_GeometryFromText('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))')) |
+--------------------------------------------------------------------------------+
| ST_POLYGON |
+--------------------------------------------------------------------------------+
```

**Type of a Circle (Doris Extension)**
```sql
SELECT ST_GEOMETRYTYPE(ST_Circle(0, 0, 100));
```
```text
+---------------------------------------+
| ST_GEOMETRYTYPE(ST_Circle(0, 0, 100)) |
+---------------------------------------+
| ST_CIRCLE |
+---------------------------------------+
```

**Invalid Parameter (Returns NULL)**
```sql
SELECT ST_GEOMETRYTYPE('NOT_A_GEOMETRY');
```
```text
+-----------------------------------+
| ST_GEOMETRYTYPE('NOT_A_GEOMETRY') |
+-----------------------------------+
| NULL |
+-----------------------------------+
```

**NULL Parameter**
```sql
SELECT ST_GEOMETRYTYPE(NULL);
```
```text
+-----------------------+
| ST_GEOMETRYTYPE(NULL) |
+-----------------------+
| NULL |
+-----------------------+
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
---
{
"title": "ST_LENGTH",
"language": "en",
"description": "Returns the length (or perimeter) of a line or surface geometry object. The unit is meters."
}
---

## Description

Returns the spherical length of a line geometry object or the boundary perimeter of a surface geometry object, in meters. This function uses a spherical Earth model for calculation.
- For `LINESTRING` or `MULTILINESTRING`, returns the sum of the great-circle distances of all its segments on the sphere, i.e., the **length** of the line object.
- For `POLYGON` or `MULTIPOLYGON`, returns the sum of the great-circle distances of its outer boundary and inner boundaries (holes) on the sphere, i.e., the **perimeter** of the surface object.
- For `CIRCLE`, returns its circumference, calculated by the formula `2 * π * radius`.
- For `POINT`, returns `0.0`.

## Syntax

```sql
ST_LENGTH( <shape> )
```

## Parameters

| Parameter | Description |
| :--- | :--- |
| `<shape>` | The input geometry, of type GEOMETRY or VARCHAR (in WKT format) that can be converted to GEOMETRY. Supports types such as `LINESTRING`, `POLYGON`, `CIRCLE`, `POINT`. |

## Return Value

Returns the length or perimeter of the geometry object, in meters (DOUBLE type).

`ST_LENGTH` has the following edge cases:
- If the input parameter is `NULL`, returns `NULL`.
- If the input parameter cannot be parsed into a valid geometry object, returns `NULL`.
- If the input geometry object is a `POINT` or a line of zero length, returns `0.0`.
- For the `CIRCLE` type, the radius parameter when created with `ST_CIRCLE` must be in meters to ensure the correct circumference (in meters) is returned.

## Example

**Calculate the Length of a Line (LINESTRING)**
```sql
-- Calculate the length of a line segment with a 1-degree longitude difference on the equator
SELECT ST_LENGTH(ST_GeometryFromText('LINESTRING(0 0, 1 0)'));
```
```text
+--------------------------------------------------------+
| ST_LENGTH(ST_GeometryFromText('LINESTRING(0 0, 1 0)')) |
+--------------------------------------------------------+
| 111195.1011774839 |
+--------------------------------------------------------+
```

**Calculate the Perimeter of a Polygon (POLYGON)**
```sql
-- Calculate the perimeter of a small square with a side length of approximately 0.0009 degrees (~100 meters)
SELECT ST_LENGTH(ST_GeometryFromText('POLYGON((-0.00045 -0.00045, 0.00045 -0.00045, 0.00045 0.00045, -0.00045 0.00045, -0.00045 -0.00045))')) AS perimeter;
```
```text
+-------------------+
| perimeter |
+-------------------+
| 400.3023642327689 |
+-------------------+
```

**Calculate the Circumference of a Circle (CIRCLE)**
```sql
-- Calculate the circumference of a circle with a radius of 100 meters
SELECT ST_LENGTH(ST_Circle(0, 0, 100));
```
```text
+---------------------------------+
| ST_LENGTH(ST_Circle(0, 0, 100)) |
+---------------------------------+
| 628.3185307179587 |
+---------------------------------+
```

**Length of a Point**
```sql
SELECT ST_LENGTH(ST_GeometryFromText('POINT(1 1)'));
```
```text
+----------------------------------------------+
| ST_LENGTH(ST_GeometryFromText('POINT(1 1)')) |
+----------------------------------------------+
| 0 |
+----------------------------------------------+
```

**Invalid Parameter (Returns NULL)**
```sql
SELECT ST_LENGTH('NOT_A_GEOMETRY');
```
```text
+-----------------------------+
| ST_LENGTH('NOT_A_GEOMETRY') |
+-----------------------------+
| NULL |
+-----------------------------+
```

**NULL Parameter**
```sql
SELECT ST_LENGTH(NULL);
```
```text
+-----------------+
| ST_LENGTH(NULL) |
+-----------------+
| NULL |
+-----------------+
```

**Length of a Complex Line Object**
```sql
-- Calculate the total length of a polyline
SELECT ST_LENGTH(ST_LineFromText("LINESTRING (0 0,1 0,1 1)"));
```
```text
+--------------------------------------------------------+
| ST_LENGTH(ST_LineFromText("LINESTRING (0 0,1 0,1 1)")) |
+--------------------------------------------------------+
| 222390.2023549679 |
+--------------------------------------------------------+
```
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ ST_ANGLE( <point1>, <point2>, <point3>)
|----------|--------------------------|
| `<point1>` | 第一条直线的第一个端点 ,类型为 `GeoPoint` |
| `<point2>` | 第一条直线的第二个端点且是第二条直线的第一个端点, 类型为 `GeoPoint` |
| `<point3>` | 第二条直线的第二个端点, 类型为 `GeoPint` |
| `<point3>` | 第二条直线的第二个端点, 类型为 `GeoPoint` |

## 返回值

Expand Down
Loading