Code Monkey home page Code Monkey logo

gcoord's Issues

发现一个bug,转换geojson对象Polygon时,坐标会偏移,图形变形了

从BD09到WGS84
gcoord.transform(geojson, gcoord.BD09, gcoord.WGS84);
转换前:
{
"type": "Polygon",
"coordinates": [
[
[
110.30060468148584,
21.219847338501882
],
[
110.31066570319426,
21.18898007297982
],
[
110.31440265411453,
21.20111209125531
],
[
110.31857079167945,
21.214995275091464
],
[
110.30865349885258,
21.21769088580071
],
[
110.30060468148584,
21.219847338501882
]
]
]
}
转换后:
{
"type": "Polygon",
"coordinates": [
[
[
110.27907103222238,
21.212303455167472
],
[
110.29982281199085,
21.18536961030313
],
[
110.30355067508778,
21.19756068173438
],
[
110.3077014913672,
21.211509795833887
],
[
110.29783559081969,
21.214053794383407
],
[
110.27907103222238,
21.212303455167472
]
]
]
}

transform参数

transform参数不支持通过网页获取到对应的当前坐标系和待转换坐标系的value 来传入方法中吗?

ES model 中Cannot find module './geojson'

ionic 3 中通过npm 下载后,启动项目提示:

typescript: node_modules/gcoord/dist/types/transform.d.ts, line: 1 
Cannot find module './geojson'. 
L1:  import { Position, GeoJSON } from './geojson';

转换精度低

我试了下百度的坐标转换,发现精度对不上

"WGS84" :121.18180305555556, 31.287874444444444 转"BD09"

百度自带的结果为:121.19272701709394,31.29222496103614

库的结果为:121.19272205711691,31.292220583538928

这会不会是js精度带来的问题?

大地2000 经纬度转换

现在好多地图都开始使用大地2000的经纬坐标
大地2000 和WGS84是否有差别
如果有能否增加一个大地2000 和各个经纬度的转换

大家有用到Cesium上不同地图底图纠偏吗?

如题,大家有用到Cesium吗,现在我在Cesium上调用高德,谷歌**,腾讯,百度地图,然后调用腾讯的poi接口,得到的poi兴趣点中的经纬度,显示在高德,谷歌**,腾讯的底图上都没问题,但是显示在百度地图的底图就有偏差了,调用了转换还是偏差很大。不知道大家是怎么处理这个问题的?

gcoord.transform(
[loc.lng, loc.lat], // 经纬度坐标
gcoord.GCJ02, // 当前坐标系
gcoord.BD09// 目标坐标系
)

我用C重写了WGS84和GCJ02的转换代码,发现和你的结果有偏差

#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define PI 3.1415926535897932384626

double a = 6378245;
double ee = 0.006693421622965823;

// roughly check whether coordinates are in China.
int isInChinaBbox(double lon, double lat){
  	return lon >= 72.004 && lon <= 137.8347 && lat >= 0.8293 && lat <= 55.8271;
}

double transformLat(double x, double y){
	double ret = -100.0 + 2.0 * x + 3.0 * y + 0.2 * y * y + 0.1 * x * y + 0.2 * sqrt(fabs(x));
	ret += ((20.0 * sin(6.0 * x * PI) + 20.0 * sin(2.0 * x * PI)) * 2.0) / 3.0;
	ret += ((20.0 * sin(y * PI) + 40.0 * sin((y / 3.0) * PI)) * 2.0) / 3.0;
	ret += ((160.0 * sin((y / 12.0) * PI) + 320.0 * sin((y * PI) / 30.0)) * 2.0) / 3.0;
	return ret;
}

double transformLon(double x, double y){
	double ret = 300.0 + x + 2.0 * y + 0.1 * x * x + 0.1 * x * y + 0.1 * sqrt(fabs(x));
	ret += ((20.0 * sin(6.0 * x * PI) + 20.0 * sin(2.0 * x * PI)) * 2.0) / 3.0;
	ret += ((20.0 * sin(x * PI) + 40.0 * sin((x / 3.0) * PI)) * 2.0) / 3.0;
	ret += ((150.0 * sin((x / 12.0) * PI) + 300.0 * sin((x / 30.0) * PI)) * 2.0) / 3.0;
	return ret;
}

