From b6642fcb36db4663b8bfaca16707d384faa93030 Mon Sep 17 00:00:00 2001 From: Matthew Powers Date: Wed, 26 Nov 2025 07:36:27 -0500 Subject: [PATCH 1/7] docs: add version to current functions --- docs/reference/sql.md | 129 +++++++++++++++++++++++++++++++++++++++--- 1 file changed, 122 insertions(+), 7 deletions(-) diff --git a/docs/reference/sql.md b/docs/reference/sql.md index d8f451f0b..5624a7da7 100644 --- a/docs/reference/sql.md +++ b/docs/reference/sql.md @@ -23,19 +23,14 @@ The following SQL functions are available for SedonaDB. You can query data directly from files and URLs by treating them like database tables. This feature supports formats like **Parquet**, **CSV**, and **JSON**. -To query a file, place its path or URL in single quotes within the `FROM` clause. - -```python -# Query a remote Parquet file directly -"SELECT * FROM 'https://raw.githubusercontent.com/geoarrow/geoarrow-data/v0.2.0/natural-earth/files/natural-earth_cities_geo.parquet'").show() -``` - ## ST_Analyze_Aggr #### Description Return the statistics of geometries for the input geometry. +Since: v0.1. + #### Format `ST_Analyze_Aggr (A: Geometry)` @@ -56,6 +51,8 @@ SELECT ST_Analyze_Aggr(ST_GeomFromText('MULTIPOINT(1.1 101.1,2.1 102.1,3.1 103.1 Return the area of a geometry. +Since: v0.1. + #### Format `ST_Area (A: Geometry)` @@ -76,6 +73,8 @@ SELECT ST_Area(ST_GeomFromWKT('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))')); Return the Well-Known Binary representation of a geometry or geography. This function also has the alias **ST_AsWKB**. +Since: v0.1. + #### Format `ST_AsBinary (A: Geometry)` @@ -96,6 +95,8 @@ SELECT ST_AsBinary(ST_Point(1.0, 2.0)); Return the Well-Known Text string representation of a geometry or geography. +Since: v0.1. + #### Format `ST_AsText (A: Geometry)` @@ -116,6 +117,8 @@ SELECT ST_AsText(ST_Point(1.0, 2.0)) Returns a geometry that represents all points whose distance from the input geometry is less than or equal to a specified distance. +Since: v0.1. + #### Format `ST_Buffer (A: Geometry, distance: Double)` @@ -137,6 +140,8 @@ SELECT ST_Buffer(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), 1.0) Returns the centroid of geom. +Since: v0.1. + #### Format `ST_Centroid (A: Geometry)` @@ -157,6 +162,8 @@ SELECT ST_AsText(ST_Centroid(ST_GeomFromWKT('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 Aggregates a set of geometries into a single `GeometryCollection`, `MultiPoint`, `MultiLineString`, or `MultiPolygon`. If all input geometries are of the same type (e.g., all points), it creates a multi-geometry of that type. If the geometries are of mixed types, it returns a `GeometryCollection`. +Since: v0.1. + #### Format `ST_Collect (geom: Geometry)` @@ -177,6 +184,8 @@ SELECT ST_Collect(ST_GeomFromWKT('MULTIPOINT (0 1, 10 11)')) Return true if geomA contains geomB. +Since: v0.1. + #### Format `ST_Contains (A: Geometry, B: Geometry)` @@ -198,6 +207,8 @@ SELECT ST_Contains(ST_Point(0.25 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1 Return true if geomA is covered by geomB. +Since: v0.1. + #### Format `ST_CoveredBy (A: Geometry, B: Geometry)` @@ -219,6 +230,8 @@ SELECT ST_CoveredBy(ST_Point(0.25 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 Return true if geomA covers geomB. +Since: v0.1. + #### Format `ST_Covers (A: Geometry, B: Geometry)` @@ -240,6 +253,8 @@ SELECT ST_Covers(ST_Point(0.25 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, Computes the difference between geomA and geomB. +Since: v0.1. + #### Format `ST_Difference (A: Geometry, B: Geometry)` @@ -261,6 +276,8 @@ SELECT ST_Difference(ST_GeomFromText('POLYGON ((1 1, 11 1, 1 11, 0 0))'), ST_Geo Return the dimension of the geometry. +Since: v0.1. + #### Format `ST_Dimension (A: Geometry)` @@ -281,6 +298,8 @@ SELECT ST_Dimension(ST_GeomFromWKT('POLYGON ((0 0, 1 0, 0 1, 0 0))')); Return true if geomA is disjoint from geomB. +Since: v0.1. + #### Format `ST_Disjoint (A: Geometry, B: Geometry)` @@ -302,6 +321,8 @@ SELECT ST_Disjoint(ST_Point(0.25 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1 Calculates the distance between geomA and geomB. +Since: v0.1. + #### Format `ST_Distance (A: Geometry, B: Geometry)` @@ -323,6 +344,8 @@ SELECT ST_Distance(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), ST Calculates the spherical distance between geomA and geomB. +Since: v0.1. + #### Format `ST_DistanceSphere (A: Geometry, B: Geometry)` @@ -344,6 +367,8 @@ SELECT ST_DistanceSphere(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10)) Calculates the spheroidal (ellipsoidal) distance between geomA and geomB. +Since: v0.1. + #### Format `ST_DistanceSpheroid (A: Geometry, B: Geometry)` @@ -365,6 +390,8 @@ SELECT ST_DistanceSpheroid(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10 Returns true if two geometries are within a specified distance of each other. +Since: v0.1. + #### Format `ST_DWithin (A: Geometry, B: Geometry, distance: Double)` @@ -387,6 +414,8 @@ SELECT ST_DWithin(ST_Point(0.25, 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1 Returns the bounding box (envelope) of a geometry as a new geometry. The resulting geometry represents the minimum bounding rectangle that encloses the input geometry. Depending on the input, the output can be a `Point`, `LineString`, or `Polygon`. +Since: v0.1. + #### Format `ST_Envelope (A: Geometry)` @@ -407,6 +436,8 @@ SELECT ST_Envelope(ST_Point(1.0, 2.0)) An aggregate function that returns the collective bounding box (envelope) of a set of geometries. +Since: v0.1. + #### Format `ST_Envelope_Aggr (geom: Geometry)` @@ -433,6 +464,8 @@ SELECT ST_AsText(ST_Envelope_Aggr(geom)) FROM shapes; Return true if geomA equals geomB. +Since: v0.1. + #### Format `ST_Equals (A: Geometry, B: Geometry)` @@ -454,6 +487,8 @@ SELECT ST_Equals(ST_Point(0.25 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, Returns a new geometry with the X and Y coordinates of each vertex swapped. This is useful for correcting geometries that have been created with longitude and latitude in the wrong order. +Since: v0.1. + #### Format `ST_FlipCoordinates (A: geometry)` @@ -474,6 +509,8 @@ SELECT ST_FlipCoordinates(df.geometry) Calculates the Frechet distance between geomA and geomB. +Since: v0.1. + #### Format `ST_FrechetDistance (A: Geometry, B: Geometry)` @@ -495,6 +532,8 @@ SELECT ST_FrechetDistance(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10) Construct a Geometry from WKB. +Since: v0.1. + #### Format `ST_GeomFromWKB (Wkb: Binary)` @@ -516,6 +555,8 @@ SELECT ST_AsText(ST_GeomFromWKB(FROM_HEX('0101000000000000000000F03F000000000000 Construct a Geometry from WKT. This function also has the alias **ST_GeomFromText**. +Since: v0.1. + #### Format `ST_GeomFromWKT (Wkt: String)` @@ -536,6 +577,8 @@ SELECT ST_AsText(ST_GeomFromWKT('POINT (30 10)')); Return the type of a geometry. +Since: v0.1. + #### Format `ST_GeometryType (A: Geometry)` @@ -556,6 +599,8 @@ SELECT ST_GeometryType(ST_GeomFromWKT('POLYGON ((0 0, 1 0, 0 1, 0 0))')) Return true if the geometry has a M dimension. +Since: v0.1. + #### Format `ST_HasM (A: Geometry)` @@ -576,6 +621,8 @@ SELECT ST_HasM(ST_GeomFromWKT('POLYGON ((0 0, 1 0, 0 1, 0 0))')) Return true if the geometry has a Z dimension. +Since: v0.1. + #### Format `ST_HasZ (A: Geometry)` @@ -596,6 +643,8 @@ SELECT ST_HasZ(ST_GeomFromWKT('POLYGON ((0 0, 1 0, 0 1, 0 0))')) Calculates the Hausdorff distance between geomA and geomB. +Since: v0.1. + #### Format `ST_HausdorffDistance (A: Geometry, B: Geometry)` @@ -617,6 +666,8 @@ SELECT ST_HausdorffDistance(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 1 Computes the intersection between geomA and geomB. +Since: v0.1. + #### Format `ST_Intersection (A: Geometry, B: Geometry)` @@ -638,6 +689,8 @@ SELECT ST_Intersection(ST_GeomFromText('POLYGON ((1 1, 11 1, 1 11, 0 0))'), ST_G An aggregate function that returns the geometric intersection of all geometries in a set. +Since: v0.1. + #### Format `ST_Intersection_Aggr (geom: Geometry)` @@ -664,6 +717,8 @@ SELECT ST_AsText(ST_Intersection_Aggr(geom)) FROM shapes; Return true if geomA intersects geomB. +Since: v0.1. + #### Format `ST_Intersects (A: Geometry, B: Geometry)` @@ -685,6 +740,8 @@ SELECT ST_Intersects(ST_Point(0.25 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 Return true if the geometry is empty. +Since: v0.1. + #### Format `ST_IsEmpty (A: Geometry)` @@ -705,6 +762,8 @@ SELECT ST_IsEmpty(ST_GeomFromWKT('POLYGON EMPTY')); Return true if geomA finds k nearest neighbors from geomB. +Since: v0.1. + #### Format `ST_KNN (A: Geometry, B: Geometry, k: Integer, use_spheroid: Boolean)` @@ -728,6 +787,8 @@ SELECT * FROM table1 a JOIN table2 b ON ST_KNN(a.geom, b.geom, 5, false) Returns the length of geom. This function only supports LineString, MultiLineString, and GeometryCollections containing linear geometries. Use ST_Perimeter for polygons. +Since: v0.1. + #### Format `ST_Length (A: Geometry)` @@ -748,6 +809,8 @@ SELECT ST_Length(ST_GeomFromWKT('LINESTRING(0 0, 10 0)')); Returns the M (measure) coordinate of a `Point` geometry. If the geometry does not have an M value, it returns `NULL`. +Since: v0.1. + #### Format `ST_M (A: Point)` @@ -768,6 +831,8 @@ SELECT ST_M(ST_Point(1.0, 2.0)) Creates a `LineString` from two or more input `Point`, `MultiPoint`, or `LineString` geometries. The function connects the input geometries in the order they are provided to form a single continuous line. +Since: v0.1. + #### Format `ST_MakeLine (g1: Geometry or Geography, g2: Geometry or Geography)` @@ -789,6 +854,8 @@ SELECT ST_MakeLine(ST_Point(0, 1), ST_Point(2, 3)) as geom Calculates the maximum distance between geomA and geomB. +Since: v0.1. + #### Format `ST_MaxDistance (A: Geometry, B: Geometry)` @@ -810,6 +877,8 @@ SELECT ST_MaxDistance(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), Returns the maximum M (measure) value from a geometry's bounding box. +Since: v0.1. + #### Format `ST_MMax (A: Geometry)` @@ -830,6 +899,8 @@ SELECT ST_MMax(ST_GeomFromWKT('POLYGON ((0 0, 1 0, 0 1, 0 0))')) Returns the minimum **M-coordinate** (measure) of a geometry's bounding box. +Since: v0.1. + #### Format `ST_MMin (A: Geometry)` @@ -853,6 +924,8 @@ This function calculates the 2D perimeter of a given geometry. It supports Polyg To get the perimeter in meters, set **use_spheroid** to true. This calculates the geodesic perimeter using the WGS84 spheroid. When using use_spheroid, the **lenient** parameter defaults to true, assuming the geometry uses EPSG:4326. To throw an exception instead, set lenient to false. +Since: v0.1. + #### Format `ST_Perimeter(geom: Geometry)` @@ -877,6 +950,8 @@ SELECT ST_Perimeter(ST_GeomFromWKT('POLYGON((0 0, 10 0, 10 10, 0 10, 0 0))')); Construct a Point Geometry from X and Y. +Since: v0.1. + #### Format `ST_Point (x: Double, y: Double)` @@ -898,6 +973,8 @@ SELECT ST_AsText(ST_Point(-74.0060, 40.7128)); Constructs a `Point` with an M (measure) coordinate from X, Y, and M values. +Since: v0.1. + #### Format `ST_PointM (x: Double, y: Double, m: Double)` @@ -920,6 +997,8 @@ SELECT ST_PointM(-64.36, 45.09, 50.0) Constructs a `Point` with a Z (elevation) coordinate from X, Y, and Z values. +Since: v0.1. + #### Format `ST_PointZ (x: Double, y: Double, z: Double)` @@ -942,6 +1021,8 @@ SELECT ST_PointZ(-64.36, 45.09, 100.0) Constructs a `Point` with both Z (elevation) and M (measure) coordinates from X, Y, Z, and M values. +Since: v0.1. + #### Format `ST_PointZM (x: Double, y: Double, z: Double, m: Double)` @@ -965,6 +1046,8 @@ SELECT ST_PointZM(-64.36, 45.09, 100.0, 50.0) Sets the spatial reference system identifier (SRID) of a geometry. This only changes the metadata; it does not transform the coordinates. +Since: v0.1. + #### Format `ST_SetSRID (geom: Geometry, srid: Integer)` @@ -986,6 +1069,8 @@ SELECT ST_SetSRID(ST_GeomFromWKT('POINT (-64.363049 45.091501)'), 4326); Returns the Spatial Reference System Identifier (SRID) of a geometry. If the geometry does not have an SRID, it returns 0. +Since: v0.1. + #### Format `ST_SRID (geom: Geometry)` @@ -1006,6 +1091,8 @@ SELECT ST_SRID(polygon) Computes the symmetric difference between geomA and geomB. +Since: v0.1. + #### Format `ST_SymDifference (A: Geometry, B: Geometry)` @@ -1027,6 +1114,8 @@ SELECT ST_SymDifference(ST_GeomFromText('POLYGON ((1 1, 11 1, 1 11, 0 0))'), ST_ Return true if geomA touches geomB. +Since: v0.1. + #### Format `ST_Touches (A: Geometry, B: Geometry)` @@ -1050,6 +1139,8 @@ Transforms the coordinates of a geometry from a source Coordinate Reference Syst If the source CRS is not specified, it will be read from the geometry's metadata. Sedona ensures that coordinates are handled in longitude/latitude order for geographic CRS transformations. +Since: v0.1. + #### Format `ST_Transform (A: Geometry, TargetCRS: String)` @@ -1075,6 +1166,8 @@ SELECT ST_Transform(ST_SetSRID(ST_GeomFromWkt('POLYGON((170 50,170 72,-130 72,-1 Computes the union between geomA and geomB. +Since: v0.1. + #### Format `ST_Union (A: Geometry, B: Geometry)` @@ -1096,6 +1189,8 @@ SELECT ST_Union(ST_GeomFromText('POLYGON ((1 1, 11 1, 1 11, 0 0))'), ST_GeomFrom An aggregate function that returns the geometric union of all geometries in a set. +Since: v0.1. + #### Format `ST_Union_Aggr (geom: Geometry)` @@ -1122,6 +1217,8 @@ SELECT ST_AsText(ST_Union_Aggr(geom)) FROM shapes; Return true if geomA is fully contained by geomB. +Since: v0.1. + #### Format `ST_Within (A: Geometry, B: Geometry)` @@ -1143,6 +1240,8 @@ SELECT ST_Within(ST_Point(0.25 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, Return the X component of a point geometry or geography. +Since: v0.1. + #### Format `ST_X(A: Point)` @@ -1163,6 +1262,8 @@ SELECT ST_X(ST_Point(1.0, 2.0)) Returns the maximum **X-coordinate** of a geometry's bounding box. +Since: v0.1. + #### Format `ST_XMax (A: Geometry)` @@ -1184,6 +1285,8 @@ SELECT ST_XMax(ST_GeomFromWKT('LINESTRING(1 5, 10 15)')); Returns the minimum **X-coordinate** of a geometry's bounding box. +Since: v0.1. + #### Format `ST_XMin (A: Geometry)` @@ -1205,6 +1308,8 @@ SELECT ST_XMin(ST_GeomFromWKT('LINESTRING(1 5, 10 15)')); Return the Y component of a point geometry or geography. +Since: v0.1. + #### Format `ST_Y(A: Point)` @@ -1225,6 +1330,8 @@ SELECT ST_Y(ST_Point(1.0, 2.0)) Returns the maximum **Y-coordinate** of a geometry's bounding box. +Since: v0.1. + #### Format `ST_YMax (A: Geometry)` @@ -1246,6 +1353,8 @@ SELECT ST_YMax(ST_GeomFromWKT('LINESTRING(1 5, 10 15)')); Returns the minimum **Y-coordinate** of a geometry's bounding box. +Since: v0.1. + #### Format `ST_YMin (A: Geometry)` @@ -1267,6 +1376,8 @@ SELECT ST_YMin(ST_GeomFromWKT('LINESTRING(1 5, 10 15)')); Return the Z component of a point geometry or geography. +Since: v0.1. + #### Format `ST_Z(A: Point)` @@ -1287,6 +1398,8 @@ SELECT ST_Z(ST_Point(1.0, 2.0)) Returns the maximum **Z-coordinate** of a geometry's bounding box. +Since: v0.1. + #### Format `ST_ZMax (A: Geometry)` @@ -1308,6 +1421,8 @@ SELECT ST_ZMax(ST_GeomFromWKT('LINESTRING ZM (1 2 3 4, 5 6 7 8)')); Returns the minimum **Z-coordinate** of a geometry's bounding box. +Since: v0.1. + #### Format `ST_ZMin (A: Geometry)` From f3be0fb210313ef1997a12a97e99ca73a0c1dffc Mon Sep 17 00:00:00 2001 From: Matthew Powers Date: Wed, 26 Nov 2025 10:18:06 -0500 Subject: [PATCH 2/7] docs: add v0.2 sql functions --- docs/reference/sql.md | 472 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 472 insertions(+) diff --git a/docs/reference/sql.md b/docs/reference/sql.md index 5624a7da7..e86dbd392 100644 --- a/docs/reference/sql.md +++ b/docs/reference/sql.md @@ -111,6 +111,30 @@ Since: v0.1. SELECT ST_AsText(ST_Point(1.0, 2.0)) ``` +## ST_Azimuth + +Introduction: Returns Azimuth for two given points in radians null otherwise. + +Format: ST_Azimuth(pointA: Point, pointB: Point) + +Since: v0.2. + +```sql +SELECT ST_Azimuth(ST_POINT(0.0, 25.0), ST_POINT(0.0, 0.0)) +``` + +## ST_Boundary + +Returns the closure of the combinatorial boundary of this Geometry. + +Format: `ST_Boundary(geom: Geometry)` + +Since: v0.2. + +```sql +SELECT ST_Boundary(ST_GeomFromWKT('POLYGON((1 1,0 0, -1 1, 1 1))')) +``` + ## ST_Buffer #### Description @@ -156,6 +180,18 @@ Since: v0.1. SELECT ST_AsText(ST_Centroid(ST_GeomFromWKT('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))'))); ``` +## ST_ClosestPoint + +Returns the 2-dimensional point on geom1 that is closest to geom2. This is the first point of the shortest line between the geometries. If using 3D geometries, the Z coordinates will be ignored. If you have a 3D Geometry, you may prefer to use ST_3DClosestPoint. It will throw an exception indicates illegal argument if one of the params is an empty geometry. + +Format: `ST_ClosestPoint(g1: Geometry, g2: Geometry)` + +Since: v0.2. + +```sql +SELECT ST_AsText( ST_ClosestPoint(g1, g2)) As ptwkt; +``` + ## ST_Collect #### Description @@ -201,6 +237,18 @@ Since: v0.1. SELECT ST_Contains(ST_Point(0.25 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val ``` +## ST_ConvexHull + +Return the Convex Hull of polygon A + +Format: `ST_ConvexHull (A: Geometry)` + +Since: v0.2. + +```sql +SELECT ST_ConvexHull(ST_GeomFromText('POLYGON((175 150, 20 40, 50 60, 125 100, 175 150))')) +``` + ## ST_CoveredBy #### Description @@ -247,6 +295,22 @@ Since: v0.1. SELECT ST_Covers(ST_Point(0.25 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val ``` +## ST_Crosses + +Introduction: Return true if A crosses B + +Format: `ST_Crosses (A: Geometry, B: Geometry)` + +Since: v0.2. + +```sql +SELECT ST_Crosses(ST_GeomFromWKT('POLYGON((1 1, 4 1, 4 4, 1 4, 1 1))'),ST_GeomFromWKT('POLYGON((2 2, 5 2, 5 5, 2 5, 2 2))')) +``` + +## ST_CRS + +TODO + ## ST_Difference #### Description @@ -384,6 +448,18 @@ Since: v0.1. SELECT ST_DistanceSpheroid(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val ``` +## ST_Dump + +It expands the geometries. If the geometry is simple (Point, Polygon Linestring etc.) it returns the geometry itself, if the geometry is collection or multi it returns record for each of collection components. + +Format: ST_Dump(geom: Geometry) + +Since: v0.2. + +```sql +SELECT ST_Dump(ST_GeomFromText('MULTIPOINT ((10 40), (40 30), (20 20), (30 10))')) +``` + ## ST_DWithin #### Description @@ -408,6 +484,18 @@ Since: v0.1. SELECT ST_DWithin(ST_Point(0.25, 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))'), 0.5); ``` +## ST_EndPoint + +Returns last point of given linestring. + +Format: `ST_EndPoint(geom: Geometry)` + +Since: v0.2. + +```sql +SELECT ST_EndPoint(ST_GeomFromText('LINESTRING(100 150,50 60, 70 80, 160 170)')) +``` + ## ST_Envelope #### Description @@ -526,6 +614,50 @@ Since: v0.1. SELECT ST_FrechetDistance(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val ``` +## ST_GeogPoint + +TODO + +## ST_GeogFromWKB + +Construct a Geography from WKB Binary. + +Format: `ST_GeogFromWKB (Wkb: Binary)` + +Since: v0.2. + +```sql +SELECT ST_GeogFromWKB([01 02 00 00 00 02 00 00 00 00 00 00 00 84 d6 00 c0 00 00 00 00 80 b5 d6 bf 00 00 00 60 e1 ef f7 bf 00 00 00 80 07 5d e5 bf]) +``` + +## ST_GeogFromWKT + +Construct a Geography from WKT. If SRID is not set, it defaults to 0 (unknown). + +Format: `ST_GeogFromWKT (Wkt: String)` + +or + +`ST_GeogFromWKT (Wkt: String, srid: Integer)` + +Since: v0.2. + +```sql +SELECT ST_GeogFromWKT('LINESTRING (1 2, 3 4, 5 6)') +``` + +## ST_GeometryN + +Return the 0-based Nth geometry if the geometry is a GEOMETRYCOLLECTION, (MULTI)POINT, (MULTI)LINESTRING, MULTICURVE or (MULTI)POLYGON. Otherwise, return null + +Format: ST_GeometryN(geom: Geometry, n: Integer) + +Since: v0.2. + +```sql +SELECT ST_GeometryN(ST_GeomFromText('MULTIPOINT((1 2), (3 4), (5 6), (8 9))'), 1) +``` + ## ST_GeomFromWKB #### Description @@ -734,6 +866,39 @@ Since: v0.1. SELECT ST_Intersects(ST_Point(0.25 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val ``` +## ST_IsClosed + +RETURNS true if the LINESTRING start and end point are the same. + +Format: `ST_IsClosed(geom: Geometry)` + +Since: v0.2. + +```sql +SELECT ST_IsClosed(ST_GeomFromText('LINESTRING(0 0, 1 1, 1 0)')) +``` + +## ST_IsCollection + +Returns TRUE if the geometry type of the input is a geometry collection type. Collection types are the following: + +```sql +GEOMETRYCOLLECTION +MULTI{POINT, POLYGON, LINESTRING} +``` + +Format: `ST_IsCollection(geom: Geometry)` + +Since: v0.2. + +```sql +SELECT ST_IsCollection(ST_GeomFromText('MULTIPOINT(0 0), (6 6)')) +``` + +```sql +SELECT ST_IsCollection(ST_GeomFromText('POINT(5 5)')) +``` + ## ST_IsEmpty #### Description @@ -756,6 +921,38 @@ Since: v0.1. SELECT ST_IsEmpty(ST_GeomFromWKT('POLYGON EMPTY')); ``` +## ST_IsRing + +RETURN true if LINESTRING is ST_IsClosed and ST_IsSimple. + +Format: `ST_IsRing(geom: Geometry)` + +Since: v0.2. + +```sql +SELECT ST_IsRing(ST_GeomFromText("LINESTRING(0 0, 0 1, 1 1, 1 0, 0 0)")) +``` + +## ST_IsSimple + +Test if geometry's only self-intersections are at boundary points. + +Format: `ST_IsSimple (A: Geometry)` + +Since: v0.2. + +```sql +SELECT ST_IsSimple(ST_GeomFromWKT('POLYGON((1 1, 3 1, 3 3, 1 3, 1 1))')) +``` + +## ST_IsValid + +TODO + +## ST_IsValidReason + +TODO + ## ST_KNN #### Description @@ -803,6 +1000,30 @@ Since: v0.1. SELECT ST_Length(ST_GeomFromWKT('LINESTRING(0 0, 10 0)')); ``` +## ST_LineInterpolatePoint + +Returns a point interpolated along a line. First argument must be a LINESTRING. Second argument is a Double between 0 and 1 representing fraction of total linestring length the point has to be located. + +Format: `ST_LineInterpolatePoint (geom: Geometry, fraction: Double)` + +Since: v0.2. + +```sql +SELECT ST_LineInterpolatePoint(ST_GeomFromWKT('LINESTRING(25 50, 100 125, 150 190)'), 0.2) +``` + +## ST_LineLocatePoint + +Returns a double between 0 and 1, representing the location of the closest point on the LineString as a fraction of its total length. The first argument must be a LINESTRING, and the second argument is a POINT geometry. + +Format: `ST_LineLocatePoint(linestring: Geometry, point: Geometry)` + +Since: v0.2. + +```sql +SELECT ST_LineLocatePoint(ST_GeomFromWKT('LINESTRING(0 0, 1 1, 2 2)'), ST_GeomFromWKT('POINT(0 2)')) +``` + ## ST_M #### Description @@ -848,6 +1069,27 @@ Since: v0.1. SELECT ST_MakeLine(ST_Point(0, 1), ST_Point(2, 3)) as geom ``` +## ST_MakeValid + +Given an invalid geometry, create a valid representation of the geometry. + +Collapsed geometries are either converted to empty (keepCollapsed=false) or a valid geometry of lower dimension (keepCollapsed=true). Default is keepCollapsed=false. + +Format: + +``` +ST_MakeValid (A: Geometry) +ST_MakeValid (A: Geometry, keepCollapsed: Boolean) +``` + +Since: v0.2. + +```sql +WITH linestring AS ( + SELECT ST_GeomFromWKT('LINESTRING(1 1, 1 1)') AS geom +) SELECT ST_MakeValid(geom), ST_MakeValid(geom, true) FROM linestring +``` + ## ST_MaxDistance #### Description @@ -871,6 +1113,42 @@ Since: v0.1. SELECT ST_MaxDistance(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val ``` +## ST_MinimumClearance + +The minimum clearance is a metric that quantifies a geometry's tolerance to changes in coordinate precision or vertex positions. It represents the maximum distance by which vertices can be adjusted without introducing invalidity to the geometry's structure. A larger minimum clearance value indicates greater robustness against such perturbations. + +For a geometry with a minimum clearance of x, the following conditions hold: + +No two distinct vertices are separated by a distance less than x. + +No vertex lies within a distance x from any line segment it is not an endpoint of. + +For geometries with no definable minimum clearance, such as single Point geometries or MultiPoint geometries where all points occupy the same location, the function returns Double.MAX_VALUE. + +Format: `ST_MinimumClearance(geometry: Geometry)` + +Since: v0.2. + +```sql +SELECT ST_MinimumClearance( + ST_GeomFromWKT('POLYGON ((65 18, 62 16, 64.5 16, 62 14, 65 14, 65 18))') +) +``` + +## ST_MinimumClearanceLine + +This function returns a two-point LineString geometry representing the minimum clearance distance of the input geometry. If the input geometry does not have a defined minimum clearance, such as for single Points or coincident MultiPoints, an empty LineString geometry is returned instead. + +Format: `ST_MinimumClearanceLine(geometry: Geometry)` + +Since: v0.2. + +```sql +SELECT ST_MinimumClearanceLine( + ST_GeomFromWKT('POLYGON ((65 18, 62 16, 64.5 16, 62 14, 65 14, 65 18))') +) +``` + ## ST_MMax #### Description @@ -916,6 +1194,42 @@ SELECT ST_MMin(ST_GeomFromWKT('LINESTRING ZM (1 2 3 4, 5 6 7 8)')); -- Returns: 4 ``` +## ST_NPoints + +Return points of the geometry + +Format: `ST_NPoints (A: Geometry)` + +Since: v0.2. + +```sql +SELECT ST_NPoints(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)')) +``` + +## ST_NumGeometries + +Returns the number of Geometries. If geometry is a GEOMETRYCOLLECTION (or MULTI*) return the number of geometries, for single geometries will return 1. + +Format: `ST_NumGeometries (A: Geometry)` + +Since: v0.2. + +```sql +SELECT ST_NumGeometries(ST_GeomFromWKT('LINESTRING (-29 -27, -30 -29.7, -45 -33)')) +``` + +## ST_Overlaps + +Return true if A overlaps B + +Format: `ST_Overlaps (A: Geometry, B: Geometry)` + +Since: v0.2. + +```sql +SELECT ST_Overlaps(ST_GeomFromWKT('POLYGON((2.5 2.5, 2.5 4.5, 4.5 4.5, 4.5 2.5, 2.5 2.5))'), ST_GeomFromWKT('POLYGON((4 4, 4 6, 6 6, 6 4, 4 4))')) +``` + ## ST_Perimeter #### Description @@ -991,6 +1305,30 @@ Since: v0.1. SELECT ST_PointM(-64.36, 45.09, 50.0) ``` +## ST_PointN + +Return the Nth point in a single linestring or circular linestring in the geometry. Negative values are counted backwards from the end of the LineString, so that -1 is the last point. Returns NULL if there is no linestring in the geometry. + +Format: `ST_PointN(geom: Geometry, n: Integer)` + +Since: v0.2. + +```sql +SELECT ST_PointN(ST_GeomFromText("LINESTRING(0 0, 1 2, 2 4, 3 6)"), 2) +``` + +## ST_Points + +Returns a MultiPoint geometry consisting of all the coordinates of the input geometry. It preserves duplicate points as well as M and Z coordinates. + +Format: `ST_Points(geom: Geometry)` + +Since: v0.2. + +```sql +SELECT ST_AsText(ST_Points(ST_GeomFromEWKT('LINESTRING (2 4, 3 3, 4 2, 7 3)'))); +``` + ## ST_PointZ #### Description @@ -1040,6 +1378,84 @@ Since: v0.1. SELECT ST_PointZM(-64.36, 45.09, 100.0, 50.0) ``` +## ST_Polygonize + +Generates a GeometryCollection composed of polygons that are formed from the linework of an input GeometryCollection. When the input does not contain any linework that forms a polygon, the function will return an empty GeometryCollection. + +Note that ST_Polygonize function assumes that the input geometries form a valid and simple closed linestring that can be turned into a polygon. If the input geometries are not noded or do not form such linestrings, the resulting GeometryCollection may be empty or may not contain the expected polygons. + +Format: `ST_Polygonize(geom: Geometry)` + +Since: v0.2. + +```sql +SELECT ST_AsText(ST_Polygonize(ST_GeomFromEWKT('GEOMETRYCOLLECTION (LINESTRING (2 0, 2 1, 2 2), LINESTRING (2 2, 2 3, 2 4), LINESTRING (0 2, 1 2, 2 2), LINESTRING (2 2, 3 2, 4 2), LINESTRING (0 2, 1 3, 2 4), LINESTRING (2 4, 3 3, 4 2))'))); +``` + +## ST_Reverse + +Return the geometry with vertex order reversed + +Format: `ST_Reverse (A: Geometry)` + +Since: v0.2. + +```sql +SELECT ST_Reverse(ST_GeomFromWKT('LINESTRING(0 0, 1 2, 2 4, 3 6)')) +``` + +## ST_SetCRS + +TODO + +## ST_ShortestLine + +TODO + +## ST_Simplify + +This function simplifies the input geometry by applying the Douglas-Peucker algorithm. + +Note: The simplification may not preserve topology, potentially producing invalid geometries. Use ST_SimplifyPreserveTopology to retain valid topology after simplification. + +Format: `ST_Simplify(geom: Geometry, tolerance: Double)` + +Since: v0.2. + +```sql +SELECT ST_Simplify(ST_Buffer(ST_GeomFromWKT('POINT (0 2)'), 10), 1) +``` + +## ST_SimplifyPreserveTopology + +Simplifies a geometry and ensures that the result is a valid geometry having the same dimension and number of components as the input, and with the components having the same topological relationship. + +Since: v0.2. + +Format: `ST_SimplifyPreserveTopology (A: Geometry, distanceTolerance: Double)` + +```sql +SELECT ST_SimplifyPreserveTopology(ST_GeomFromText('POLYGON((8 25, 28 22, 28 20, 15 11, 33 3, 56 30, 46 33,46 34, 47 44, 35 36, 45 33, 43 19, 29 21, 29 22,35 26, 24 39, 8 25))'), 10) +``` + +## ST_Snap + +Snaps the vertices and segments of the input geometry to reference geometry within the specified tolerance distance. The tolerance parameter controls the maximum snap distance. + +If the minimum distance between the geometries exceeds the tolerance, the input geometry is returned unmodified. Adjusting the tolerance value allows tuning which vertices should snap to the reference and which remain untouched. + +Since: v0.2. + +Format: `ST_Snap(input: Geometry, reference: Geometry, tolerance: double)` + +```sql +SELECT + ST_Snap(poly, line, ST_Distance(poly, line) * 1.01) AS polySnapped FROM ( + SELECT ST_GeomFromWKT('POLYGON ((236877.58 -6.61, 236878.29 -8.35, 236879.98 -8.33, 236879.72 -7.63, 236880.35 -6.62, 236877.58 -6.61), (236878.45 -7.01, 236878.43 -7.52, 236879.29 -7.50, 236878.63 -7.22, 236878.76 -6.89, 236878.45 -7.01))') as poly, + ST_GeomFromWKT('LINESTRING (236880.53 -8.22, 236881.15 -7.68, 236880.69 -6.81)') as line +) +``` + ## ST_SetSRID #### Description @@ -1085,6 +1501,18 @@ Since: v0.1. SELECT ST_SRID(polygon) ``` +## ST_StartPoint + +Returns first point of given linestring. + +Format: `ST_StartPoint(geom: Geometry)` + +Since: v0.2. + +```sql +SELECT ST_StartPoint(ST_GeomFromText('LINESTRING(100 150,50 60, 70 80, 160 170)')) +``` + ## ST_SymDifference #### Description @@ -1160,6 +1588,34 @@ Since: v0.1. SELECT ST_Transform(ST_SetSRID(ST_GeomFromWkt('POLYGON((170 50,170 72,-130 72,-130 50,170 50))'), 4326), 'EPSG:32649'); ``` +## ST_Translate + +Returns the input geometry with its X, Y and Z coordinates (if present in the geometry) translated by deltaX, deltaY and deltaZ (if specified) + +If the geometry is 2D, and a deltaZ parameter is specified, no change is done to the Z coordinate of the geometry and the resultant geometry is also 2D. + +If the geometry is empty, no change is done to it. If the given geometry contains sub-geometries (GEOMETRY COLLECTION, MULTI POLYGON/LINE/POINT), all underlying geometries are individually translated. + +Format: `ST_Translate(geometry: Geometry, deltaX: Double, deltaY: Double, deltaZ: Double)` + +Since: v0.2. + +```sql +SELECT ST_Translate(ST_GeomFromText('POINT(-71.01 42.37)'), 1, 2) +``` + +## vST_UnaryUnion + +This variant of ST_Union operates on a single geometry input. The input geometry can be a simple Geometry type, a MultiGeometry, or a GeometryCollection. The function calculates the geometric union across all components and elements within the provided geometry object. + +Format: `ST_UnaryUnion(geometry: Geometry)` + +Since: v0.2. + +```sql +SELECT ST_UnaryUnion(ST_GeomFromWKT('MULTIPOLYGON(((0 10,0 30,20 30,20 10,0 10)),((10 0,10 20,30 20,30 0,10 0)))')) +``` + ## ST_Union #### Description @@ -1437,3 +1893,19 @@ Since: v0.1. SELECT ST_ZMin(ST_GeomFromWKT('LINESTRING ZM (1 2 3 4, 5 6 7 8)')); -- Returns: 3 ``` + +## ST_Zmflag + +Returns a code indicating the Z and M coordinate dimensions present in the input geometry. + +Values are: 0 = 2D, 1 = 3D-M, 2 = 3D-Z, 3 = 4D. + +Format: `ST_Zmflag(geom: Geometry)` + +Since: v0.2. + +```sql +SELECT ST_Zmflag( + ST_GeomFromWKT('LINESTRING Z(1 2 3, 4 5 6)') +) +``` From c27330ec1f364f24176aaa61e85423453c9acffb Mon Sep 17 00:00:00 2001 From: Matthew Powers Date: Fri, 28 Nov 2025 09:10:38 -0500 Subject: [PATCH 3/7] rename some aggregate functions --- docs/reference/sql.md | 68 +++++++++++++++++++++++-------------------- 1 file changed, 36 insertions(+), 32 deletions(-) diff --git a/docs/reference/sql.md b/docs/reference/sql.md index e86dbd392..49474eaf6 100644 --- a/docs/reference/sql.md +++ b/docs/reference/sql.md @@ -19,11 +19,7 @@ # SQL API Reference -The following SQL functions are available for SedonaDB. - -You can query data directly from files and URLs by treating them like database tables. This feature supports formats like **Parquet**, **CSV**, and **JSON**. - -## ST_Analyze_Aggr +## ST_Analyze_Agg #### Description @@ -33,7 +29,7 @@ Since: v0.1. #### Format -`ST_Analyze_Aggr (A: Geometry)` +`ST_Analyze_Agg (A: Geometry)` #### Arguments @@ -42,7 +38,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_Analyze_Aggr(ST_GeomFromText('MULTIPOINT(1.1 101.1,2.1 102.1,3.1 103.1,4.1 104.1,5.1 105.1,6.1 106.1,7.1 107.1,8.1 108.1,9.1 109.1,10.1 110.1)')) +SELECT ST_Analyze_Agg(ST_GeomFromText('MULTIPOINT(1.1 101.1,2.1 102.1,3.1 103.1,4.1 104.1,5.1 105.1,6.1 106.1,7.1 107.1,8.1 108.1,9.1 109.1,10.1 110.1)')); ``` ## ST_Area @@ -108,7 +104,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_AsText(ST_Point(1.0, 2.0)) +SELECT ST_AsText(ST_Point(1.0, 2.0)); ``` ## ST_Azimuth @@ -120,7 +116,7 @@ Format: ST_Azimuth(pointA: Point, pointB: Point) Since: v0.2. ```sql -SELECT ST_Azimuth(ST_POINT(0.0, 25.0), ST_POINT(0.0, 0.0)) +SELECT ST_Azimuth(ST_POINT(0.0, 25.0), ST_POINT(0.0, 0.0)); ``` ## ST_Boundary @@ -132,7 +128,7 @@ Format: `ST_Boundary(geom: Geometry)` Since: v0.2. ```sql -SELECT ST_Boundary(ST_GeomFromWKT('POLYGON((1 1,0 0, -1 1, 1 1))')) +SELECT ST_Boundary(ST_GeomFromWKT('POLYGON((1 1,0 0, -1 1, 1 1))')); ``` ## ST_Buffer @@ -189,7 +185,7 @@ Format: `ST_ClosestPoint(g1: Geometry, g2: Geometry)` Since: v0.2. ```sql -SELECT ST_AsText( ST_ClosestPoint(g1, g2)) As ptwkt; +SELECT ST_AsText(ST_ClosestPoint(g1, g2)) As ptwkt; ``` ## ST_Collect @@ -211,9 +207,13 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_Collect(ST_GeomFromWKT('MULTIPOINT (0 1, 10 11)')) +SELECT ST_Collect(ST_GeomFromWKT('MULTIPOINT (0 1, 10 11)')); ``` +## ST_Collect_Agg + +TODO + ## ST_Contains #### Description @@ -234,7 +234,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_Contains(ST_Point(0.25 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val +SELECT ST_Contains(ST_Point(0.25 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val; ``` ## ST_ConvexHull @@ -246,7 +246,7 @@ Format: `ST_ConvexHull (A: Geometry)` Since: v0.2. ```sql -SELECT ST_ConvexHull(ST_GeomFromText('POLYGON((175 150, 20 40, 50 60, 125 100, 175 150))')) +SELECT ST_ConvexHull(ST_GeomFromText('POLYGON((175 150, 20 40, 50 60, 125 100, 175 150))')); ``` ## ST_CoveredBy @@ -269,7 +269,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_CoveredBy(ST_Point(0.25 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val +SELECT ST_CoveredBy(ST_Point(0.25 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')); ``` ## ST_Covers @@ -304,7 +304,7 @@ Format: `ST_Crosses (A: Geometry, B: Geometry)` Since: v0.2. ```sql -SELECT ST_Crosses(ST_GeomFromWKT('POLYGON((1 1, 4 1, 4 4, 1 4, 1 1))'),ST_GeomFromWKT('POLYGON((2 2, 5 2, 5 5, 2 5, 2 2))')) +SELECT ST_Crosses(ST_GeomFromWKT('POLYGON((1 1, 4 1, 4 4, 1 4, 1 1))'),ST_GeomFromWKT('POLYGON((2 2, 5 2, 5 5, 2 5, 2 2))')); ``` ## ST_CRS @@ -331,7 +331,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_Difference(ST_GeomFromText('POLYGON ((1 1, 11 1, 1 11, 0 0))'), ST_GeomFromText('POLYGON ((0 0, 10 0, 0 10, 0 0))')) AS val +SELECT ST_Difference(ST_GeomFromText('POLYGON ((1 1, 11 1, 1 11, 0 0))'), ST_GeomFromText('POLYGON ((0 0, 10 0, 0 10, 0 0))')) AS val; ``` ## ST_Dimension @@ -518,7 +518,7 @@ Since: v0.1. SELECT ST_Envelope(ST_Point(1.0, 2.0)) ``` -## ST_Envelope_Aggr +## ST_Envelope_Agg #### Description @@ -528,7 +528,7 @@ Since: v0.1. #### Format -`ST_Envelope_Aggr (geom: Geometry)` +`ST_Envelope_Agg (geom: Geometry)` #### Arguments @@ -542,7 +542,7 @@ WITH shapes(geom) AS ( VALUES (ST_GeomFromWKT('POINT (0 1)')), (ST_GeomFromWKT('POINT (10 11)')) ) -SELECT ST_AsText(ST_Envelope_Aggr(geom)) FROM shapes; +SELECT ST_AsText(ST_Envelope_Agg(geom)) FROM shapes; -- Returns: POLYGON ((0 1, 0 11, 10 11, 10 1, 0 1)) ``` @@ -655,7 +655,7 @@ Format: ST_GeometryN(geom: Geometry, n: Integer) Since: v0.2. ```sql -SELECT ST_GeometryN(ST_GeomFromText('MULTIPOINT((1 2), (3 4), (5 6), (8 9))'), 1) +SELECT ST_GeometryN(ST_GeomFromText('MULTIPOINT((1 2), (3 4), (5 6), (8 9))'), 1); ``` ## ST_GeomFromWKB @@ -722,7 +722,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_GeometryType(ST_GeomFromWKT('POLYGON ((0 0, 1 0, 0 1, 0 0))')) +SELECT ST_GeometryType(ST_GeomFromWKT('POLYGON ((0 0, 1 0, 0 1, 0 0))')); ``` ## ST_HasM @@ -744,7 +744,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_HasM(ST_GeomFromWKT('POLYGON ((0 0, 1 0, 0 1, 0 0))')) +SELECT ST_HasM(ST_GeomFromWKT('POLYGON ((0 0, 1 0, 0 1, 0 0))')); ``` ## ST_HasZ @@ -766,7 +766,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_HasZ(ST_GeomFromWKT('POLYGON ((0 0, 1 0, 0 1, 0 0))')) +SELECT ST_HasZ(ST_GeomFromWKT('POLYGON ((0 0, 1 0, 0 1, 0 0))')); ``` ## ST_HausdorffDistance @@ -815,7 +815,7 @@ Since: v0.1. SELECT ST_Intersection(ST_GeomFromText('POLYGON ((1 1, 11 1, 1 11, 0 0))'), ST_GeomFromText('POLYGON ((0 0, 10 0, 0 10, 0 0))')) AS val ``` -## ST_Intersection_Aggr +## ST_Intersection_Agg #### Description @@ -825,7 +825,7 @@ Since: v0.1. #### Format -`ST_Intersection_Aggr (geom: Geometry)` +`ST_Intersection_Agg (geom: Geometry)` #### Arguments @@ -839,7 +839,7 @@ WITH shapes(geom) AS ( VALUES (ST_GeomFromWKT('POLYGON((0 0, 2 0, 2 2, 0 2, 0 0))')), (ST_GeomFromWKT('POLYGON((1 1, 3 1, 3 3, 1 3, 1 1))')) ) -SELECT ST_AsText(ST_Intersection_Aggr(geom)) FROM shapes; +SELECT ST_AsText(ST_Intersection_Agg(geom)) FROM shapes; -- Returns: POLYGON ((1 1, 1 2, 2 2, 2 1, 1 1)) ``` @@ -930,7 +930,7 @@ Format: `ST_IsRing(geom: Geometry)` Since: v0.2. ```sql -SELECT ST_IsRing(ST_GeomFromText("LINESTRING(0 0, 0 1, 1 1, 1 0, 0 0)")) +SELECT ST_IsRing(ST_GeomFromText("LINESTRING(0 0, 0 1, 1 1, 1 0, 0 0)")); ``` ## ST_IsSimple @@ -1392,6 +1392,10 @@ Since: v0.2. SELECT ST_AsText(ST_Polygonize(ST_GeomFromEWKT('GEOMETRYCOLLECTION (LINESTRING (2 0, 2 1, 2 2), LINESTRING (2 2, 2 3, 2 4), LINESTRING (0 2, 1 2, 2 2), LINESTRING (2 2, 3 2, 4 2), LINESTRING (0 2, 1 3, 2 4), LINESTRING (2 4, 3 3, 4 2))'))); ``` +## ST_Polygonize_Agg + +TODO + ## ST_Reverse Return the geometry with vertex order reversed @@ -1639,7 +1643,7 @@ Since: v0.1. SELECT ST_Union(ST_GeomFromText('POLYGON ((1 1, 11 1, 1 11, 0 0))'), ST_GeomFromText('POLYGON ((0 0, 10 0, 0 10, 0 0))')) AS val ``` -## ST_Union_Aggr +## ST_Union_Agg #### Description @@ -1649,7 +1653,7 @@ Since: v0.1. #### Format -`ST_Union_Aggr (geom: Geometry)` +`ST_Union_Agg (geom: Geometry)` #### Arguments @@ -1663,7 +1667,7 @@ WITH shapes(geom) AS ( VALUES (ST_GeomFromWKT('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')), (ST_GeomFromWKT('POLYGON ((2 2, 3 2, 3 3, 2 3, 2 2))')) ) -SELECT ST_AsText(ST_Union_Aggr(geom)) FROM shapes; +SELECT ST_AsText(ST_Union_Agg(geom)) FROM shapes; -- Returns: MULTIPOLYGON (((2 2, 3 2, 3 3, 2 3, 2 2)), ((0 0, 1 0, 1 1, 0 1, 0 0))) ``` @@ -1868,7 +1872,7 @@ Since: v0.1. ```sql SELECT ST_ZMax(ST_GeomFromWKT('LINESTRING ZM (1 2 3 4, 5 6 7 8)')); --- Returns: 7 +-- Returns: 7.0 ``` ## ST_ZMin From 602533a5d3e922850a3e7113149105dfe9a1d774 Mon Sep 17 00:00:00 2001 From: Matthew Powers Date: Tue, 2 Dec 2025 13:49:01 -0500 Subject: [PATCH 4/7] update sql docs --- docs/reference/sql.md | 230 +++++++++++++++++++++++++++++------------- 1 file changed, 161 insertions(+), 69 deletions(-) diff --git a/docs/reference/sql.md b/docs/reference/sql.md index 49474eaf6..30e40f428 100644 --- a/docs/reference/sql.md +++ b/docs/reference/sql.md @@ -185,7 +185,12 @@ Format: `ST_ClosestPoint(g1: Geometry, g2: Geometry)` Since: v0.2. ```sql -SELECT ST_AsText(ST_ClosestPoint(g1, g2)) As ptwkt; +SELECT ST_AsText( + ST_ClosestPoint( + ST_GeogFromText('POINT(-118.4 34.0)'), -- Santa Monica + ST_GeogFromText('LINESTRING(-118.5 34.1, -118.3 33.9, -118.2 33.8)') -- LA coastline + ) +) As ptwkt; ``` ## ST_Collect @@ -212,7 +217,18 @@ SELECT ST_Collect(ST_GeomFromWKT('MULTIPOINT (0 1, 10 11)')); ## ST_Collect_Agg -TODO +ST_Collect_Agg is an aggregate function that combines multiple geometries from a set of rows into a single collection. + +```sql +SELECT ST_Collect_Agg(geom) as collected_points +FROM ( + SELECT ST_Point(-122.4194, 37.7749) as geom -- San Francisco + UNION ALL + SELECT ST_Point(-118.2437, 34.0522) -- Los Angeles + UNION ALL + SELECT ST_Point(-122.6765, 45.5231) -- Portland +) as cities; +``` ## ST_Contains @@ -234,7 +250,10 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_Contains(ST_Point(0.25 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val; +SELECT ST_Contains( + ST_Point(0.25, 0.25), + ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))') +) AS val; ``` ## ST_ConvexHull @@ -269,7 +288,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_CoveredBy(ST_Point(0.25 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')); +SELECT ST_CoveredBy(ST_Point(0.25, 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')); ``` ## ST_Covers @@ -292,7 +311,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_Covers(ST_Point(0.25 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val +SELECT ST_Covers(ST_Point(0.25, 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val; ``` ## ST_Crosses @@ -309,7 +328,11 @@ SELECT ST_Crosses(ST_GeomFromWKT('POLYGON((1 1, 4 1, 4 4, 1 4, 1 1))'),ST_GeomFr ## ST_CRS -TODO +ST_CRS returns the Coordinate Reference System (CRS) metadata associated with a geometry or geography object. + +```sql +SELECT ST_CRS(ST_Point(0.25, 0.25, 4326)) as crs_info; +``` ## ST_Difference @@ -331,7 +354,12 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_Difference(ST_GeomFromText('POLYGON ((1 1, 11 1, 1 11, 0 0))'), ST_GeomFromText('POLYGON ((0 0, 10 0, 0 10, 0 0))')) AS val; +sd.sql(""" +SELECT ST_Difference( + ST_GeomFromText('POLYGON ((1 1, 11 1, 11 11, 1 11, 1 1))'), + ST_GeomFromText('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))') +) AS val; +""").show() ``` ## ST_Dimension @@ -376,7 +404,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_Disjoint(ST_Point(0.25 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val +SELECT ST_Disjoint(ST_Point(0.25, 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val; ``` ## ST_Distance @@ -399,7 +427,10 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_Distance(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val +SELECT ST_Distance( + ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), + ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))') +) AS val; ``` ## ST_DistanceSphere @@ -421,8 +452,10 @@ Since: v0.1. #### SQL Example +TODO: fix sql + ```sql -SELECT ST_DistanceSphere(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val +SELECT ST_DistanceSphere(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val; ``` ## ST_DistanceSpheroid @@ -444,8 +477,13 @@ Since: v0.1. #### SQL Example +TODO: fix sql + ```sql -SELECT ST_DistanceSpheroid(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val +SELECT ST_DistanceSpheroid( + ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), + ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))') +) AS val ``` ## ST_Dump @@ -457,7 +495,7 @@ Format: ST_Dump(geom: Geometry) Since: v0.2. ```sql -SELECT ST_Dump(ST_GeomFromText('MULTIPOINT ((10 40), (40 30), (20 20), (30 10))')) +SELECT ST_Dump(ST_GeomFromText('MULTIPOINT ((10 40), (40 30), (20 20), (30 10))')); ``` ## ST_DWithin @@ -481,7 +519,11 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_DWithin(ST_Point(0.25, 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))'), 0.5); +SELECT ST_DWithin( + ST_Point(0.25, 0.25), + ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))'), + 0.5 +); ``` ## ST_EndPoint @@ -493,7 +535,7 @@ Format: `ST_EndPoint(geom: Geometry)` Since: v0.2. ```sql -SELECT ST_EndPoint(ST_GeomFromText('LINESTRING(100 150,50 60, 70 80, 160 170)')) +SELECT ST_EndPoint(ST_GeomFromText('LINESTRING(100 150,50 60, 70 80, 160 170)')); ``` ## ST_Envelope @@ -515,7 +557,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_Envelope(ST_Point(1.0, 2.0)) +SELECT ST_Envelope(ST_Point(1.0, 2.0)); ``` ## ST_Envelope_Agg @@ -536,6 +578,8 @@ Since: v0.1. #### SQL Example +TODO: fix sql + ```sql -- Create a table with geometries and calculate the aggregate envelope WITH shapes(geom) AS ( @@ -566,7 +610,10 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_Equals(ST_Point(0.25 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val +SELECT ST_Equals( + ST_Point(0.25, 0.25), + ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))') +); ``` ## ST_FlipCoordinates @@ -588,7 +635,9 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_FlipCoordinates(df.geometry) +SELECT ST_FlipCoordinates( + ST_Point(1, 2) +); ``` ## ST_FrechetDistance @@ -610,8 +659,10 @@ Since: v0.1. #### SQL Example +TODO: fix sql + ```sql -SELECT ST_FrechetDistance(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val +SELECT ST_FrechetDistance(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val; ``` ## ST_GeogPoint @@ -626,8 +677,10 @@ Format: `ST_GeogFromWKB (Wkb: Binary)` Since: v0.2. +TODO: fix sql + ```sql -SELECT ST_GeogFromWKB([01 02 00 00 00 02 00 00 00 00 00 00 00 84 d6 00 c0 00 00 00 00 80 b5 d6 bf 00 00 00 60 e1 ef f7 bf 00 00 00 80 07 5d e5 bf]) +SELECT ST_GeogFromWKB([01 02 00 00 00 02 00 00 00 00 00 00 00 84 d6 00 c0 00 00 00 00 80 b5 d6 bf 00 00 00 60 e1 ef f7 bf 00 00 00 80 07 5d e5 bf]); ``` ## ST_GeogFromWKT @@ -643,7 +696,7 @@ or Since: v0.2. ```sql -SELECT ST_GeogFromWKT('LINESTRING (1 2, 3 4, 5 6)') +SELECT ST_GeogFromWKT('LINESTRING (1 2, 3 4, 5 6)'); ``` ## ST_GeometryN @@ -678,7 +731,9 @@ Since: v0.1. ```sql -- Creates a POINT(1 2) geometry from its WKB representation -SELECT ST_AsText(ST_GeomFromWKB(FROM_HEX('0101000000000000000000F03F0000000000000040'))); +SELECT ST_AsText( + ST_GeomFromWKB(decode('0101000000000000000000F03F0000000000000040', 'hex')) +); ``` ## ST_GeomFromWKT @@ -788,8 +843,10 @@ Since: v0.1. #### SQL Example +TODO: fix sql + ```sql -SELECT ST_HausdorffDistance(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val +SELECT ST_HausdorffDistance(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val; ``` ## ST_Intersection @@ -812,7 +869,10 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_Intersection(ST_GeomFromText('POLYGON ((1 1, 11 1, 1 11, 0 0))'), ST_GeomFromText('POLYGON ((0 0, 10 0, 0 10, 0 0))')) AS val +SELECT ST_Intersection( + ST_GeomFromText('POLYGON ((1 1, 11 1, 11 11, 1 11, 1 1))'), + ST_GeomFromText('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))') +) AS val; ``` ## ST_Intersection_Agg @@ -863,7 +923,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_Intersects(ST_Point(0.25 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val +SELECT ST_Intersects(ST_Point(0.25, 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val; ``` ## ST_IsClosed @@ -875,7 +935,7 @@ Format: `ST_IsClosed(geom: Geometry)` Since: v0.2. ```sql -SELECT ST_IsClosed(ST_GeomFromText('LINESTRING(0 0, 1 1, 1 0)')) +SELECT ST_IsClosed(ST_GeomFromText('LINESTRING(0 0, 1 1, 1 0)')); ``` ## ST_IsCollection @@ -892,11 +952,11 @@ Format: `ST_IsCollection(geom: Geometry)` Since: v0.2. ```sql -SELECT ST_IsCollection(ST_GeomFromText('MULTIPOINT(0 0), (6 6)')) +SELECT ST_IsCollection(ST_GeomFromText('MULTIPOINT(0 0), (6 6)')); ``` ```sql -SELECT ST_IsCollection(ST_GeomFromText('POINT(5 5)')) +SELECT ST_IsCollection(ST_GeomFromText('POINT(5 5)')); ``` ## ST_IsEmpty @@ -930,7 +990,7 @@ Format: `ST_IsRing(geom: Geometry)` Since: v0.2. ```sql -SELECT ST_IsRing(ST_GeomFromText("LINESTRING(0 0, 0 1, 1 1, 1 0, 0 0)")); +SELECT ST_IsRing(ST_GeomFromText('LINESTRING(0 0, 0 1, 1 1, 1 0, 0 0)')); ``` ## ST_IsSimple @@ -942,16 +1002,28 @@ Format: `ST_IsSimple (A: Geometry)` Since: v0.2. ```sql -SELECT ST_IsSimple(ST_GeomFromWKT('POLYGON((1 1, 3 1, 3 3, 1 3, 1 1))')) +SELECT ST_IsSimple(ST_GeomFromWKT('POLYGON((1 1, 3 1, 3 3, 1 3, 1 1))')); ``` ## ST_IsValid -TODO +ST_IsValid checks whether a geometry meets the rules of a valid spatial object according to the OGC standard. + +```sql +SELECT ST_IsValid( + ST_GeomFromText('POLYGON ((0 0, 2 0, 2 2, 1 1, 0 2, 0 0))') +) AS is_valid; +``` ## ST_IsValidReason -TODO +ST_IsValidReason returns a text explanation describing why a geometry is invalid. + +```sql +SELECT ST_IsValidReason( + ST_GeomFromText('POLYGON((0 0, 2 0, 2 2, 1 1, 0 2, 0 0))') +) AS reason; +``` ## ST_KNN @@ -975,7 +1047,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT * FROM table1 a JOIN table2 b ON ST_KNN(a.geom, b.geom, 5, false) +SELECT * FROM table1 a JOIN table2 b ON ST_KNN(a.geom, b.geom, 5, false); ``` ## ST_Length @@ -1009,7 +1081,7 @@ Format: `ST_LineInterpolatePoint (geom: Geometry, fraction: Double)` Since: v0.2. ```sql -SELECT ST_LineInterpolatePoint(ST_GeomFromWKT('LINESTRING(25 50, 100 125, 150 190)'), 0.2) +SELECT ST_LineInterpolatePoint(ST_GeomFromWKT('LINESTRING(25 50, 100 125, 150 190)'), 0.2); ``` ## ST_LineLocatePoint @@ -1020,8 +1092,10 @@ Format: `ST_LineLocatePoint(linestring: Geometry, point: Geometry)` Since: v0.2. +TODO: fix sql + ```sql -SELECT ST_LineLocatePoint(ST_GeomFromWKT('LINESTRING(0 0, 1 1, 2 2)'), ST_GeomFromWKT('POINT(0 2)')) +SELECT ST_LineLocatePoint(ST_GeomFromWKT('LINESTRING(0 0, 1 1, 2 2)'), ST_GeomFromWKT('POINT(0 2)')); ``` ## ST_M @@ -1043,7 +1117,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_M(ST_Point(1.0, 2.0)) +SELECT ST_M(ST_Point(1.0, 2.0)); ``` ## ST_MakeLine @@ -1066,7 +1140,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_MakeLine(ST_Point(0, 1), ST_Point(2, 3)) as geom +SELECT ST_MakeLine(ST_Point(0, 1), ST_Point(2, 3)) as geom; ``` ## ST_MakeValid @@ -1084,10 +1158,12 @@ ST_MakeValid (A: Geometry, keepCollapsed: Boolean) Since: v0.2. +TODO: fix sql + ```sql WITH linestring AS ( SELECT ST_GeomFromWKT('LINESTRING(1 1, 1 1)') AS geom -) SELECT ST_MakeValid(geom), ST_MakeValid(geom, true) FROM linestring +) SELECT ST_MakeValid(geom), ST_MakeValid(geom, true) FROM linestring; ``` ## ST_MaxDistance @@ -1109,8 +1185,10 @@ Since: v0.1. #### SQL Example +TODO: fix sql + ```sql -SELECT ST_MaxDistance(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val +SELECT ST_MaxDistance(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val; ``` ## ST_MinimumClearance @@ -1131,8 +1209,8 @@ Since: v0.2. ```sql SELECT ST_MinimumClearance( - ST_GeomFromWKT('POLYGON ((65 18, 62 16, 64.5 16, 62 14, 65 14, 65 18))') -) + ST_GeomFromWKT('POLYGON ((65 18, 62 16, 64.5 16, 62 14, 65 14, 65 18))') +); ``` ## ST_MinimumClearanceLine @@ -1145,8 +1223,8 @@ Since: v0.2. ```sql SELECT ST_MinimumClearanceLine( - ST_GeomFromWKT('POLYGON ((65 18, 62 16, 64.5 16, 62 14, 65 14, 65 18))') -) + ST_GeomFromWKT('POLYGON ((65 18, 62 16, 64.5 16, 62 14, 65 14, 65 18))') +); ``` ## ST_MMax @@ -1168,7 +1246,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_MMax(ST_GeomFromWKT('POLYGON ((0 0, 1 0, 0 1, 0 0))')) +SELECT ST_MMax(ST_GeomFromWKT('POLYGON ((0 0, 1 0, 0 1, 0 0))')); ``` ## ST_MMin @@ -1203,7 +1281,7 @@ Format: `ST_NPoints (A: Geometry)` Since: v0.2. ```sql -SELECT ST_NPoints(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)')) +SELECT ST_NPoints(ST_GeomFromText('LINESTRING(77.29 29.07,77.42 29.26,77.27 29.31,77.29 29.07)')); ``` ## ST_NumGeometries @@ -1215,7 +1293,7 @@ Format: `ST_NumGeometries (A: Geometry)` Since: v0.2. ```sql -SELECT ST_NumGeometries(ST_GeomFromWKT('LINESTRING (-29 -27, -30 -29.7, -45 -33)')) +SELECT ST_NumGeometries(ST_GeomFromWKT('LINESTRING (-29 -27, -30 -29.7, -45 -33)')); ``` ## ST_Overlaps @@ -1227,7 +1305,7 @@ Format: `ST_Overlaps (A: Geometry, B: Geometry)` Since: v0.2. ```sql -SELECT ST_Overlaps(ST_GeomFromWKT('POLYGON((2.5 2.5, 2.5 4.5, 4.5 4.5, 4.5 2.5, 2.5 2.5))'), ST_GeomFromWKT('POLYGON((4 4, 4 6, 6 6, 6 4, 4 4))')) +SELECT ST_Overlaps(ST_GeomFromWKT('POLYGON((2.5 2.5, 2.5 4.5, 4.5 4.5, 4.5 2.5, 2.5 2.5))'), ST_GeomFromWKT('POLYGON((4 4, 4 6, 6 6, 6 4, 4 4))')); ``` ## ST_Perimeter @@ -1302,7 +1380,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_PointM(-64.36, 45.09, 50.0) +SELECT ST_PointM(-64.36, 45.09, 50.0); ``` ## ST_PointN @@ -1314,7 +1392,7 @@ Format: `ST_PointN(geom: Geometry, n: Integer)` Since: v0.2. ```sql -SELECT ST_PointN(ST_GeomFromText("LINESTRING(0 0, 1 2, 2 4, 3 6)"), 2) +SELECT ST_PointN(ST_GeomFromText('LINESTRING(0 0, 1 2, 2 4, 3 6)'), 2); ``` ## ST_Points @@ -1326,7 +1404,7 @@ Format: `ST_Points(geom: Geometry)` Since: v0.2. ```sql -SELECT ST_AsText(ST_Points(ST_GeomFromEWKT('LINESTRING (2 4, 3 3, 4 2, 7 3)'))); +SELECT ST_AsText(ST_Points(ST_GeomFromText('LINESTRING (2 4, 3 3, 4 2, 7 3)'))); ``` ## ST_PointZ @@ -1350,7 +1428,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_PointZ(-64.36, 45.09, 100.0) +SELECT ST_PointZ(-64.36, 45.09, 100.0); ``` ## ST_PointZM @@ -1375,7 +1453,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_PointZM(-64.36, 45.09, 100.0, 50.0) +SELECT ST_PointZM(-64.36, 45.09, 100.0, 50.0); ``` ## ST_Polygonize @@ -1389,7 +1467,7 @@ Format: `ST_Polygonize(geom: Geometry)` Since: v0.2. ```sql -SELECT ST_AsText(ST_Polygonize(ST_GeomFromEWKT('GEOMETRYCOLLECTION (LINESTRING (2 0, 2 1, 2 2), LINESTRING (2 2, 2 3, 2 4), LINESTRING (0 2, 1 2, 2 2), LINESTRING (2 2, 3 2, 4 2), LINESTRING (0 2, 1 3, 2 4), LINESTRING (2 4, 3 3, 4 2))'))); +SELECT ST_AsText(ST_Polygonize(ST_GeomFromText('GEOMETRYCOLLECTION (LINESTRING (2 0, 2 1, 2 2), LINESTRING (2 2, 2 3, 2 4), LINESTRING (0 2, 1 2, 2 2), LINESTRING (2 2, 3 2, 4 2), LINESTRING (0 2, 1 3, 2 4), LINESTRING (2 4, 3 3, 4 2))'))); ``` ## ST_Polygonize_Agg @@ -1405,12 +1483,18 @@ Format: `ST_Reverse (A: Geometry)` Since: v0.2. ```sql -SELECT ST_Reverse(ST_GeomFromWKT('LINESTRING(0 0, 1 2, 2 4, 3 6)')) +SELECT ST_Reverse(ST_GeomFromWKT('LINESTRING(0 0, 1 2, 2 4, 3 6)')); ``` ## ST_SetCRS -TODO +TODO: fix sql + +```sql +SELECT ST_AsText( + ST_SetCRS(ST_Point(10, 20), 4326) +) AS geom_with_crs; +``` ## ST_ShortestLine @@ -1427,7 +1511,7 @@ Format: `ST_Simplify(geom: Geometry, tolerance: Double)` Since: v0.2. ```sql -SELECT ST_Simplify(ST_Buffer(ST_GeomFromWKT('POINT (0 2)'), 10), 1) +SELECT ST_Simplify(ST_Buffer(ST_GeomFromWKT('POINT (0 2)'), 10), 1); ``` ## ST_SimplifyPreserveTopology @@ -1439,7 +1523,7 @@ Since: v0.2. Format: `ST_SimplifyPreserveTopology (A: Geometry, distanceTolerance: Double)` ```sql -SELECT ST_SimplifyPreserveTopology(ST_GeomFromText('POLYGON((8 25, 28 22, 28 20, 15 11, 33 3, 56 30, 46 33,46 34, 47 44, 35 36, 45 33, 43 19, 29 21, 29 22,35 26, 24 39, 8 25))'), 10) +SELECT ST_SimplifyPreserveTopology(ST_GeomFromText('POLYGON((8 25, 28 22, 28 20, 15 11, 33 3, 56 30, 46 33,46 34, 47 44, 35 36, 45 33, 43 19, 29 21, 29 22,35 26, 24 39, 8 25))'), 10); ``` ## ST_Snap @@ -1457,7 +1541,7 @@ SELECT ST_Snap(poly, line, ST_Distance(poly, line) * 1.01) AS polySnapped FROM ( SELECT ST_GeomFromWKT('POLYGON ((236877.58 -6.61, 236878.29 -8.35, 236879.98 -8.33, 236879.72 -7.63, 236880.35 -6.62, 236877.58 -6.61), (236878.45 -7.01, 236878.43 -7.52, 236879.29 -7.50, 236878.63 -7.22, 236878.76 -6.89, 236878.45 -7.01))') as poly, ST_GeomFromWKT('LINESTRING (236880.53 -8.22, 236881.15 -7.68, 236880.69 -6.81)') as line -) +); ``` ## ST_SetSRID @@ -1514,7 +1598,7 @@ Format: `ST_StartPoint(geom: Geometry)` Since: v0.2. ```sql -SELECT ST_StartPoint(ST_GeomFromText('LINESTRING(100 150,50 60, 70 80, 160 170)')) +SELECT ST_StartPoint(ST_GeomFromText('LINESTRING(100 150,50 60, 70 80, 160 170)')); ``` ## ST_SymDifference @@ -1537,7 +1621,10 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_SymDifference(ST_GeomFromText('POLYGON ((1 1, 11 1, 1 11, 0 0))'), ST_GeomFromText('POLYGON ((0 0, 10 0, 0 10, 0 0))')) AS val +SELECT ST_SymDifference( + ST_GeomFromText('POLYGON ((1 1, 11 1, 11 11, 1 11, 1 1))'), + ST_GeomFromText('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))') +) AS val; ``` ## ST_Touches @@ -1560,7 +1647,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_Touches(ST_Point(0.25 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val +SELECT ST_Touches(ST_Point(0.25, 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val; ``` ## ST_Transform @@ -1605,7 +1692,7 @@ Format: `ST_Translate(geometry: Geometry, deltaX: Double, deltaY: Double, deltaZ Since: v0.2. ```sql -SELECT ST_Translate(ST_GeomFromText('POINT(-71.01 42.37)'), 1, 2) +SELECT ST_Translate(ST_GeomFromText('POINT(-71.01 42.37)'), 1, 2); ``` ## vST_UnaryUnion @@ -1617,7 +1704,7 @@ Format: `ST_UnaryUnion(geometry: Geometry)` Since: v0.2. ```sql -SELECT ST_UnaryUnion(ST_GeomFromWKT('MULTIPOLYGON(((0 10,0 30,20 30,20 10,0 10)),((10 0,10 20,30 20,30 0,10 0)))')) +SELECT ST_UnaryUnion(ST_GeomFromWKT('MULTIPOLYGON(((0 10,0 30,20 30,20 10,0 10)),((10 0,10 20,30 20,30 0,10 0)))')); ``` ## ST_Union @@ -1640,7 +1727,10 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_Union(ST_GeomFromText('POLYGON ((1 1, 11 1, 1 11, 0 0))'), ST_GeomFromText('POLYGON ((0 0, 10 0, 0 10, 0 0))')) AS val +SELECT ST_Union( + ST_GeomFromText('POLYGON ((1 1, 11 1, 11 11, 1 11, 1 1))'), + ST_GeomFromText('POLYGON ((0 0, 10 0, 10 10, 0 10, 0 0))') +) AS val; ``` ## ST_Union_Agg @@ -1661,6 +1751,8 @@ Since: v0.1. #### SQL Example +TODO: fix sql + ```sql -- Create a table with two separate polygons and unite them into a single multipolygon WITH shapes(geom) AS ( @@ -1691,7 +1783,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_Within(ST_Point(0.25 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val +SELECT ST_Within(ST_Point(0.25, 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val; ``` ## ST_X @@ -1713,7 +1805,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_X(ST_Point(1.0, 2.0)) +SELECT ST_X(ST_Point(1.0, 2.0)); ``` ## ST_XMax @@ -1781,7 +1873,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_Y(ST_Point(1.0, 2.0)) +SELECT ST_Y(ST_Point(1.0, 2.0)); ``` ## ST_YMax @@ -1849,7 +1941,7 @@ Since: v0.1. #### SQL Example ```sql -SELECT ST_Z(ST_Point(1.0, 2.0)) +SELECT ST_Z(ST_Point(1.0, 2.0)); ``` ## ST_ZMax @@ -1910,6 +2002,6 @@ Since: v0.2. ```sql SELECT ST_Zmflag( - ST_GeomFromWKT('LINESTRING Z(1 2 3, 4 5 6)') -) + ST_GeomFromWKT('LINESTRING Z(1 2 3, 4 5 6)') +); ``` From 0f987146c80f925411f5af2ee769c54afab63f05 Mon Sep 17 00:00:00 2001 From: Matthew Powers Date: Tue, 2 Dec 2025 15:02:47 -0500 Subject: [PATCH 5/7] update sql functions --- docs/reference/sql.md | 160 ++---------------------------------------- 1 file changed, 7 insertions(+), 153 deletions(-) diff --git a/docs/reference/sql.md b/docs/reference/sql.md index 30e40f428..b480d2229 100644 --- a/docs/reference/sql.md +++ b/docs/reference/sql.md @@ -193,28 +193,6 @@ SELECT ST_AsText( ) As ptwkt; ``` -## ST_Collect - -#### Description - -Aggregates a set of geometries into a single `GeometryCollection`, `MultiPoint`, `MultiLineString`, or `MultiPolygon`. If all input geometries are of the same type (e.g., all points), it creates a multi-geometry of that type. If the geometries are of mixed types, it returns a `GeometryCollection`. - -Since: v0.1. - -#### Format - -`ST_Collect (geom: Geometry)` - -#### Arguments - - * **geom**: The input geometry or geography to be collected. - -#### SQL Example - -```sql -SELECT ST_Collect(ST_GeomFromWKT('MULTIPOINT (0 1, 10 11)')); -``` - ## ST_Collect_Agg ST_Collect_Agg is an aggregate function that combines multiple geometries from a set of rows into a single collection. @@ -407,85 +385,6 @@ Since: v0.1. SELECT ST_Disjoint(ST_Point(0.25, 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val; ``` -## ST_Distance - -#### Description - -Calculates the distance between geomA and geomB. - -Since: v0.1. - -#### Format - -`ST_Distance (A: Geometry, B: Geometry)` - -#### Arguments - - * **geomA**: Input geometry or geography. - * **geomB**: Input geometry or geography. - -#### SQL Example - -```sql -SELECT ST_Distance( - ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), - ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))') -) AS val; -``` - -## ST_DistanceSphere - -#### Description - -Calculates the spherical distance between geomA and geomB. - -Since: v0.1. - -#### Format - -`ST_DistanceSphere (A: Geometry, B: Geometry)` - -#### Arguments - - * **geomA**: Input geometry or geography. - * **geomB**: Input geometry or geography. - -#### SQL Example - -TODO: fix sql - -```sql -SELECT ST_DistanceSphere(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val; -``` - -## ST_DistanceSpheroid - -#### Description - -Calculates the spheroidal (ellipsoidal) distance between geomA and geomB. - -Since: v0.1. - -#### Format - -`ST_DistanceSpheroid (A: Geometry, B: Geometry)` - -#### Arguments - - * **geomA**: Input geometry or geography. - * **geomB**: Input geometry or geography. - -#### SQL Example - -TODO: fix sql - -```sql -SELECT ST_DistanceSpheroid( - ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), - ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))') -) AS val -``` - ## ST_Dump It expands the geometries. If the geometry is simple (Point, Polygon Linestring etc.) it returns the geometry itself, if the geometry is collection or multi it returns record for each of collection components. @@ -640,35 +539,14 @@ SELECT ST_FlipCoordinates( ); ``` -## ST_FrechetDistance - -#### Description - -Calculates the Frechet distance between geomA and geomB. - -Since: v0.1. - -#### Format - -`ST_FrechetDistance (A: Geometry, B: Geometry)` - -#### Arguments - - * **geomA**: Input geometry or geography. - * **geomB**: Input geometry or geography. - -#### SQL Example +## ST_GeogPoint -TODO: fix sql +ST_GeogPoint creates a geography POINT from given longitude and latitude coordinates. ```sql -SELECT ST_FrechetDistance(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val; +SELECT ST_GeogPoint(10, 10), ST_GeogPoint(0, 0); ``` -## ST_GeogPoint - -TODO - ## ST_GeogFromWKB Construct a Geography from WKB Binary. @@ -824,31 +702,6 @@ Since: v0.1. SELECT ST_HasZ(ST_GeomFromWKT('POLYGON ((0 0, 1 0, 0 1, 0 0))')); ``` -## ST_HausdorffDistance - -#### Description - -Calculates the Hausdorff distance between geomA and geomB. - -Since: v0.1. - -#### Format - -`ST_HausdorffDistance (A: Geometry, B: Geometry)` - -#### Arguments - - * **geomA**: Input geometry or geography. - * **geomB**: Input geometry or geography. - -#### SQL Example - -TODO: fix sql - -```sql -SELECT ST_HausdorffDistance(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val; -``` - ## ST_Intersection #### Description @@ -1092,10 +945,11 @@ Format: `ST_LineLocatePoint(linestring: Geometry, point: Geometry)` Since: v0.2. -TODO: fix sql - ```sql -SELECT ST_LineLocatePoint(ST_GeomFromWKT('LINESTRING(0 0, 1 1, 2 2)'), ST_GeomFromWKT('POINT(0 2)')); +SELECT ST_LineLocatePoint( + ST_GeogFromText('LINESTRING(0 0, 1 1, 2 2)'), + ST_GeogFromText('POINT(0 2)') +); ``` ## ST_M From 508d0a98432eb4c7432d8b50a2b5676d1a510134 Mon Sep 17 00:00:00 2001 From: Matthew Powers Date: Tue, 2 Dec 2025 16:50:09 -0500 Subject: [PATCH 6/7] pre commit --- docs/reference/sql.md | 82 ++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 43 deletions(-) diff --git a/docs/reference/sql.md b/docs/reference/sql.md index b480d2229..1a0bc8e43 100644 --- a/docs/reference/sql.md +++ b/docs/reference/sql.md @@ -229,7 +229,7 @@ Since: v0.1. ```sql SELECT ST_Contains( - ST_Point(0.25, 0.25), + ST_Point(0.25, 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))') ) AS val; ``` @@ -419,8 +419,8 @@ Since: v0.1. ```sql SELECT ST_DWithin( - ST_Point(0.25, 0.25), - ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))'), + ST_Point(0.25, 0.25), + ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))'), 0.5 ); ``` @@ -477,16 +477,8 @@ Since: v0.1. #### SQL Example -TODO: fix sql - ```sql --- Create a table with geometries and calculate the aggregate envelope -WITH shapes(geom) AS ( - VALUES (ST_GeomFromWKT('POINT (0 1)')), - (ST_GeomFromWKT('POINT (10 11)')) -) -SELECT ST_AsText(ST_Envelope_Agg(geom)) FROM shapes; --- Returns: POLYGON ((0 1, 0 11, 10 11, 10 1, 0 1)) +SELECT ST_Envelope_Agg(ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) ``` ## ST_Equals @@ -510,7 +502,7 @@ Since: v0.1. ```sql SELECT ST_Equals( - ST_Point(0.25, 0.25), + ST_Point(0.25, 0.25), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))') ); ``` @@ -555,10 +547,8 @@ Format: `ST_GeogFromWKB (Wkb: Binary)` Since: v0.2. -TODO: fix sql - ```sql -SELECT ST_GeogFromWKB([01 02 00 00 00 02 00 00 00 00 00 00 00 84 d6 00 c0 00 00 00 00 80 b5 d6 bf 00 00 00 60 e1 ef f7 bf 00 00 00 80 07 5d e5 bf]); +SELECT ST_GeogFromWKB(decode('010200000002000000000000000084d600c0000000000080b5d6bf00000060e1eff7bf00000080075de5bf', 'hex')); ``` ## ST_GeogFromWKT @@ -1012,12 +1002,8 @@ ST_MakeValid (A: Geometry, keepCollapsed: Boolean) Since: v0.2. -TODO: fix sql - ```sql -WITH linestring AS ( - SELECT ST_GeomFromWKT('LINESTRING(1 1, 1 1)') AS geom -) SELECT ST_MakeValid(geom), ST_MakeValid(geom, true) FROM linestring; +SELECT ST_MakeValid(ST_GeomFromWKT('LINESTRING(1 1, 1 1)')); ``` ## ST_MaxDistance @@ -1039,10 +1025,11 @@ Since: v0.1. #### SQL Example -TODO: fix sql - ```sql -SELECT ST_MaxDistance(ST_GeomFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), ST_GeomFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))')) AS val; +SELECT ST_MaxDistance( + ST_GeogFromText('POLYGON ((10 10, 11 10, 10 11, 10 10))'), + ST_GeogFromText('POLYGON ((0 0, 1 0, 0 1, 0 0))') +) AS val; ``` ## ST_MinimumClearance @@ -1326,7 +1313,20 @@ SELECT ST_AsText(ST_Polygonize(ST_GeomFromText('GEOMETRYCOLLECTION (LINESTRING ( ## ST_Polygonize_Agg -TODO +ST_Polygonize_Agg is an aggregate function that combines a set of linestrings into polygons by finding closed rings formed by the input geometries. + +```sql +SELECT ST_Polygonize_Agg(geom) AS polygons +FROM ( + SELECT ST_GeomFromText('LINESTRING(0 0, 0 1)') AS geom + UNION ALL + SELECT ST_GeomFromText('LINESTRING(0 1, 1 1)') + UNION ALL + SELECT ST_GeomFromText('LINESTRING(1 1, 1 0)') + UNION ALL + SELECT ST_GeomFromText('LINESTRING(1 0, 0 0)') +) AS edges; +``` ## ST_Reverse @@ -1342,17 +1342,16 @@ SELECT ST_Reverse(ST_GeomFromWKT('LINESTRING(0 0, 1 2, 2 4, 3 6)')); ## ST_SetCRS -TODO: fix sql - -```sql -SELECT ST_AsText( - ST_SetCRS(ST_Point(10, 20), 4326) -) AS geom_with_crs; -``` +ST_SetCRS sets or changes the Coordinate Reference System (CRS) identifier of a geometry without transforming its coordinates. -## ST_ShortestLine +```python +import pyproj +crs = pyproj.CRS("EPSG:3857") -TODO +sd.sql(f""" +SELECT ST_SetCRS(ST_GeomFromText('LINESTRING(0 1, 2 3)'), '{crs.to_json()}') as geom; +""").show() +``` ## ST_Simplify @@ -1605,16 +1604,13 @@ Since: v0.1. #### SQL Example -TODO: fix sql - ```sql --- Create a table with two separate polygons and unite them into a single multipolygon -WITH shapes(geom) AS ( - VALUES (ST_GeomFromWKT('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')), - (ST_GeomFromWKT('POLYGON ((2 2, 3 2, 3 3, 2 3, 2 2))')) -) -SELECT ST_AsText(ST_Union_Agg(geom)) FROM shapes; --- Returns: MULTIPOLYGON (((2 2, 3 2, 3 3, 2 3, 2 2)), ((0 0, 1 0, 1 1, 0 1, 0 0))) +SELECT ST_AsText(ST_Union_Agg(geom)) +FROM ( + SELECT ST_GeomFromWKT('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))') AS geom + UNION ALL + SELECT ST_GeomFromWKT('POLYGON ((2 2, 3 2, 3 3, 2 3, 2 2))') +) AS shapes; ``` ## ST_Within From f50818dab422e857616896f87d49ce6eb4617fa6 Mon Sep 17 00:00:00 2001 From: Matthew Powers Date: Tue, 2 Dec 2025 17:39:39 -0500 Subject: [PATCH 7/7] Apply suggestions from code review Co-authored-by: Peter Nguyen Co-authored-by: Dewey Dunnington --- docs/reference/sql.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/reference/sql.md b/docs/reference/sql.md index 1a0bc8e43..9881c4e48 100644 --- a/docs/reference/sql.md +++ b/docs/reference/sql.md @@ -139,6 +139,8 @@ Returns a geometry that represents all points whose distance from the input geom Since: v0.1. +Changed in version v0.2: Support buffer parameters argument + #### Format `ST_Buffer (A: Geometry, distance: Double)` @@ -608,7 +610,7 @@ SELECT ST_AsText( #### Description -Construct a Geometry from WKT. This function also has the alias **ST_GeomFromText**. +Construct a Geometry from WKT. This function also has the aliases **ST_GeomFromText** and ** ST_GeometryFromText** Since: v0.1. @@ -785,7 +787,7 @@ SELECT ST_IsClosed(ST_GeomFromText('LINESTRING(0 0, 1 1, 1 0)')); Returns TRUE if the geometry type of the input is a geometry collection type. Collection types are the following: -```sql +``` GEOMETRYCOLLECTION MULTI{POINT, POLYGON, LINESTRING} ```