pg_eviltransform
Overview
| Package | Version | Category | License | Language |
|---|---|---|---|---|
pg_eviltransform | 0.0.4 | GIS | MIT | Rust |
| ID | Extension | Bin | Lib | Load | Create | Trust | Reloc | Schema |
|---|---|---|---|---|---|---|---|---|
| 1580 | pg_eviltransform | No | Yes | No | Yes | No | Yes | eviltransform_internal |
| Related | postgis postgis pgrouting pg_geohash h3 q3c earthdistance tzf geoip |
|---|
Version
| Type | Repo | Version | PG Ver | Package | Deps |
|---|---|---|---|---|---|
| EXT | PIGSTY | 0.0.4 | 1817161514 | pg_eviltransform | postgis |
| RPM | PIGSTY | 0.0.4 | 1817161514 | pg_eviltransform_$v | postgis36_$v |
| DEB | PIGSTY | 0.0.4 | 1817161514 | postgresql-$v-eviltransform | postgresql-$v-postgis |
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
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)andST_EvilTransform(geometry, text, integer|text): four overloads corresponding to the PostGISST_Transforminterface.ST_JenksBins(values[], breaks [, invert]): classifies an array and returnsdouble precision[]edges.ST_JenksBins(value, breaks [, invert]): streaming aggregate that avoids materializingarray_agg.- PostGIS is a runtime prerequisite and must be installed before
pg_eviltransform. - Jenks inputs must be finite and
breaksmust be at least one.numericvalues are converted to finitef64, 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 returnNULL.
Feedback
Was this page helpful?
Thanks for the feedback! Please let us know how we can improve.
Sorry to hear that. Please let us know how we can improve.