double* delta(double lon, double lat){
	double *d = (double *)malloc(2*sizeof(double));
	double dLon = transformLon(lon - 105.0, lat - 35.0);
    double dLat = transformLat(lon - 105.0, lat - 35.0);
	
	double radLat = (lat / 180.0) * PI;
	double magic = sin(radLat);
	
	magic = 1.0 - ee * magic * magic;
	
	double sqrtMagic = sqrt(magic);
	d[0] = (dLon * 180.0) / (a / sqrtMagic * cos(radLat) * PI);
	d[1] = (dLat * 180.0) / ((a * (1.0 - ee)) / (magic * sqrtMagic) * PI);
	return d;
}

double* WGS84ToGCJ02(double lon_WGS, double lat_WGS){
	double *GCJ = (double *)malloc(2*sizeof(double));
	if (!isInChinaBbox(lon_WGS, lat_WGS)){
		GCJ[0] = lon_WGS;
		GCJ[1] = lat_WGS;
		return GCJ;
	} 
	double *d = delta(lon_WGS, lat_WGS);
	GCJ[0] = lon_WGS + d[0];
	GCJ[1] = lat_WGS + d[1];
	return GCJ;
}

double* GCJ02ToWGS84(double lon_GCJ, double lat_GCJ) {
	double *WGS = (double *)malloc(2*sizeof(double));
	if (!isInChinaBbox(lon_GCJ, lat_GCJ)){
		WGS[0] = lon_GCJ;
		WGS[1] = lat_GCJ;
		return WGS;
	} 
	WGS[0] = lon_GCJ; WGS[1] = lat_GCJ;
	double *temp = WGS84ToGCJ02(WGS[0], WGS[1]);
	double dx = temp[0] - lon_GCJ;
	double dy = temp[1] - lat_GCJ;
	while (fabs(dx) > 1e-6 || fabs(dy) > 1e-6) {
		WGS[0] -= dx;
		WGS[1] -= dy;
		temp = WGS84ToGCJ02(WGS[0], WGS[1]);
		dx = temp[0] - lon_GCJ;
		dy = temp[1] - lat_GCJ;
	}
	return WGS;
}

int main(){
	double lon, lat;
	double x = 114.5048503, y = 37.0705911; 
	double *q = GCJ02ToWGS84(x, y);
	printf("%.10lf %.10lf\n", q[0], q[1]);
	getchar(); 
} 

image
在china-cities.json中随机选取一份数据
"WGS84": [114.498916, 37.0700925],
"GCJ02": [114.5048503, 37.0705911],
使用我的代码将GCJ02转换为WGS84,结果为[114.4989213554, 37.0700966574]
不知道是不是你的算法写错了,还是我重写的代码出了问题,我反复对照了多遍,没发现有遗漏的地方。希望得到你的回复。

BD09 -> GCJ02 不生效

var result = gcoord.transform(
    [121.41473785401124, 31.076902617360464 ],    // 经纬度坐标
    gcoord.BD09,                 // 当前坐标系
    gcoord.GCJ02                   // 目标坐标系

)
console.log(result);

转换的原理疑问和不同坐标下瓦片的转换建议

  1. 理论上,GCJ-02的加密过程是不可逆的,但是可以通过一些方法来逼近接原始坐标,并且这种方式的精度很高。gcoord使用的纠偏方式达到了厘米级的精度,能满足绝大多数情况
    引用wiki上的这句话,可以公布下通过哪些方法来逼近接原始坐标吗?(只是个人疑问)

  2. 希望可以推出不同坐标下瓦片的转换(比如在wgs84坐标的地图上,加载在线的互联网地图会偏移)
    需求是,可以矫正一些互联网地图到标准的地图上。
    思路是,通过请求的url中的 {x}/{y}/{z}通过scale或者solution和zoom等计算(定位)出wgs84的瓦片的 四至,转换四至的坐标到在线地图的坐标下,再通过在线地图的坐标,计算出在线地图的瓦片。(如有错误请指正)

