Skip to content
pg_eviltransform

pg_eviltransform

pg_eviltransform : Coordinate transforms for BD09/GCJ02 via PostGIS ST_Transform

Overview

ID Extension Package Version Category License Language
1580
pg_eviltransform
pg_eviltransform
0.0.4
GIS
MIT
Rust
Attribute Has Binary Has Library Need Load Has DDL Relocatable Trusted
--s-d-r
No
Yes
No
Yes
yes
no
Relationships
Schemas eviltransform_internal
Requires
postgis
See Also
postgis
pgrouting
pg_geohash
h3
q3c
earthdistance
tzf
geoip

Packages

Type Repo Version PG Major Compatibility Package Pattern Dependencies
EXT
PIGSTY
0.0.4
18
17
16
15
14
pg_eviltransform postgis
RPM
PIGSTY
0.0.4
18
17
16
15
14
pg_eviltransform_$v postgis36_$v
DEB
PIGSTY
0.0.4
18
17
16
15
14
postgresql-$v-eviltransform postgresql-$v-postgis
Linux / PG PG18 PG17 PG16 PG15 PG14
el8.x86_64
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
el8.aarch64
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
el9.x86_64
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
el9.aarch64
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
el10.x86_64
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
el10.aarch64
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
d12.x86_64
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
d12.aarch64
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
d13.x86_64
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
d13.aarch64
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
u22.x86_64
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
u22.aarch64
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
u24.x86_64
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
u24.aarch64
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
u26.x86_64
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
u26.aarch64
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
PIGSTY 0.0.4
Package Version OS ORG SIZE File URL
pg_eviltransform_18 0.0.4 el8.x86_64 pigsty 918.9 KiB pg_eviltransform_18-0.0.4-1PIGSTY.el8.x86_64.rpm
pg_eviltransform_18 0.0.4 el8.aarch64 pigsty 819.2 KiB pg_eviltransform_18-0.0.4-1PIGSTY.el8.aarch64.rpm
pg_eviltransform_18 0.0.4 el9.x86_64 pigsty 926.7 KiB pg_eviltransform_18-0.0.4-1PIGSTY.el9.x86_64.rpm
pg_eviltransform_18 0.0.4 el9.aarch64 pigsty 871.2 KiB pg_eviltransform_18-0.0.4-1PIGSTY.el9.aarch64.rpm
pg_eviltransform_18 0.0.4 el10.x86_64 pigsty 926.8 KiB pg_eviltransform_18-0.0.4-1PIGSTY.el10.x86_64.rpm
pg_eviltransform_18 0.0.4 el10.aarch64 pigsty 849.0 KiB pg_eviltransform_18-0.0.4-1PIGSTY.el10.aarch64.rpm
postgresql-18-eviltransform 0.0.4 d12.x86_64 pigsty 737.3 KiB postgresql-18-eviltransform_0.0.4-1PIGSTY~bookworm_amd64.deb
postgresql-18-eviltransform 0.0.4 d12.aarch64 pigsty 611.9 KiB postgresql-18-eviltransform_0.0.4-1PIGSTY~bookworm_arm64.deb
postgresql-18-eviltransform 0.0.4 d13.x86_64 pigsty 737.2 KiB postgresql-18-eviltransform_0.0.4-1PIGSTY~trixie_amd64.deb
postgresql-18-eviltransform 0.0.4 d13.aarch64 pigsty 612.7 KiB postgresql-18-eviltransform_0.0.4-1PIGSTY~trixie_arm64.deb
postgresql-18-eviltransform 0.0.4 u22.x86_64 pigsty 816.9 KiB postgresql-18-eviltransform_0.0.4-1PIGSTY~jammy_amd64.deb
postgresql-18-eviltransform 0.0.4 u22.aarch64 pigsty 723.7 KiB postgresql-18-eviltransform_0.0.4-1PIGSTY~jammy_arm64.deb
postgresql-18-eviltransform 0.0.4 u24.x86_64 pigsty 810.9 KiB postgresql-18-eviltransform_0.0.4-1PIGSTY~noble_amd64.deb
postgresql-18-eviltransform 0.0.4 u24.aarch64 pigsty 715.0 KiB postgresql-18-eviltransform_0.0.4-1PIGSTY~noble_arm64.deb
postgresql-18-eviltransform 0.0.4 u26.x86_64 pigsty 806.7 KiB postgresql-18-eviltransform_0.0.4-1PIGSTY~resolute_amd64.deb
postgresql-18-eviltransform 0.0.4 u26.aarch64 pigsty 713.3 KiB postgresql-18-eviltransform_0.0.4-1PIGSTY~resolute_arm64.deb

Source

pig build pkg pg_eviltransform;		# build rpm/deb

Install

Make sure PGDG and PIGSTY repo available:

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

Install this extension with pig:

pig install pg_eviltransform;		# install via package name, for the active PG version

pig install pg_eviltransform -v 18;   # install for PG 18
pig install pg_eviltransform -v 17;   # install for PG 17
pig install pg_eviltransform -v 16;   # install for PG 16
pig install pg_eviltransform -v 15;   # install for PG 15
pig install pg_eviltransform -v 14;   # install for PG 14

Create this extension with:

CREATE EXTENSION pg_eviltransform CASCADE; -- requires postgis

Usage

Sources:

pg_eviltransform extends PostGIS with coordinate transformations involving China’s GCJ-02 and BD-09 systems. Version 0.0.4 also adds exact Jenks natural-break classification through ST_JenksBins array and aggregate overloads.

Coordinate Transformation

CREATE EXTENSION postgis;
CREATE EXTENSION pg_eviltransform;

-- WGS84 to GCJ-02 using a readable coordinate-system name.
SELECT ST_EvilTransform(
    ST_SetSRID('POINT(120 30)'::geometry, 4326),
    'GCJ02'
);

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

Custom SRIDs are 990001 for GCJ-02 and 990002 for BD-09. When neither endpoint uses a custom system, ST_EvilTransform delegates to PostGIS ST_Transform; otherwise it converts through WGS84 (4326) when necessary.

Jenks Natural Breaks

-- Array form; NULL elements are ignored.
SELECT ST_JenksBins(ARRAY[1, 2, NULL, 10, 11]::numeric[], 2);

-- Streaming aggregate form for a large table.
SELECT ST_JenksBins(value, 7)
FROM measurements;

-- Return lower rather than upper bin edges.
SELECT ST_JenksBins(value, 7, true)
FROM measurements;

Array inputs support numeric, double precision, real, bigint, integer, and smallint. Aggregate inputs are numeric or double precision; cast other numeric columns when needed.

API Index and Caveats

  • ST_EvilTransform(geometry, integer|text) and ST_EvilTransform(geometry, text, integer|text): four overloads corresponding to the PostGIS ST_Transform interface.
  • ST_JenksBins(values[], breaks [, invert]): classifies an array and returns double precision[] edges.
  • ST_JenksBins(value, breaks [, invert]): streaming aggregate that avoids materializing array_agg.
  • PostGIS is a runtime prerequisite and must be installed before pg_eviltransform.
  • Jenks inputs must be finite and breaks must be at least one. numeric values are converted to finite f64, so returned edges are floating-point values.
  • When the distinct value count does not exceed breaks, the result is the sorted set of unique values; no valid input rows return NULL.
Last updated on