Giter Club home page Giter Club logo

eviltransform's Introduction

Transform coordinate between earth(WGS-84) and mars in china(GCJ-02).

GCJ-02 coordiante is used by Google Maps, Autonavi Map and other china map service. (Baidu Map has an extra offset based on GCJ-02)

WGStoGCJ/wgs2gcj

func WGStoGCJ(wgsLat, wgsLng float64) (gcjLat, gcjLng float64) // Go/Golang
void wgs2gcj(double wgsLat, double wgsLng, double *gcjLat, double *gcjLng) // C/C++/Obj-C
eviltransform.wgs2gcj(wgsLat, wgsLng) // JavaScript/Python
\larryli\eviltransform\EvilTransform::WGStoGCJ($wgsLat, $wgsLng) // PHP5.4+
EvilTransform.Transform.WGS2GCJ(wgsLat, wgsLng) // CSharp
wgs2Gcj (gcjLat, gcjLng) // Haskell

Input WGS-84 coordinate(wgsLat, wgsLng) and convert to GCJ-02 coordinate(gcjLat, gcjLng). The output of JavaScript is like:

{"lat": xx.xxxx, "lng": yy.yyyy}

GCJtoWGS/gcj2wgs

func GCJtoWGS(gcjLat, gcjLng float64) (wgsLat, wgsLng float64) // Go/Golang
void gcj2wgs(double gcjLat, double gcjLng, double *wgsLat, double *wgsLnt) // C/C++/Obj-C
eviltransform.gcj2wgs(gcjLat, gcjLng) // JavaScript/Python
\larryli\eviltransform\EvilTransform::GCJtoWGS($gcjLat, $gcjLng) // PHP5.4+
EvilTransform.Transform.GCJ2WGS(gcjLat, gcjLng) //CSharp
gcj2Wgs (gcjLat, gcjLng) // Haskell

Input GCJ-02 coordinate(gcjLat, gcjLng) and convert to WGS-84 coordinate(wgsLat, wgsLng). The output of JavaScript is like:

{"lat": xx.xxxx, "lng": yy.yyyy}

The output WGS-84 coordinate's accuracy is 1m to 2m. If you want more exactly result, use GCJtoWGSExact/gcj2wgs_exact.

GCJtoWGSExact/gcj2wgs_exact

func GCJtoWGSExact(gcjLat, gcjLng float64) (wgsLat, wgsLng float64) // Go/Golang
void gcj2wgs_exact(double gcjLat, double gcjLng, double *wgsLat, double *wgsLnt) // C/C++/Obj-C
eviltransform.gcj2wgs_exact(gcjLat, gcjLng) // JavaScript/Python
\larryli\eviltransform\EvilTransform::GCJtoWGSExact($gcjLat, $gcjLng) // PHP5.4+
EvilTransform.Transform.GCJ2WGSExact(gcjLat, gcjLng) //CSharp
gcj2WgsExact (gcjLat, gcjLng) //Haskell

Input GCJ-02 coordinate(gcjLat, gcjLng) and convert to WGS-84 coordinate(wgsLat, wgsLng). The output of JavaScript is like:

{"lat": xx.xxxx, "lng": yy.yyyy}

The output WGS-84 coordinate's accuracy is less than 0.5m, but much slower than GCJtoWGS/gcj2wgs.

Distance/distance

func Distance(latA, lngA, latB, lngB float64) float64 // Go/Golang
double distance(double latA, double lngA, double latB, double lngB) // C/C++/Obj-C
eviltransform.distance(latA, lngA, latB, lngB) // JavaScript/Python
\larryli\eviltransform\EvilTransform::Distance($latA, $lngA, $latB, $lngB) // PHP5.4+
EvilTransform.Transform.Distance(latA, lngA, latB, lngB) //CSharp
distance (lat, lng)

Calculate the distance between point(latA, lngA) and point(latB, lngB), unit in meter.

Original from:

See also:


