Geospatial

Operations happen in places. Shops have addresses, farms have parcels, a reefer run is a line across the island and then either the causeway or the ferry. The Ontology stores points, shapes and tracks as properties of objects, indexes them for spatial queries, turns movement into geofence events, and aggregates by area. This page covers the types, the query operators, how tracks and geofences work, and how location data is protected

TypesGeopoint, geoshape and geotemporal track
ReferenceWGS 84 coordinates, GeoJSON for shapes
QueriesDistance, box, polygon, intersection and nearest
GridsH3 cells for aggregation

In the platform today

Spatial filters on geopoint properties run in the platform service with tests. They are ordinary object set filters, so access labels, row policies and hidden properties apply as on any query. Markham Aviation's aircraft have a position, and the Live map in the Markham workspace asks the service for box and area selection and for what is near a selected object

OperatorBuilt behaviour
$nearWithin a distance of a point, in m, km or mi, by the haversine formula on a sphere of the Earth's mean radius
$inBoxInside a box by its corners, or south, west, north and east; a box can cross the antimeridian
$inAreaInside a GeoJSON Polygon or MultiPolygon, holes respected
$distanceA derived distance to a point, for orderBy and display
{
  "query": {
    "from": "shop",
    "where": { "position": { "$near": {
      "center": { "lat": 46.24, "lon": -63.13 },
      "distance": { "value": 100, "unit": "km" }
    } } },
    "steps": [{ "derive": { "km": { "$distance": {
      "property": "position",
      "to": { "lat": 46.24, "lon": -63.13 },
      "unit": "km"
    } } } }]
  },
  "orderBy": [{ "property": "km" }]
}

$inArea and $distance use the geodesic distance on the WGS 84 ellipsoid where the spatial engine is available, and a spherical fallback otherwise; the result says which ran. Geoshapes, tracks, geofences, $overlaps, $disjoint, H3 and geohash grids, the spatial index, vector tiles and location privacy on this page are delivered on request

Spatial property types

TypeHoldsCreamery example
geopointOne latitude and longitudeLocation of each Scoop shop and Dairy farm gate
geoshapeA GeoJSON geometry: Point, LineString, Polygon, MultiPolygon or GeometryCollectionA delivery zone, the ferry terminal yard, a farm's pasture parcels
geotemporal trackA series of positions with timestamps, speed and heading, stored like a time seriesThe GPS track of each Reefer delivery, a point every 30 s
H3 cell (derived)The H3 cell id of a point at a chosen resolutionposition.h3r7 for regional rollups of shop sales

Every coordinate is WGS 84, the system GPS receivers report. There is one trap worth naming: GeoJSON writes positions as longitude first, then latitude. The plant sits at about latitude 45.59, longitude −62.65, which is [-62.65, 45.59] in GeoJSON. The SDK's GeoPoint uses named fields, { lat, lon }, so the order cannot be swapped by accident in code

In ontology.yaml a point is a property with type: geopoint. On request, geoshapes and tracks are declared the same way

Validation

Spatial values are validated when the sync service writes them, and invalid ones go to the rejected rows dataset with the reason. Latitude must be within −90 to 90 and longitude within −180 to 180. Polygons must be closed, with the exterior ring counter-clockwise and holes clockwise. Rings that cross themselves are rejected with INVALID_GEOMETRY rather than repaired, because an automatic repair of a delivery zone can quietly change which shops it contains

Bringing spatial data in

Spatial values reach objects through pipelines like any other property

  • Formats. Pipelines read GeoJSON, well-known text, well-known binary, shapefiles and GeoPackage files, and plain latitude and longitude columns
  • Coordinate systems. Canadian government and municipal datasets are often published in NAD83(CSRS) or in a projected system such as a UTM zone or a provincial stereographic projection. A pipeline step reprojects them to WGS 84 before they reach a backing dataset, with the source system recorded in lineage, because the Ontology stores only WGS 84 and a shape in the wrong system can land kilometres away
  • Addresses. Addresses without coordinates can be geocoded in a pipeline step through a geocoding connector, and the match quality is stored beside the point so that low-confidence locations can be reviewed before a delivery zone depends on them

Very detailed shapes, such as a coastline traced to the metre, are simplified in the pipeline to the precision the operation needs. A delivery zone rarely needs more than a few hundred vertices, and every vertex costs index space and query time

How spatial data is indexed

