Skip to content

ST Class

Overview

The ST static class provide a common set of spatial operations that can be used consistently in both SQLite and C#. Rather than maintaining separate implementations for application code and database queries, developers can work with a familiar set of spatial concepts across both environments.

This unified model makes it easier to move spatial logic between application code and the database. Operations such as creating geometries, calculating distances, testing spatial relationships, and performing geometric transformations can be expressed using the same conceptual API, whether they are executed in-memory through C# or within SQLite queries.

C# Namespace

using SQuan.Helpers.SQLite.Spatial;

Constructors

Name Description
ST_Point Creates a point geometry
ST_GeomFromText Creates a geometry using WKT definition

Methods

Name Description
ST_Area Calculates the area of a polygon geometry.
ST_AsText Returns the WKT representation of the geometry.
ST_X Extracts the X-coordinate of the centroid of a geometry.
ST_XMax Returns the Y maximum of a bounding box or a geometry.
ST_XMin Returns the X minimum of a bounding box or a geometry.
ST_Y Extracts the Y-coordinate of the centroid of a geometry.
ST_YMax Returns the Y maximum of a bounding box or a geometry.
ST_YMin Returns the Y minimum of a bounding box or a geometry.

ST_Area

Calculates the area of a polygon geometry provided in EWKB format. If the input is null or invalid, the method returns null. The area is computed assuming planar geometry and is expressed in the same units as the coordinate system of the input.

double ST_Area(blob ewkb)
SELECT ST_Area('POLYGON((0 0, 40 30, 40 0, 0 0))')
byte[] square = "POLYGON((0 0, 40 30, 40 0, 0 0))".ST_GeomFromText();
double area = square.ST_Area();

ST_AsText

Returns the OGC Well-Known Text (WKT) representation of the geometry.

text ST_AsText(blob ewkb)
SELECT ST_AsText(ST_Point(40,30))
byte[] point = ST.ST_Point(40, 30);
string ewkt = point.ST_AsText();

ST_GeomFromText

blob ST_GeomFromText(text wkt)

Constructs a geometry object from the OGC Well-Known text representation.

SELECT ST_GeomFromText('POLYGON((0 0, 40 30, 40 0, 0 0))')
byte[] geometry = "POLYGON((0 0, 40 30, 40 0, 0 0))".ST_GeomFromText();

ST_Point

blob ST_Point(real x, real y, [integer srid = 4326])

Returns a Point with the given X and Y coordinate values.

SELECT ST_Point(40,30)
byte[] point = ST.ST_Point(40, 30);

ST_X

Extracts the X-coordinate of the centroid (geometric center) of a geometry provided in EWKB format. The centroid represents the average position of all points in the geometry and is useful for labeling, spatial indexing, and geometric analysis.

real ST_X(blob ewkb)
SELECT ST_X(ST_Point(40, 30))
byte[] point = ST.ST_Point(40, 30);
double x_40 = point.ST_X();

ST_XMax

Returns the X maximum of a bounding box or a geometry.

real ST_XMax(blob ewkb)
SELECT ST_XMax(ST_GeomFromText("POLYGON((30 40, 50 40, 50 60, 30 60, 30 40))"))
byte[] square = "POLYGON((30 40, 50 40, 50 60, 30 60, 30 40))".ST_GeomFromText();
double xmax_50 = square.ST_XMax();

ST_XMin

Returns the X minimum of a bounding box or a geometry.

real ST_XMin(blob ewkb)
SELECT ST_XMin(ST_GeomFromText("POLYGON((30 40, 50 40, 50 60, 30 60, 30 40))"))
byte[] square = "POLYGON((30 40, 50 40, 50 60, 30 60, 30 40))".ST_GeomFromText();
double xmin_30 = square.ST_XMin();

ST_Y

Extracts the Y-coordinate of the centroid (geometric center) of a geometry provided in EWKB format. The centroid represents the average position of all points in the geometry and is useful for labeling, spatial indexing, and geometric analysis.

real ST_Y(blob ewkb)
SELECT ST_Y(ST_Point(40, 30))
byte[] point = ST.ST_Point(40, 30);
double y_30 = point.ST_Y();

ST_YMax

Returns the Y maximum of a bounding box or a geometry.

real ST_YMax(blob ewkb)

SELECT ST_YMax(ST_GeomFromText("POLYGON((30 40, 50 40, 50 60, 30 60, 30 40))"))
byte[] square = "POLYGON((30 40, 50 40, 50 60, 30 60, 30 40))".ST_GeomFromText();
double ymax_60 = square.ST_YMax();

ST_YMin

Returns the Y minimum of a bounding box or a geometry.

real ST_YMin(blob ewkb)
SELECT ST_YMin(ST_GeomFromText("POLYGON((30 40, 50 40, 50 60, 30 60, 30 40))"))
byte[] square = "POLYGON((30 40, 50 40, 50 60, 30 60, 30 40))".ST_GeomFromText();
double ymin_40 = square.ST_YMin();