地球坐标(WGS-84)与火星坐标(GCJ-2)转换.

GCJ-02坐标用在谷歌地图,高德地图等**地图服务。(百度地图要在GCJ-02基础上再加转换)

WGStoGCJ/wgs2gcj

func WGStoGCJ(wgsLat, wgsLng float64) (gcjLat, gcjLng float64) // Go/Golang
void wgs2gcj(double wgsLat, double wgsLng, double *gcjLat, double *gcjLng) // C/C++/Obj-C
eviltransform.wgs2gcj(wgsLat, wgsLng) // JavaScript/Python
\larryli\eviltransform\EvilTransform::WGStoGCJ($wgsLat, $wgsLng) // PHP5.4+
EvilTransform.Transform.WGS2GCJ(wgsLat, wgsLng) // CSharp
wgs2Gcj (gcjLat, gcjLng) // Haskell

输入WGS-84地球坐标(wgsLat, wgsLng),转换为GCJ-02火星坐标(gcjLat, gcjLng)。JavaScript输出格式如下:

{"lat": xx.xxxx, "lng": yy.yyyy}

GCJtoWGS/gcj2wgs

func GCJtoWGS(gcjLat, gcjLng float64) (wgsLat, wgsLng float64) // Go/Golang
void gcj2wgs(double gcjLat, double gcjLng, double *wgsLat, double *wgsLnt) // C/C++/Obj-C
eviltransform.gcj2wgs(gcjLat, gcjLng) // JavaScript/Python
\larryli\eviltransform\EvilTransform::GCJtoWGS($gcjLat, $gcjLng) // PHP5.4+
EvilTransform.Transform.GCJ2WGS(gcjLat, gcjLng) //CSharp
gcj2Wgs (gcjLat, gcjLng) // Haskell

输入GCJ-02火星坐标(gcjLat, gcjLng),转换为WGS-84地球坐标(wgsLat, wgsLng)。JavaScript输出格式如下:

{"lat": xx.xxxx, "lng": yy.yyyy}

输出的WGS-84坐标精度为1米到2米之间。如果要更精确的结果,使用GCJtoWGSExact/gcj2wgs_exact。

GCJtoWGSExact/gcj2wgs_exact

func GCJtoWGSExact(gcjLat, gcjLng float64) (wgsLat, wgsLng float64) // Go/Golang
void gcj2wgs_exact(double gcjLat, double gcjLng, double *wgsLat, double *wgsLnt) // C/C++/Obj-C
eviltransform.gcj2wgs_exact(gcjLat, gcjLng) // JavaScript/Python
\larryli\eviltransform\EvilTransform::GCJtoWGSExact($gcjLat, $gcjLng) // PHP5.4+
EvilTransform.Transform.GCJ2WGSExact(gcjLat, gcjLng) //CSharp
gcj2WgsExact (gcjLat, gcjLng) //Haskell

输入GCJ-02火星坐标(gcjLat, gcjLng),转换为WGS-84地球坐标(wgsLat, wgsLng)。JavaScript 输出格式如下:

{"lat": xx.xxxx, "lng": yy.yyyy}

输出的WGS-84坐标精度为0.5米内,但是计算速度慢于GCJtoWGS/gcj2wgs。

Distance/distance

func Distance(latA, lngA, latB, lngB float64) float64 // Go/Golang
double distance(double latA, double lngA, double latB, double lngB) // C/C++/Obj-C
eviltransform.distance(latA, lngA, latB, lngB) // JavaScript/Python
\larryli\eviltransform\EvilTransform::Distance($latA, $lngA, $latB, $lngB) // PHP5.4+
EvilTransform.Transform.Distance(latA, lngA, latB, lngB) //CSharp
distance (lat, lng)

计算点(latA, lngA)和点(latB, lngB)之间的距离,单位为米。

算法来源:

参考:

eviltransform's People

Contributors

