Package: prcoords
PRCoordsPeople'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 inChinaMapShift,eviltransform, andgeoChina. (Referring to the process of replacing straight lines with wavy ones as a "transform" is euphemism overdone.)LanguagesJavaScript (npm install prcoords)Web demo:https://artoria2e5.github.io/PRCoords/demoPython (pip install prcoords)(Obj-)C/C++ (C structs)Makefile withinstallRubySwiftC#Haskell (GCJ only; data structure incomplete)need to move googollee/eviltransform#54 here sometime.JavaMatlab/Octavetoo lazy to split the files. also expand "caijun"PGSQLTyped Racketis it done?(should I split them into submodules?)For languages not yet supported, we recommend you to check foreviltransform(MIT) orgeoChina(GPLv3, R) instead.APIPRCoord's APIs operate on, and returns, dedicated structures for coordinates. In API names, we generally refer to WGS-84 aswgs, GCJ-02 asgcj, and BD-09 (lat-lon) asbd.Inverse functionsThe obfuscations generally have these properties to maintain basic usefulness:obfs(coord)is sort of close tocoord.obfs(a) - obfs(b)is usually close toa - b. (The closeraandbare
to each other, the better it works.)In general two approaches of inverting the "forward" obfuscations, or working fromobfs(coord)tocoord, are implemented:Run it backwards:obfs(coord)is never too far fromcoord, so just useobfs(obfs(coord)) - obfs(coord)to estimateobfs(coord) - coord.Iterate a bit: Get a roughguesssomehow, and just use property 2 to estimate
the remaining error asobfs(guess) - obfs(coord)and correct theguess.You can read on the demo page about how well these methods work from theΔRoundtripentry. Unless you are doing archival work, you generally don't have to iterate.The "in China" sanity checkTypically PRCoords is only supposed to be ran on obfuscated input data, which
are primarily Chinese coordinates. For this reason, initial implementations
include thisvery very roughsanity 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 byIITC: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.Why another wheel?Public DomainClean API based on pairs of coordinatesNeed to find a place for this sarcastic namePhysical PRCoordsYou can print out a minimal copy of PRCoords withthis PDF file. I am working on some better optionsin issue #2. A fairly simple tote bag with an older version of the PDF isavailable 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 onPatreonthough.LicenseUnless otherwise mentioned, all files in this package, including this README file,
are dual-licensed under:CC0 1.0 Public Domain DedicationGNU General Public License (version 3 or up)GPL is only included for fun here.SourcesAlgorithm.Coords.ConverterfromEMQ(GitHub mirror) is probablytheGCJ leak. It is a JSP project "for demonstrating GIS systems", probably done by some government contractor.There is some randomness in the GCJ deltas on both axes: onesininvocation and one LCG. Each add a maximum of 1 meter of error.on4wp7(2013) is the earliest rationalized GCJ (forward) implementation. No randomness is attempted.ChinaMapShift(2014) figured out the quick iterative inverse for GCJ. I learned about it via geoChina first and generalized it here.BD-09 is not very well sourced, butpycoordtrans(2014) seems to have it.See alsoRestrictions on geographic data in China: this Wikipedia article outlines impacts and the "common secret" deobfuscation approach.Chinese readers: see中华人民共和国测绘限制.eviltransformis among the most popular cross-language soltions to the problem. It borrows its name directly fromEvilTransform.cs, an early refactored version of a raw-flesh Java implementation found in "emq", some sort of government contractor GIS demo project.Since June 2016, eviltransform contains numerous parameter errors that compromise its output, especially for BD-09. See googollee/eviltransform#43,#53and#44for corrections. As of June 2019 these problems are not fixed.geoChinaby caijun is a clear, concise implementation written in R. It features the iterative method from ChinaMapShift.I am planning on moving some of the comments on the algorithm found inmy initial JavaScript implementationto theGitHub Wiki. I don't think anyone is going to be interested in copying comments on these idiocy when translating my implementation to other languages.
** If you are doing a translation, consider only using the comments from the PDF.Oh, and finally, here is an officialnews reporton that particular[bleep]who came up with GCJ-02.