Distance filters use the haversine formula on a sphere of the Earth's mean radius. When a result must be exact, such as a contractual delivery radius, the $distance derived property computes the geodesic distance on the WGS 84 ellipsoid. On request, points and shapes are indexed spatially, so distance, box and intersection queries read only the parts of the index that can match

Spatial queries

OperatorApplies toMatches
$nearGeopoint, geoshape, track latestWithin a distance of a point, in metres, kilometres or miles
$inBoxGeopoint, geoshapeInside a box given by its top-left and bottom-right corners
$inAreaGeopoint, geoshapeEntirely inside a polygon, holes respected
$overlapsGeoshape, geopointSharing any point with a geometry
$disjointGeoshape, geopointSharing no point with a geometry
$distance (derived)GeopointNot a filter: the geodesic distance to a point, for sorting and display
const creamery = { lat: 46.2382, lon: -63.1311 };

// Shops within 25 km of the creamery
const nearby = mso.objects(Shop)
  .where({ position: { $near: { center: creamery, distance: { value: 25, unit: "km" } } } });

// A truck has stopped. Which three open shops are closest to where it is now
const truck = await mso.objects(Delivery).one("DLV-5521");
const closest = await mso.objects(Shop)
  .where({ status: { $ne: "Closed" } })
  .derive({ km: { $distance: { property: "position", to: truck.position, unit: "km" } } })
  .page({ pageSize: 3, orderBy: "km" });

Polygons in filters are GeoJSON. This finds deliveries whose current position is inside the zone around the causeway approach

{
  "query": {"from": "delivery", "where": {
    "track.latest": {
      "$inArea": {
        "type": "Polygon",
        "coordinates": [
          [
            [-61.44, 45.63],
            [-61.39, 45.63],
            [-61.39, 45.66],
            [-61.44, 45.66],
            [-61.44, 45.63]
          ]
        ]
      }
    }
  }}
}

Spatial predicates are pushed down to the index like any other filter, and combine with property filters, text search and link traversals in one object set. Pass a geometry by reference instead of inline with { "$ref": { "objectType": "shop", "primaryKey": "SHP-HFX", "property": "deliveryZone" } }, which keeps zone definitions in the Ontology rather than copied into every query

Tracks

On request, tracks keep positions over time and say where an asset was, its path, where it stopped and when it entered an area

Geofences and events

On request, any area can be a geofence raising enter, exit and dwell events from tracks, buffered so GPS jitter causes no false events

Aggregation and maps

On request, three ways of grouping by place: H3 grids of hexagonal cells of near-equal area, which is what heat maps want; geohash grids, for compatibility with other tools; and grouping by containing shape, such as sales by delivery zone

Maps in the platform

The Live map in a workspace draws layers from object sets, and asks the service for box and area selection and for what is near a selected object. On request, vector tiles from the index, clustering at low zoom, a configurable base map and offline tile bundles for disconnected sites

Location privacy

A truck's track is also its driver's day. Location data about people is personal information under Canadian privacy law, including PIPEDA, and the Ontology gives you the controls to treat it that way

  • Field access. Hide a track from groups that do not need it. Dispatch sees live positions, the sales team does not
  • Precision reduction. On request, serve a coarsened position to some groups, snapped to an H3 cell at a chosen resolution, while others see full precision. Queries by those groups run against the coarsened value, so a narrow distance filter cannot recover the exact point
  • Short retention. On request, tracks are kept for less time than other series, while totals such as distance and dwell time are kept longer without the path itself
  • Access labels. Mark driver-linked tracks with an access label such as PII so they stay restricted in every derived dataset

Limitations

  • Only WGS 84 is stored. Data in NAD83(CSRS), UTM or other systems must be reprojected in a pipeline before it reaches a backing dataset
  • Invalid geometry, such as a self-intersecting ring, is rejected rather than repaired automatically
  • Distance filters use a spherical approximation, within 0.5% of the true distance. Exact geodesic distance is available only as the $distance derived property, for sorting and display, not as a filter
  • Grouping by containing shape is much slower than H3 or geohash grids on large sets
  • Geofence events are produced only from geotemporal tracks. A geopoint property that changes through sync or an action does not emit enter or exit events
  • Coarsened positions are served by group, not by person or by purpose, and a group that sees full precision sees it for every track it can read

The platform service allows up to 10,000 vertices in an $inArea polygon, or 2,000 where the spatial engine is not available. Other limits for spatial data are set per implementation, as described in limits and quotas

Related