These functions convert an ordinary (non-temporal) geometry into the cell or cell set that covers it at a given resolution, and test whether a temporal cell trajectory ever enters that cell set. The cell-set output together with the ever-intersects predicate form the cross-platform spatial prefilter used by the portable BerlinMOD queries.
Return the cell of a grid that contains a point geometry at the given resolution
latLngToCell(geometry,resolution integer) → h3index geoToQuadbinCell(geometry,integer) → quadbin geoToS2Cell(geography,integer) → s2cell
The geometry must be a non-empty POINT, its longitude and latitude are interpreted in SRID 4326, and the resolution lies between 0 and 15 for H3, 0 and 26 for QUADBIN, and 0 and 30 for S2; any other argument raises an error. The H3 form takes the name of the h3-pg function h3_latlng_to_cell; QUADBIN and S2 have no host extension, and their forms keep the names MobilityDB gives them.
SELECT latLngToCell(geometry 'SRID=4326;Point(4.35 50.85)', 7); -- 871fa4418ffffff SELECT geoToQuadbinCell(geometry 'SRID=4326;Point(4.35 50.85)', 10); -- 48a6227affffffff SELECT geoToS2Cell(geography 'SRID=4326;Point(4.35 50.85)', 10); -- 47c3c3
Return the set of cells of a grid covering a geometry at the given resolution
geoToH3IndexSet(geometry,integer) → h3indexset geoToQuadbinSet(geometry,integer) → quadbinset geoToS2CellSet(geography,integer) → s2cellset
The set holds the cells that hold a point of the geometry, each point assigned to its cell as latLngToCell, geoToQuadbinCell or geoToS2Cell assigns it. It is the set a temporal cell of a trajectory takes its values from, so a cell set test against it never misses a trajectory sharing a point with the geometry. A POINT yields a single cell, a LINESTRING the cells its segments pass through, a POLYGON those of its rings together with those it encloses, and MULTI* / GEOMETRYCOLLECTION values return the union of their components. A curve, a TIN or a TRIANGLE, alone or inside a collection, is refused, since a cover omitting its cells would drop a trajectory the prefilter must keep. H3 walks each segment from cell to cell across the edges of the cells, and for a polygon takes the cells holding no point of a ring whose centre the polygon holds, reading them outwards from the cells of the rings. A QUADBIN tile is bounded by two meridians and two parallels, so QUADBIN walks each segment from tile to tile and fills the rows of tiles between the boundary tiles of a polygon. An S2 cell is bounded by four arcs of great circles, the path a geodetic segment follows, so S2 walks each segment of a geography from cell to cell and reads the cube faces down the cell hierarchy for the cells a polygon encloses. This covering is the one a spatial prefilter needs, where the h3-pg function h3_polygon_to_cells answers the cells whose centre a polygon holds, which is why the name stays MobilityDB's.
SELECT geoToH3IndexSet(geometry 'SRID=4326;Point(4.35 50.85)', 7);
-- {"871fa4418ffffff"}
SELECT geoToQuadbinSet(geometry 'SRID=4326;Point(4.35 50.85)', 10);
-- {"48a6227affffffff"}
SELECT geoToS2CellSet(geography 'SRID=4326;Point(4.35 50.85)', 10);
-- {"47c3c3"}
Return whether a temporal cell trajectory ever takes one of the cells in a cell set
h3indexset ?= th3index → boolean quadbinset ?= tquadbin → boolean s2cellset ?= ts2cell → boolean
Combined with the cell set constructor it answers whether a trip ever passes through a region without materialising the trajectory geometry, a conservative prefilter for the exact eIntersects. It rests on a kernel every grid shares.
SELECT geoToH3IndexSet(geometry 'SRID=4326;Point(4.35 50.85)', 7) ?= th3index '871fa4418ffffff@2001-01-01'; -- t SELECT geoToQuadbinSet(geometry 'SRID=4326;Point(4.35 50.85)', 10) ?= tquadbin '48a6227affffffff@2001-01-01'; -- t SELECT geoToS2CellSet(geography 'SRID=4326;Point(4.35 50.85)', 10) ?= ts2cell '47c3c3@2001-01-01'; -- t