adclose avatar aokizen avatar artoria2e5 avatar bewantbe avatar chenweiyj avatar gengen1988 avatar ghostflying avatar googollee avatar gumblex avatar gutenye avatar jeremypenner avatar josh-taylr avatar larryli avatar lbt05 avatar lennonshawn avatar rockerhx avatar w1ndy avatar xingxing avatar y-x-c avatar zunsthy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

eviltransform's Issues

wgs2gcj 代码注释上的建议

今天重新看了一下 wgs→gcj 里面对于 transform() 一滩浑水之后的两个数值的处理:

	d.lat = (d.lat * 180.0) / ((earthR * (1 - ee)) / (magic * sqrtMagic) * Math.PI);
	d.lng = (d.lng * 180.0) / (earthR / sqrtMagic * Math.cos(radLat) * Math.PI);

这边实际上是进行了这样的操作

// https://en.wikipedia.org/wiki/Latitude#Length_of_a_degree_of_latitude
d.lat /= 椭球体纬线1°弧长({纬度: lat})
// https://en.wikipedia.org/wiki/Longitude#Length_of_a_degree_of_longitude
d.lon /= 椭球体经线1°弧长({纬度: lat})

如果感兴趣的话可以加上注释说明。能得到的一个比较有意思的结论是可以从 GCJ 的 transform 函数中直接得到经纬方向上加偏的距离,以及 transform 这个步骤的返回变量可以尝试说明单位是米。

wgtochina_lb and gpsHeight

Looking into the comment area in coolypf's article, it looks like the author omitted these two lines after applying the nonlinear deltas:

// variables renamed for readability. original: wg_heit, wg_time
dx += ((int) gpsHeight) * 0.001 + sin(((int) gpsWeekTime) * pi / 180) + random_yj();
dy += ((int) gpsHeight) * 0.001 + sin(((int) gpsWeekTime) * pi / 180) + random_yj();
// random_yj(): double rand [0,1)

The original code also branched away when gpsHeight > 5000:

if ((int) gpsHeight > 5000) { return null; }

But in getEncryPoint it was omitted. However, getEncryPoint shows a rather different variable name style, so I guess this might be added by someone else who has decompiled the code and wanted to try the thing out using this and the main function.

So here is the problem: is there any observable derivation in the current wgs2gcj implementation that approximately match the landscape of China for areas with alt <= 5000? If so, can we figure out what unit gpsHeight is supposed be in (derivations of 5 deg max sounds impossible to me, so there has to be another unit involved, like km)? This might not help this library (since the difference sounds small), but this helps with documenting the whole coord system.


// Linear Congruential Generator for real random numbers in the range [0,1)
// D. Rapaport, The Art of Molecular Dynamics Simulation, Cambridge, 2004
protected double random_yj()
{
    me.casm_rr = 314159269 /* a */ * me.casm_rr + 453806245 /* c */;
    me.casm_rr %= 2.0;
    me.casm_rr /= 2.0;
    return (me.casm_rr);
}
// see also: IniCasm, wgtochina_lb:branch[wg_flag == 0]

[question]integrate with pyproj

也许和这个项目不是非常相关, 不好意思:

因为需要转换一些GeoJson和shapely.geometry类型, 不知道有没有pyproj的wgs84, bd09, gcj02的转换设置?

We need new transform algorithm

data at 2015.10.11

NMEA from GPS source:
lat = 39.5768506
lon = 116.2097481

Real Location (From 1. android API 2. picked by BaiduMap):
lat = 39.96165504
lon = 116.35180069

If you have any improvement,
Please contact me @ [email protected]
Thank you very much !

outOfChina 或许可以裁掉南海(地图输入原因)

Google 的南海数据基本没有路,大部分都是从卫星直接出来的岛的形状之类的。百度的数据有偏移和没有一样烂(试试三沙市)。

我现在私下用的是北纬 17.75455,另有一个用来避免大规模误伤的Google偏移多边形近似界限用在这里。(最后裁下去都不好意思叫”China“了……)

