Skip to content
Geospatial

Geospatial SQL Engine

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.

16 resolution levels (continent to sub-meter)
H3-aware data skipping for fast queries
Native implementation - no external deps
18+ PostGIS-compatible st_* spatial functions
Resolution Res 0 1,107 km Res 7 1.2 km Res 9 174 m 15 0.5 m Index Stats Cells indexed 2.4M Query time 12ms Spatial Aggregation Query SELECT h3_latlng_to_cell (lat, lng, 9 ) AS cell, COUNT(*) FROM locations GROUP BY cell ORDER BY 2 DESC

H3 SQL Functions

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

Spatial Operations

Powerful spatial analysis capabilities

Grid Traversal

Navigate the hexagonal grid efficiently.

  • h3_hex_ring - Get ring of cells at distance k
  • h3_hex_disk - Get all cells within distance k
  • h3_grid_path - Path between two cells
  • Neighbor traversal functions
  • Distance calculations
  • Ring and disk iterators

Polygon Operations

Fill and analyze polygon regions.

  • h3_polyfill - Fill polygon with cells
  • h3_cells_to_boundary - Merge cells to polygon
  • Compact cell sets
  • Uncompact to target resolution
  • Polygon containment tests
  • Area calculations

Hierarchical Operations

Multi-resolution analysis capabilities.

  • Parent/child cell navigation
  • Resolution change operations
  • Center child calculation
  • Hierarchy containment
  • Multi-scale aggregation
  • Zoom level management

Cell Properties

Analyze individual cell characteristics.

  • h3_cell_area - Area in km2 or m2
  • h3_edge_length - Edge length
  • h3_is_valid_cell - Validation
  • h3_is_pentagon - Pentagon check
  • h3_is_res_class_iii - Class check
  • Cell string conversion

Resolution Guide

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

Use Cases

Real-world applications of H3 indexing

Ride-Sharing

  • Surge pricing zones
  • Driver allocation
  • Demand prediction
  • Route optimization

Retail Analytics

  • Store catchment areas
  • Customer density analysis
  • Delivery zone planning
  • Competition mapping

IoT & Telemetry

  • Device location tracking
  • Sensor data aggregation
  • Coverage analysis
  • Movement patterns

Urban Planning

  • Population density
  • Infrastructure planning
  • Transit optimization
  • Environmental analysis

Real Estate

  • Property valuation
  • Market analysis
  • Neighborhood scoring
  • Development potential

Logistics

  • Delivery optimization
  • Warehouse placement
  • Fleet management
  • Last-mile routing

H3-Aware Data Skipping

Automatically skip irrelevant files in spatial queries

How It Works

  • Store H3 min/max per Parquet file
  • Query planner uses spatial predicates
  • Skip files outside query region
  • Works with all H3 functions

Performance Benefits

  • 10-100x faster spatial queries
  • Reduced I/O and memory
  • Works with petabyte datasets
  • No special partitioning needed

Supported Predicates

  • Cell equality and ranges
  • Parent/child containment
  • Distance-based filters
  • Polygon intersection

Integration

  • Automatic with Delta tables
  • Works with Z-ordering
  • Compatible with partitioning
  • Statistics in Delta log

PostGIS-Compatible Spatial Functions

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

Spatial SQL Examples

Standard SQL syntax for real-world geospatial queries

Distance Between Ports

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';

Point-in-Polygon Containment

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';

Buffer Zone Analysis

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';

Area and Centroid

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;

Power your location analytics

Start building with H3 indexing and spatial SQL functions today.