إنتقل إلى المحتوى الرئيسي

Indexing functions

These functions convert between geographic coordinates and Terra cell identifiers, and retrieve the geometry of a given cell.

latLngToCell​

Indexes the location at the specified resolution, returning the Terra Index String of the cell containing that point. For more information see the algorithm description.

terra.latlon_to_cell(lat, lng, res, datum='KSA-GRF17')
# Returns: str (Terra Index String)

# Riyadh — Masmak Fortress
cell = terra.latlon_to_cell(24.6877, 46.7219, 8)
# "t10830cd1943ffff8"

# Jeddah — Al-Balad historic district
cell = terra.latlon_to_cell(21.4858, 39.1862, 8)

# NEOM — Tabuk region
cell = terra.latlon_to_cell(27.9654, 35.2034, 8)

The datum parameter accepts 'KSA-GRF17' (default, EPSG:9333) or 'WGS84' (auto-converted).

cellToCenter​

Finds the geographic centre of a Terra cell in the LAEA projection, reprojected to WGS84 (or KSA-GRF17).

The centre returned is the centroid of the hexagonal cell. It will differ slightly from the original coordinates used to index the cell, because the cell covers a region rather than a point.

terra.cell_to_center(cell)
# Returns: (lat, lng) tuple

center = terra.cell_to_center("t10830cd1943ffff8")
# (24.6880, 46.7221)

cellToBoundary​

Returns the six vertices of the hexagonal cell boundary as (lat, lng) pairs.

terra.cell_to_boundary(cell)
# Returns: list of (lat, lng) tuples — 6 vertices

boundary = terra.cell_to_boundary("t10830cd1943ffff8")
# [(24.6935, 46.7177), (24.6963, 46.7253), (24.6908, 46.7328),
# (24.6825, 46.7326), (24.6797, 46.7250), (24.6852, 46.7176)]

For GeoJSON compatibility (lng/lat order), pass geo_json=True.

cellToSaudiCode​

Converts a Terra cell to its human-readable Terra Grid Code (TGC) — the T[RES]-[POSITION] string intended for citizens, maps, and dispatch systems. See the Saudi Grid Code guide for full documentation.

Terra-specific

The Saudi Grid Code is the citizen-facing half of the Terra addressing model. Use it wherever a code will be spoken, written on a form, or read off a screen; use the TIS everywhere else.

terra.cell_to_saudi_code(cell)
# Returns: str (Terra Grid Code)

code = terra.cell_to_saudi_code("t10830cd1943ffff8")
# "T08-0C6D351E"

# Reverse: TGC -> TIS
cell = terra.string_to_cell("T08-0C6D351E")
# "t10830cd1943ffff8"

The Terra System is designed and developed by Tec Solution KSA.