#28 半径的跟进

首先我犯了个错误:球面估计距离的时候应该用平均半径 6371e3,而不是 6378e3 的赤道半径。

其次 eviltransform 在 gcj 中提出半径参数,与距离共享的做法是严重错误的:

  • gcj 使用的是一个该死的 SZ-42 椭球体
  • gcj 的 A 参数是赤道半径

考虑将repo转移到一个单独的project下面

这个项目创立之初,只有我自己的工作中用到的转换实现。后来感谢大家贡献代码,有了各种语言的实现。但是目前看上去,单一repo的形式有不少问题:

  • 我对其他语言不熟悉,比如matlab,java等。我无力维护这些语言的patch是否合理。
  • 我个人并不能及时响应所有语言的同步
  • 有占有其他人工作的嫌疑

我想将这个repo转化为单独的project,其中有一个doc repo,来定义所有实现需要的接口,以及相关算法和使用到的参数。同时这个doc会维护一个版本号,其他语言在实现时,需要指明对应的版本号。每个版本号发布后会对应一个tag。每个语言的实现单独一个repo,使用tag作为版本号。

我不知道各位贡献者对这个方案的想法如何。目前看得到的弊端是,对现有代码可能有影响(可以保留现有repo,但在readme里提示新的使用方法),star会分散到每个语言的repo里(我无所谓)。

对于原理的探讨

我想问一下,

  1. wgs_to_gcj02,这个方式是不是和真实使用的方法完全一致?转换后的gcj02是没有误差的?
  2. gcj02_to_wgs84_exact,增加迭代次数,是不是能继续缩减误差,假如到到1e-3以下呢?

Noob question: does this fix the GPS deviation issue?

I'm just beginning to understand the GPS offset problem in China, and it seems that it is caused by both the different projection system used, and by the GPS deviation that must be legally be introduced by either GPS manufacturers, or map providers (unclear on this).

So does the code in this repo fix both issues?

The goal would be to copy the coordinates of a place from the maps.google.com URL, transform them, paste the result in Baidu Maps, and get the same location displayed.

Does this jsbin also solve the problem by calling Baidu Maps' conversion API?

WGS84 or WSG84?

I want to know if the class named WSGPointer.java in the Java library is a spelling error?

Functions and variables in other libraries that refer to the World Geodetic System abbreviate it to "WGS".

I know it's a small change to make but it added to confusion about coordinates in geoTest.java being incorrect. I found that pairs of coordinates in WGS84 and GCJ-02 aren't converted to the same location by the Baidu Maps API.

Mix-up in test data (and algorithm).

Hello,

I am using the Java port and Baidu Maps API in my Android project. I'm sure those familiar with the Baidu API know that it uses the BD-09 coordinate system and that it provides a way to convert WGS84 and GCJ-02 coordinates to BD-09.

I was using pairs of coordinates from geoTest.java and noticed that converting them to BD-09 with the Baidu API didn't place them at the same position. I demonstrated this in an app that places a marker at two coordinates taken from geoTest.java and where CoordinateConverter corrects them to. Because the WGS84 and GCJ-02 coordinates represent the same position the corrected markers should be in the same place.

WSGPointer shanghaiWSGPointer = new WSGPointer(31.1774276, 121.5272106);
GCJPointer shanghaiGCJPointer = new GCJPointer(31.17530398364597, 121.531541859215);

This shows that 1.) the data is mixed up (the WGS points are actually GCJ, and vice-versa) and 2.) the conversion algorithms have a minor bug. In GCJPointer.java the delta should be added instead of subtracted and in WSGPointer.java the delta should be subtracted instead of added.

screenshot_2015-11-25-14-18-57

Phillipines not seen as out of China

"location" : {
    "lat" : 14.5733678,
    "lng" : 120.9824999
},

Seems currently to be transformed, while it shouldn't since it is in Manilla, the Philippines

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.