Skip to content

Instantly share code, notes, and snippets.

@shankerwangmiao
Created April 24, 2021 11:17
Show Gist options
  • Save shankerwangmiao/713d41fc2472f94b1ee2e1724399e69c to your computer and use it in GitHub Desktop.
Save shankerwangmiao/713d41fc2472f94b1ee2e1724399e69c to your computer and use it in GitHub Desktop.
GCJ-02 to WGS-84
def __out_of_china:
.lng > 73.66 and .lng < 135.05 and .lat > 3.86 and .lat < 53.55 | not;
def __PI: 3.1415926535897932384626;
def __transformlng:
300.0 + .lng + 2.0 * .lat + 0.1 * .lng * .lng + 0.1 * .lng * .lat + 0.1 * (.lng | fabs | sqrt) +
(20.0 * (6.0 * .lng * __PI | sin) + 20.0 * (2.0 * .lng * __PI | sin)) * 2.0 / 3.0 +
(20.0 * (.lng * __PI | sin) + 40.0 * (.lng / 3.0 * __PI | sin)) * 2.0 / 3.0 +
(150.0 * (.lng / 12.0 * __PI | sin) + 300.0 * (.lng / 30.0 * __PI | sin)) * 2.0 / 3.0;
def __transformlat:
-100.0 + 2.0 * .lng + 3.0 * .lat + 0.2 * .lat * .lat + 0.1 * .lng * .lat + 0.2 * (.lng | fabs | sqrt) +
(20.0 * (6.0 * .lng * __PI | sin) + 20.0 * (2.0 * .lng * __PI | sin)) * 2.0 / 3.0 +
(20.0 * (.lat * __PI | sin) + 40.0 * (.lat / 3.0 * __PI | sin)) * 2.0 / 3.0 +
(160.0 * (.lat / 12.0 * __PI | sin) + 320 * (.lat * __PI / 30.0 | sin)) * 2.0 / 3.0;
def gcj02towgs84:
if . | __out_of_china then
.
else
{ee: 0.00669342162296594323, a: 6378245.0} as {$ee, $a} |
{dlat: {lng: (.lng - 105.0), lat: (.lat - 35.0)} | __transformlat} as {$dlat} |
{dlng: {lng: (.lng - 105.0), lat: (.lat - 35.0)} | __transformlng} as {$dlng} |
{radlat: (.lat / 180.0 * __PI)} as {$radlat} |
{magic: $radlat | sin | (1 - $ee * . * .)} as {$magic} |
{sqrtmagic: $magic | sqrt} as {$sqrtmagic} |
{dlat: (($dlat * 180.0) / (($a * (1 - $ee)) / ($magic * $sqrtmagic) * __PI))} as {$dlat} |
{dlng: (($dlng * 180.0) / ($a / $sqrtmagic * ($radlat | cos) * __PI))} as {$dlng} |
{lng: (.lng - $dlng), lat: (.lat - $dlat)}
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment