People's Rectified Coordinates (PRCoords) is a cross-language implementation of "public secret" Chinese coordinate obfuscation methods including GCJ-02 and BD-09, along with general deobfuscation methods previously established in ChinaMapShift, eviltransform, and geoChina. (Referring to the process of replacing straight lines with wavy ones as a "transform" is euphemism overdone.)
For a background on China's geographic obfuscation, see Restrictions on geographic data in China and 中华人民共和国测绘限制 on Wikipedia.
npm install prcoords
)
__esModule
interop for Babel and TypeScript!pip install prcoords
)install
(should I split them into submodules?)
For languages not yet supported, we recommend you to check for eviltransform (MIT) or geoChina (GPLv3, R) instead.
PRCoord's APIs operate on, and returns, dedicated structures for coordinates. In API names, we generally refer to WGS-84 as wgs
, GCJ-02 as gcj
, and BD-09 (lat-lon) as bd
.
The obfuscations generally have these properties to maintain basic usefulness:
obfs(coord)
is sort of close to coord
.obfs(a) - obfs(b)
is usually close to a - b
. (The closer a
and b
are
to each other, the better it works.)In general two approaches of inverting the "forward" obfuscations, or working from
obfs(coord)
to coord
, are implemented:
obfs(coord)
is never too far from coord
, so just use
obfs(obfs(coord)) - obfs(coord)
to estimate obfs(coord) - coord
.guess
somehow, and just use property 2 to estimate
the remaining error as obfs(guess) - obfs(coord)
and correct the guess
.You can read on the demo page about how well these methods work from the ΔRoundtrip
entry. Unless you are doing archival work, you generally don't have to iterate.
Typically PRCoords is only supposed to be ran on obfuscated input data, which are primarily Chinese coordinates. For this reason, initial implementations include this very very rough sanity check that spans a rectangular region on a mercator-projected map. This check can be overridden by passing a boolean value, or may be not at all implemented in certain languages if I am not in the right mood for doing silly things.
There is an "insane" sanity check intended to approximate the range of Google
and Baidu's distortion, intended for use by IITC:
js/insane_is_in_china.js
.
It is basically a ray-casting polygon check with 70 vertices. You, as the
caller, should still be responsible for telling whether a point is part of the
gov-screwed Chinese data.
Not directly as a datum, because in both representations a datum is either "sane" (no non-linearity in 3D, Helmert possible) or a big table of grids.
It should be possible to describe the two CS with a PROJECTION
entry as
a PROJCS
. Since a PROJCS
cannot be nested in another, the BD
transformation must be described using WGS84 and a fuzed GCJ-BD projection.
The situation is similar with Baidu "Meractor".
The good people at proj4js has made their stuff very easy to extend. Here is an example.
Yes. Nobody knows what the original looks like anyways, so what's wrong with letting the compiler recombine a bit more? You can't be more off than the one-meter random error (in "EMQ") anyways.
Or tinker with 32-bit floats and fixed-point numbers. Or try approximation tools like Sollya or MC++. Really, just search on the Internet for "\<language> Taylor Chebyshev Model". You only need less than 1e-6 error on a not-very-large slice of the Earth anyways.
I threw TaylorModels.jl at GCJ-02, and got decent results out of it. Still too lazy to put it in code though. Check out approx/approx.ipynb. (Nope, not decent. Gotta do it properly some day, just don't use the notebook and expect it to work!)
I tried another route with the C++ version using a devmaster user Nick's sinpi()
approximation. It seems to be good enough for 1e-6: check out cpp/bench_out and cpp/badmath.hh.
You can print out a minimal copy of PRCoords with this PDF file. I am working on some better options in issue #2. A fairly simple tote bag with an older version of the PDF is available from Teespring.
Feel free to print and sell t-shirts with the PDF file! It is put in the Public Domain, so you don't have to pay me for that. You can always fund my subversive activities on Patreon though.
Unless otherwise mentioned, all files in this package, including this README file, are dual-licensed under:
GPL is only included for fun here.
sin
invocation and one LCG. Each add a maximum of 1 meter of error.Oh, and finally, here is an official news report on that particular [bleep] who came up with GCJ-02.