Skip to content

postile

A pgrx PostgreSQL extension for map-tile generation helpers and gzip/Brotli bytea compression.

postile · A pgrx PostgreSQL extension for map-tile generation helpers and gzip/Brotli bytea compression.

Overview

IDExtensionPackageVersionCategoryLicenseLanguage
100823postilepostile0.0.1GISMITRust

PostgreSQL · 13, 14, 15, 16, 17, 18

Usage

Sources:

postile is a pgrx extension for producing map-layer tile bytes and compressing binary payloads inside PostgreSQL. Version 0.0.1 exposes a compact, evolving SQL surface; treat the current source, rather than the general project description alone, as the API contract.

Core Workflow

Install the extension in each database that generates tiles. For a table whose coordinates are already in tile space, encode its rows as one MapLibre Tile layer:

CREATE EXTENSION postile;

CREATE TABLE tile_features (
  id bigint PRIMARY KEY,
  geom point NOT NULL,
  name text,
  rank integer
);

INSERT INTO tile_features VALUES
  (1, point(10, 20), 'one', 7),
  (2, point(30, 40), 'two', 9);

SELECT PT_AsMLT(
  'tile_features'::regclass,
  'places',
  4096,
  'geom',
  'id'
);

PT_AsMLT reads every non-null geometry row from the named relation. Its arguments select the relation, layer name, extent, geometry column, and optional integer feature-ID column. Scalar boolean, integer, floating-point, text, varchar, and character columns become feature properties; unsupported property types are skipped.

Compression Helpers

The extension also provides immutable, parallel-safe compression helpers that return bytea:

SELECT pt_gzip('Hello, world!'::bytea);
SELECT pt_gzip('Hello, world!'::bytea, 9);
SELECT pt_brotli('Hello, world!'::bytea);
SELECT pt_version();
  • pt_gzip accepts an optional compression level from 0 through 9 and uses the library default when it is omitted.
  • pt_brotli uses the implementation’s fixed Brotli parameters.
  • pt_version returns the compiled extension version.

Geometry and Operational Boundaries

Native PostgreSQL point values are accepted directly. Other geometry columns are read through ST_AsEWKB, so they require an environment that supplies that function, normally PostGIS. Point, linestring, polygon, multipoint, multilinestring, and multipolygon EWKB are handled; geometry collections are rejected. Coordinates are rounded to signed 32-bit tile coordinates, and Z/M ordinates are ignored after parsing.

PT_AsMLT constructs a query over the supplied relation and materializes its result into one encoded layer. Filter and transform source rows into a bounded relation or view before calling it; do not point it at an unbounded base table. The current implementation does not perform Web Mercator projection, tile clipping, or tile-envelope filtering for you.

The control file marks the extension non-relocatable, superuser-only, and untrusted, with no preload setting. It does not declare PostGIS as an extension dependency even though non-native geometries rely on ST_AsEWKB. Test generated bytes with the intended tile consumer, and pin an upstream revision because the 0.0.1 API is still changing.

Table reader