pg_eviltransform

Coordinate transforms for BD09/GCJ02 via PostGIS ST_Transform

Overview

PackageVersionCategoryLicenseLanguage
pg_eviltransform0.0.2GISMITRust
IDExtensionBinLibLoadCreateTrustRelocSchema
1580pg_eviltransformNoYesNoYesYesNoeviltransform_internal
Relatedpostgis postgis pgrouting pg_geohash h3 q3c earthdistance tzf geoip

Version

TypeRepoVersionPG VerPackageDeps
EXTPIGSTY0.0.21817161514pg_eviltransformpostgis
RPMPIGSTY0.0.21817161514pg_eviltransform_$vpostgis36_$v
DEBPIGSTY0.0.21817161514postgresql-$v-eviltransformpostgresql-$v-postgis
OS / PGPG18PG17PG16PG15PG14
el8.x86_64
el8.aarch64
el9.x86_64
el9.aarch64
el10.x86_64
el10.aarch64
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2
d12.x86_64
d12.aarch64
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2
d13.x86_64
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2
d13.aarch64
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2
u22.x86_64
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2
u22.aarch64
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2
u24.x86_64
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2
u24.aarch64
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2
PIGSTY 0.0.2

Build

You can build the RPM / DEB packages for pg_eviltransform using pig build:

pig build pkg pg_eviltransform         # build RPM / DEB packages

Install

You can install pg_eviltransform directly. First, make sure the PGDG and PIGSTY repositories are added and enabled:

pig repo add pgsql -u          # Add repo and update cache

Install the extension using pig or apt/yum/dnf:

pig install pg_eviltransform;          # Install for current active PG version
pig ext install -y pg_eviltransform -v 18  # PG 18
pig ext install -y pg_eviltransform -v 17  # PG 17
pig ext install -y pg_eviltransform -v 16  # PG 16
pig ext install -y pg_eviltransform -v 15  # PG 15
pig ext install -y pg_eviltransform -v 14  # PG 14
dnf install -y pg_eviltransform_18       # PG 18
dnf install -y pg_eviltransform_17       # PG 17
dnf install -y pg_eviltransform_16       # PG 16
dnf install -y pg_eviltransform_15       # PG 15
dnf install -y pg_eviltransform_14       # PG 14
apt install -y postgresql-18-eviltransform   # PG 18
apt install -y postgresql-17-eviltransform   # PG 17
apt install -y postgresql-16-eviltransform   # PG 16
apt install -y postgresql-15-eviltransform   # PG 15
apt install -y postgresql-14-eviltransform   # PG 14

Create Extension:

CREATE EXTENSION pg_eviltransform CASCADE;  -- requires: postgis

Usage

pg_eviltransform: Coordinate transform between WGS84, GCJ02, and BD09

pg_eviltransform extends PostGIS ST_Transform with BD09/GCJ02 support for Chinese coordinate systems. It exposes ST_EvilTransform with the same overload interface as ST_Transform.

Custom SRIDs:

  • 990001: GCJ02
  • 990002: BD09

Functions

ST_EvilTransform(geometry, to_srid integer)
ST_EvilTransform(geometry, to_proj text)
ST_EvilTransform(geometry, from_proj text, to_srid integer)
ST_EvilTransform(geometry, from_proj text, to_proj text)

If neither side uses custom coordinates, it delegates directly to ST_Transform. If BD09/GCJ02 is involved, it transforms via WGS84 (4326) when needed.

Examples

-- WGS84 to GCJ02 using text literal
SELECT ST_EvilTransform(ST_SetSRID('POINT(120 30)'::geometry, 4326), 'GCJ02');

-- WGS84 to BD09 using text literal
SELECT ST_EvilTransform(ST_SetSRID('POINT(120 30)'::geometry, 4326), 'BD09');

-- WGS84 to GCJ02 using numeric SRID
SELECT ST_EvilTransform(ST_SetSRID('POINT(120 30)'::geometry, 4326), 990001);

-- BD09 to Web Mercator
SELECT ST_EvilTransform(
  ST_SetSRID('POINT(120.011070620552 30.0038830555128)'::geometry, 990002), 3857
);

-- from_proj / to_proj overload
SELECT ST_EvilTransform('POINT(120 30)'::geometry, 'EPSG:4326', 'GCJ02');

Performance

On PG18 with 200,000 rows, ST_EvilTransform is ~30-45x faster than the regex-based SQL approach.


Last Modified 2026-03-12: add pg extension catalog (95749bf)