api reference
Geometry API Reference
type: 'geometry': WKB, WKT and GeoJSON read into one GeoJSON geometry per cell, a readable summary, WKT export, and four spatial filter operators.
API reference › The geometry module
All 18 pages Everything on one page → Developer guide →
The geometry module
import '@toclocoinc/lattice-grid/modules/geometry';
Importing the module registers the geometry data type with the page's registry
(geometryModule is the module object, for a grid built on a registry of its own).
Without it, type: 'geometry' warns type:geometry, naming this import,
and the column is plain text.
Spatial operators: geometry columns
A column declared type: 'geometry' holds one GeoJSON geometry per cell, read on
ingest from WKB (bytes, hex or base64), WKT or GeoJSON, and answers four operators of its own.
They are evaluated in memory, so they work over any source that does not push them down.
grid.filters.set({ col: 'site', op: 'withinBbox', value: [-4, 50, 2, 56] });
grid.filters.set({ col: 'site', op: 'withinPolygon', value: 'POLYGON ((…))' });
grid.filters.set({ col: 'site', op: 'intersects', value: { type: 'LineString', coordinates: [[-10, 41], [5, 41]] } });
grid.filters.set({ col: 'site', op: 'withinDistance', value: { lon: -0.1278, lat: 51.5074, metres: 5000 } });
| Operator | Operand | A row matches when |
|---|---|---|
withinBbox | [minLon, minLat, maxLon, maxLat] | the whole geometry lies inside the box, edges included |
withinPolygon | a Polygon or MultiPolygon, as GeoJSON or WKT | every point of a Point or MultiPoint is inside it (holes excluded); any other geometry is tested by its centroid |
intersects | any geometry, or a bbox array | the two share a point: a bounding-box test, then an edge test with edges straight in longitude/latitude rather than along great circles |
withinDistance | { lon, lat, metres } | the geometry's centroid is within that many metres, by great-circle (haversine) distance |
Refused, not guessed. A geometry column accepts these four and blank/notBlank; any other operator on it, a spatial operator on any other column, and an operand that cannot be read are refused by filters.set() and state.apply() with a [lattice] warning. A value that is not a geometry is refused on ingest the same way: the cell is blank and geometry:refused:<column> names why.
The antimeridian is not handled. A box whose west edge is east of its east edge is refused; split it into two withinBbox conditions joined by or. Distances and areas are on a sphere of the mean Earth radius, within about 0.5% of the WGS84 ellipsoid; the centroid is planar in degrees, as ST_Centroid on a geometry column is.