Skip to content

geotini

Encode GeoJSON geometries as compact URL-safe text

geotini · Encode GeoJSON geometries as compact URL-safe text

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
102480geotinigeotini0.1.0GISMITRust

PostgreSQL · 15, 16, 17, 18, 19

Usage

Sources:

This documents the native 0.1.0 source revision. It is unpublished, uses Rust/pgrx, and declares PostgreSQL 15–19 support on Linux/macOS; upstream tests on Linux. The control marks it trusted, so a role with database CREATE privilege can enable it after an administrator installs its files. It uses the fixed geotini schema and needs no preload or restart.

CREATE EXTENSION geotini;
SELECT geotini.geotini_version();
WITH encoded AS (
  SELECT geotini.geotini_encode(
    '{"type":"Point","coordinates":[13.40495,52.52001]}'::jsonb, 5) AS value
)
SELECT value, geotini.geotini_decode(value) FROM encoded;

Encoding and decoding

geotini_encode accepts a GeoJSON geometry as jsonb or text and returns compact URL-safe text. Use geotini_decode for GeoJSON, geotini_try_decode for NULL on invalid strings, and geotini_encode_wkb / geotini_decode_wkb for binary geometry input/output. A GeoJSON Feature must first be reduced to its geometry.

precision defaults to 5 and permits 0–15 decimal places; encoding rounds half away from zero. z_precision and m_precision default to -1, inheriting the main precision. checksum defaults to false. favor accepts default, size, or speed. Quote precision when using it as a named SQL argument.

SELECT geotini.geotini_encode(
  '{"type":"Point","coordinates":[13.40495,52.52001]}'::jsonb,
  "precision" => 6, checksum => true);
WITH encoded AS (
  SELECT geotini.geotini_encode_line(
    '{{38.5,-120.2},{40.7,-120.95}}'::float8[]) AS value
)
SELECT geotini.geotini_decode_line(value) FROM encoded;

geotini_encode_line and geotini_decode_line use latitude, longitude order in two-dimensional arrays, with optional Z and M columns. GeoJSON uses longitude, latitude. Encoded text carries no SRID; geotini_decode_wkb defaults to SRID 0. The functions are immutable, strict and parallel safe, permitting expression indexes and generated columns.

Boundaries and maintenance

GeoJSON-compatible points, lines, polygons, multi-geometries and collections are supported, with consistent coordinate dimensions and collection nesting up to 32. Curves, surfaces, TINs, triangles, XYM geometries, non-finite coordinates and inconsistent dimensions are rejected. Invalid encoded text raises SQLSTATE 22P02; invalid encoder input raises 22023. Decoding preserves the stored rounded coordinates, not any precision discarded during encoding.

This revision’s format-transition commit states that implementations other than the updated JavaScript implementation still need porting to the new vectors. Do not rely on the older PostgreSQL README’s cross-language byte-compatibility claim or treat this preview format as stable archival storage. There are no upgrade scripts yet. The alternative plain PL/pgSQL implementation shares the same schema and names and cannot coexist with the native extension; its PostgreSQL 12+ claim does not apply to this native extension. Optional PostGIS wrappers are supplied separately by geotini_postgis.

Table reader