Skip to main content

@terascope/data-mate / function-configs/geo/sql-utils

function-configs/geo/sql-utils

Functions​

asGeometry()​

asGeometry(value, inputConfig): string

Defined in: data-mate/src/function-configs/geo/sql-utils.ts:99

The column as a GEOMETRY.

A GeoJSON column already is one. A GeoPoint column becomes a point. ST_Point takes (x, y), so longitude comes first, matching makeCoordinatesFromGeoPoint.

Parameters​

ParameterType
valuestring
inputConfigDataTypeFieldAndChildren

Returns​

string


constantGeometry()​

constantGeometry(value): string

Defined in: data-mate/src/function-configs/geo/sql-utils.ts:107

A constant geo argument as a GEOMETRY, resolved at plan time.

Parameters​

ParameterType
valueunknown

Returns​

string


distanceSphere()​

distanceSphere(value, center): string

Defined in: data-mate/src/function-configs/geo/sql-utils.ts:199

The great-circle distance in meters from the point column to center.

ST_Distance_Sphere expects WGS84 coordinates in (latitude, longitude) order, the opposite of the (x, y) order asGeometry passes to ST_Point. Swapping them gives a plausible wrong number rather than an error.

Parameters​

ParameterType
valuestring
center{ lat: number; lon: number; }
center.latnumber
center.lonnumber

Returns​

string


inBoundingBoxSql()​

inBoundingBoxSql(value, topLeft, bottomRight): string

Defined in: data-mate/src/function-configs/geo/sql-utils.ts:67

A bounding-box test as two inclusive range checks rather than a spatial predicate.

DuckDB's ST_Within and ST_Contains exclude the boundary, while turf's booleanPointInPolygon (used by inGeoBoundingBox) includes it, so a spatial predicate would disagree for a point on an edge. None is needed: createValidGeoBox builds only axis-aligned boxes and rejects one that crosses the antimeridian, so containment is a latitude range and a longitude range, both inclusive like turf.

Parameters​

ParameterType
valuestring
topLeft{ lat: number; lon: number; }
topLeft.latnumber
topLeft.lonnumber
bottomRight{ lat: number; lon: number; }
bottomRight.latnumber
bottomRight.lonnumber

Returns​

string


isGeoArg()​

isGeoArg(value): boolean

Defined in: data-mate/src/function-configs/geo/sql-utils.ts:114

True when the argument resolves to a shape that constantGeometry can build.

Parameters​

ParameterType
valueunknown

Returns​

boolean


isGeoColumn()​

isGeoColumn(inputConfig): boolean

Defined in: data-mate/src/function-configs/geo/sql-utils.ts:133

A column the geo predicates can turn into a geometry.

Parameters​

ParameterType
inputConfigDataTypeFieldAndChildren | undefined

Returns​

boolean


isGeoJSONColumn()​

isGeoJSONColumn(inputConfig): boolean

Defined in: data-mate/src/function-configs/geo/sql-utils.ts:14

Helpers for the SQL expressions of the geo function configs.

A GeoJSON column is stored as a GEOMETRY and a GeoPoint column as STRUCT(lat DOUBLE, lon DOUBLE) (see data-types/src/types/v1/). Shapes are parsed once at ingest, so these helpers read the stored value rather than parsing it again.

Parameters​

ParameterType
inputConfigDataTypeFieldAndChildren | undefined

Returns​

boolean


isGeoJSONSql()​

isGeoJSONSql(value): string

Defined in: data-mate/src/function-configs/geo/sql-utils.ts:27

isGeoJSON on a GeoJSON column: the stored geometry is one of the three shapes.

Ingest only accepts those three (geoShapeToWKB rejects anything else), so this is true for every non-null value. Reading the type instead of assuming it costs nothing.

Parameters​

ParameterType
valuestring

Returns​

string


isGeoPointColumn()​

isGeoPointColumn(inputConfig): boolean

Defined in: data-mate/src/function-configs/geo/sql-utils.ts:49

Parameters​

ParameterType
inputConfigDataTypeFieldAndChildren | undefined

Returns​

boolean


isGeoShapeSql()​

isGeoShapeSql(value, shape): string

Defined in: data-mate/src/function-configs/geo/sql-utils.ts:40

True when the stored geometry is the given shape.

This intentionally differs from DataFrame. isGeoShapePoint compares the stored type string exactly against 'Point' and 'point', and DataFrame keeps whatever spelling arrived, so { type: 'POINT' } is not a point there. A GEOMETRY stores the shape rather than the spelling, so this reports that value as a point. sql-emission-spec.ts lists it as a known difference.

Parameters​

ParameterType
valuestring
shape"POINT" | "POLYGON" | "MULTIPOLYGON"

Returns​

string


isScalarColumn()​

isScalarColumn(inputConfig): boolean

Defined in: data-mate/src/function-configs/geo/sql-utils.ts:142

True for a column that holds one value per row. The FULL_VALUES predicates receive the whole value, which on an array column is a GEOMETRY[] that no ST_* function accepts. They decline it, and the UDF handles the list as DataFrame does.

Parameters​

ParameterType
inputConfigDataTypeFieldAndChildren | undefined

Returns​

boolean


pointPart()​

pointPart(value, part): string

Defined in: data-mate/src/function-configs/geo/sql-utils.ts:54

One member of the point struct.

Parameters​

ParameterType
valuestring
part"lat" | "lon"

Returns​

string


rangeInMeters()​

rangeInMeters(distance, unit): number | null

Defined in: data-mate/src/function-configs/geo/sql-utils.ts:186

A range in meters, or null when the unit has no factor here.

The SQL path intentionally differs from geoPointWithinRange. makeGeoCircle builds a 64-sided turf polygon and tests the point against it, which under-approximates the circle by about r * (1 - cos(pi/64)), roughly 1.2 km at 1000 km. For a 1000km range it reports a point 998.867 km away as out of range. A true distance test has no such error.

Parameters​

ParameterType
distanceunknown
unitunknown

Returns​

number | null


relationFunction()​

relationFunction(relation): string | null

Defined in: data-mate/src/function-configs/geo/sql-utils.ts:154

Parameters​

ParameterType
relationunknown

Returns​

string | null


tryPredicate()​

tryPredicate(expression): string

Defined in: data-mate/src/function-configs/geo/sql-utils.ts:128

Wraps a spatial predicate in try() so an unparseable shape gives null instead of failing the query.

ST_GeomFromGeoJSON throws on a non-canonical type spelling such as {"type":"POINT","coordinates":[10,20]}, and a GeoJSON column can hold that spelling (coercion normalizes 'point' to 'Point' but leaves 'POINT'). In JavaScript, toGeoJSON cannot map it either and the predicate returns false. A validation nulls the row for both false and null, so try() makes the two paths agree.

Parameters​

ParameterType
expressionstring

Returns​

string