input参数若是Array<string>的情况下,BD09->WGS84转换成功,GCJ02->WGS84转换失败。

var pointStr = "113.98245404505606,22.52280474";
    let point = pointStr.split(',');
    var result = gcoord.transform(
        point,    // 经纬度坐标
        gcoord.BD09,               // 当前坐标系
        gcoord.WGS84                 // 目标坐标系
    );
    console.log(point);//["113.98245404505606", "22.52280474"]
    console.log(result);//[113.97106644180005, 22.519655815769017]

    var result2 = gcoord.transform(
        point,    // 经纬度坐标
        gcoord.GCJ02,               // 当前坐标系
        gcoord.WGS84                 // 目标坐标系
    );
    console.log(result2);//["113.98245404505606", "22.52280474"]

BD09转换GCJ02坐标

BD09转换GCJ02坐标后,大概会有15-30米左右的一个偏移,这是一个正常的偏移量么?
[{ "longitude": 112.95516973717, "latitude": 27.110248315429 }, { "longitude": 112.95514967002, "latitude": 27.110209045353 }, { "longitude": 112.9552696853, "latitude": 27.110439072645 }, { "longitude": 112.95538827008, "latitude": 27.11055600291 }, { "longitude": 112.95552789901, "latitude": 27.110607549457 }, { "longitude": 112.95563435193, "latitude": 27.110608671425 }, { "longitude": 112.95591453403, "latitude": 27.110596723704 }, { "longitude": 112.95625794057, "latitude": 27.110520645541 }, { "longitude": 112.95637142166, "latitude": 27.110518640771 }, { "longitude": 112.9565491395, "latitude": 27.110464491862 }, { "longitude": 112.95693074252, "latitude": 27.11043674701 }, { "longitude": 112.95795897797, "latitude": 27.110248575302 }, { "longitude": 112.95866190586, "latitude": 27.110180202997 }, { "longitude": 112.95943518443, "latitude": 27.110209670777 }, { "longitude": 112.96032802743, "latitude": 27.110363173252 }, { "longitude": 112.96197014333, "latitude": 27.11084511094 }, { "longitude": 112.96234773516, "latitude": 27.110922743543 }, { "longitude": 112.96382982801, "latitude": 27.111144138779 }, { "longitude": 112.96614400844, "latitude": 27.111540288631 }, { "longitude": 112.96689684702, "latitude": 27.111625778344 }, { "longitude": 112.96737860852, "latitude": 27.111681353588 }]
map

remove geojson?

目前gcoord主要是做两件事:转换坐标系和生成geojson格式的对象

但是第二个功能似乎必要性不大,两个功能之间的关联性也不强,可以考虑移除掉geojson相关代码

移除这部分代码不会影响到transform处理geojson格式的坐标

typescript 引用报错

在 ts 工程中,这么写会报错

import gcoord from 'gcoord';

编译出来的代码会发现 gcoord 找不到

Cannot read properties of undefined (reading 'transform')

必须改成这样才行

import * as gcoord from 'gcoord';

改成这样后,语法提示又出错了。比较别扭,不知道是哪里的问题。

please help me

When the coordinate is transferred to GPS coordinates, there is no change.
For example:
var geojson = {
"type": "Point",
"coordinates": ["120.42378", "27.452646"]
}
gcoord.transform(geojson, gcoord.GCJ02, gcoord.WGS84);

function gcoord.transfrom could not use in vue

import gcoord : import gcoord from "gcoord";
use gcoord:

  1. console.log(gcoord.WGS84); //correct , log: WGS84
  2. gcoord.transfrom(
    [120.16336, 31.466956],
    gcoord.WGS84,
    gcoord.GCJ02
    );
    //error :TypeError: gcoord.transfrom is not a function
    could you help me? and how to slove the problem.

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.