H3 hexagonal indexing and PostGIS-compatible spatial functions built directly into SQL. Convert coordinates to hexagons, calculate distances, test containment, and run spatial joins at billion-point scale.
Complete H3 functionality exposed as SQL functions
h3_latlng_to_cell(lat, lng, res)
Convert coordinates to H3 cell index
h3_cell_to_latlng(cell)
Get center coordinates of a cell
h3_cell_to_boundary(cell)
Get polygon boundary of a cell
h3_get_resolution(cell)
Get resolution level of a cell
h3_cell_to_parent(cell, res)
Get parent cell at coarser resolution
h3_cell_to_children(cell, res)
Get child cells at finer resolution
h3_grid_distance(cell1, cell2)
Calculate grid distance between cells
h3_grid_path(cell1, cell2)
Get cells along path between two cells
Powerful spatial analysis capabilities
Navigate the hexagonal grid efficiently.
Fill and analyze polygon regions.
Multi-resolution analysis capabilities.
Analyze individual cell characteristics.
Choose the right resolution for your use case
Res 0-3
Continental / Country
Res 4-6
State / Province
Res 7-8
City / District
Res 9-10
Neighborhood / Block
Res 11-12
Building / Parcel
Res 13-15
Room / Sub-meter
Real-world applications of H3 indexing
Automatically skip irrelevant files in spatial queries
18+ standard st_* functions for distance, containment, area, and geometry operations
st_distance(geom1, geom2)
Distance between two points
st_bearing(geom1, geom2)
Compass bearing between points
st_contains(geom, point)
Point-in-polygon testing
st_within(geom1, geom2)
Containment testing
st_area(polygon)
Area of a polygon
st_centroid(geometry)
Center point of a geometry
st_buffer(geom, distance)
Buffer zone around a point
st_intersection(geom1, geom2)
Geometry intersection
st_union(geom1, geom2)
Merge geometries
st_length(linestring)
Length of a linestring
st_point(x, y)
Construct a point from coordinates
st_envelope(geometry)
Bounding box of a geometry
Standard SQL syntax for real-world geospatial queries
Calculate the great-circle distance between two named locations.
-- Calculate distance between two ports
SELECT st_distance(
st_point(port_a.lon, port_a.lat),
st_point(port_b.lon, port_b.lat)
) AS distance_km
FROM ports port_a, ports port_b
WHERE port_a.name = 'Rotterdam'
AND port_b.name = 'Shanghai';
Find all warehouses that fall within a delivery zone polygon.
-- Find warehouses within a delivery zone
SELECT w.name, w.location
FROM warehouses w, delivery_zones dz
WHERE st_contains(dz.polygon, w.location)
AND dz.region = 'EMEA';
Create a radius around a point and find nearby features.
-- Find stores within 5 km of a landmark
SELECT s.name, s.address
FROM stores s, landmarks l
WHERE st_within(
s.location,
st_buffer(l.location, 5.0)
) AND l.name = 'Central Station';
Compute polygon areas and center points for planning.
-- Rank districts by area, show center
SELECT name,
st_area(boundary) AS area_km2,
st_centroid(boundary) AS center
FROM districts
ORDER BY area_km2 DESC
LIMIT 10;
Start building with H3 indexing and spatial SQL functions today.