@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
| Parameter | Type |
|---|---|
value | string |
inputConfig | DataTypeFieldAndChildren |
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
| Parameter | Type |
|---|---|
value | unknown |
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
| Parameter | Type |
|---|---|
value | string |
center | { lat: number; lon: number; } |
center.lat | number |
center.lon | number |
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
| Parameter | Type |
|---|---|
value | string |
topLeft | { lat: number; lon: number; } |
topLeft.lat | number |
topLeft.lon | number |
bottomRight | { lat: number; lon: number; } |
bottomRight.lat | number |
bottomRight.lon | number |
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
| Parameter | Type |
|---|---|
value | unknown |
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
| Parameter | Type |
|---|---|
inputConfig | DataTypeFieldAndChildren | 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
| Parameter | Type |
|---|---|
inputConfig | DataTypeFieldAndChildren | 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
| Parameter | Type |
|---|---|
value | string |
Returns
string
isGeoPointColumn()
isGeoPointColumn(
inputConfig):boolean
Defined in: data-mate/src/function-configs/geo/sql-utils.ts:49
Parameters
| Parameter | Type |
|---|---|
inputConfig | DataTypeFieldAndChildren | 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
| Parameter | Type |
|---|---|
value | string |
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
| Parameter | Type |
|---|---|
inputConfig | DataTypeFieldAndChildren | 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
| Parameter | Type |
|---|---|
value | string |
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
| Parameter | Type |
|---|---|
distance | unknown |
unit | unknown |
Returns
number | null
relationFunction()
relationFunction(
relation):string|null
Defined in: data-mate/src/function-configs/geo/sql-utils.ts:154
Parameters
| Parameter | Type |
|---|---|
relation | unknown |
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
| Parameter | Type |
|---|---|
expression | string |
Returns
string