wandergis / coordtransform_py Goto Github PK
View Code? Open in Web Editor NEW提供百度坐标系(bd-09)、火星坐标系(国测局坐标系、gcj02)、WGS84坐标系直接的坐标互转,也提供了解析高德地址的方法的python版本
Home Page: http://wandergis.github.io/coordTransform_py
License: MIT License
提供百度坐标系(bd-09)、火星坐标系(国测局坐标系、gcj02)、WGS84坐标系直接的坐标互转,也提供了解析高德地址的方法的python版本
Home Page: http://wandergis.github.io/coordTransform_py
License: MIT License
A return value of tuple type is more pythonic
看到有一个 http://www.gpsspg.com/api/convert/latlng/
这个api, 和这个数据谁比较过, 区别大吗?>
GCJ02转WGS84 通常有几百米的误差
如题
希望楼主添加以某个中心点 指定范围内的随机坐标的功能,感谢!
加了个 c# 的版本,可以写到 md 文件中。
https://github.com/topcss/coordtransform
def out_of_china(lng, lat):
"""
判断是否在国内,不在国内不做偏移
:param lng:
:param lat:
:return:
"""
if lng < 72.004 or lng > 137.8347:
return True
if lat < 0.8293 or lat > 55.8271:
return True
return False
这两个if判断个人认为不能准确判断是否在国内,**形状不是规则矩形
原链接为:
geocoding = {'s': 'rsv3', 'key': self.api_key, 'city': '全国', 'address': address} geocoding = urllib.parse.urlencode(geocoding) ret = urllib.request.urlopen("%s?%s" % ("http://restapi.amap.com/v3/geocode/geo", geocoding))
(举例:[http://restapi.amap.com/v3/geocode/geos=rsv3&key=xxx&city=%广州&address=%君紫花园)]
查询结果为:
{ "status": "0",
"info": "INVALID_USER_KEY",
"infocode": "10001"}
正确链接为:[http://restapi.amap.com/v3/geocode/geo?key=xxx&city=%广州&address=%君紫花园)]
geocoding = {'key': self.api_key, 'city': city, 'address': address} geocoding = urllib.parse.urlencode(geocoding) ret = urllib.request.urlopen("%s?%s" % ("http://restapi.amap.com/v3/geocode/geo?", geocoding))
查询结果为:
{
"status": "1",
"info": "OK",
"infocode": "10000",
"count": "1",
"geocodes": [
{
"formatted_address": "广东省广州市天河区君紫花园",
"country": "**",
"province": "广东省",
"citycode": "020",
"city": "广州市",
"district": "天河区",
"township": [],
"neighborhood": {
"name": [],
"type": []
},
"building": {
"name": [],
"type": []
},
"adcode": "440106",
"street": [],
"number": [],
"location": "113.344832,23.127699",
"level": "兴趣点"
}
]
}
大神有没有百度坐标转WGS84坐标的方法啊
AttributeError: module 'urllib' has no attribute 'urlencode'
AttributeError: module 'urllib' has no attribute 'parse'
Do as follows
import urllib.parse
import urllib.request
geocoding = urllib.parse.urlencode(geocoding)
ret = urllib.request.urlopen("%s?%s" % ("http://restapi.amap.com/v3/geocode/geo", geocoding))
Works.
请问我可以在arcgis中用python将wgs1984转换到百度坐标么
Tried to migrate coordTransform to a Java version, only the wgs84_to_bd09 part.
Please wandergis can merge in your project if wanted.
package com.xxx.xxxworld.util;
Geocoding.zip
public class Geocoding {
static final double x_pi = 3.14159265358979324 * 3000.0 / 180.0;
static final double pi = 3.1415926535897932384626;
static final double a = 6378245.0; // 长半轴
static final double ee = 0.00669342162296594323; // 偏心率平方
static double[] wgs84_to_gcj02(double lng, double lat) {
// WGS84转GCJ02(火星坐标系)
// :param lng:WGS84坐标系的经度
// :param lat:WGS84坐标系的纬度
// :return:
// """
if(out_of_china(lng, lat)) //判断是否在国内
return new double[]{ lng, lat};
double dlat = _transformlat(lng - 105.0, lat - 35.0);
double dlng = _transformlng(lng - 105.0, lat - 35.0);
double radlat = lat / 180.0 * pi;
double magic = Math.sin(radlat);
magic = 1 - ee * magic * magic;
double sqrtmagic = Math.sqrt(magic);
dlat = (dlat * 180.0) / ((a * (1 - ee)) / (magic * sqrtmagic) * pi);
dlng = (dlng * 180.0) / (a / sqrtmagic * Math.cos(radlat) * pi);
double mglat = lat + dlat;
double mglng = lng + dlng;
return new double[]{mglng, mglat};
}
static double[] gcj02_to_bd09(double lng, double lat) {
// """
// 火星坐标系(GCJ-02)转百度坐标系(BD-09)
// 谷歌、高德——>百度
// :param lng:火星坐标经度
// :param lat:火星坐标纬度
// :return:
// """
double z = Math.sqrt(lng * lng + lat * lat) + 0.00002 * Math.sin(lat * x_pi);
double theta = Math.atan2(lat, lng) + 0.000003 * Math.cos(lng * x_pi);
double bd_lng = z * Math.cos(theta) + 0.0065;
double bd_lat = z * Math.sin(theta) + 0.006;
return new double[]{bd_lng, bd_lat};
}
public static double[] wgs84_to_bd09(double lon, double lat) {
double[] gcj02 = wgs84_to_gcj02(lon, lat);
return gcj02_to_bd09(gcj02[0], gcj02[1]);
}
static boolean out_of_china(double lng, double lat) {
// """
// 判断是否在国内,不在国内不做偏移
// :param lng:
// :param lat:
// :return:
// """
return !(lng > 73.66 && lng < 135.05 && lat > 3.86 && lat < 53.55);
}
static double _transformlat(double lng, double lat) {
double ret = -100.0 + 2.0 * lng + 3.0 * lat + 0.2 * lat * lat +
0.1 * lng * lat + 0.2 * Math.sqrt(Math.abs(lng));
ret += (20.0 * Math.sin(6.0 * lng * pi) + 20.0 *
Math.sin(2.0 * lng * pi)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(lat * pi) + 40.0 *
Math.sin(lat / 3.0 * pi)) * 2.0 / 3.0;
ret += (160.0 * Math.sin(lat / 12.0 * pi) + 320 *
Math.sin(lat * pi / 30.0)) * 2.0 / 3.0;
return ret;
}
static double _transformlng(double lng, double lat) {
double ret = 300.0 + lng + 2.0 * lat + 0.1 * lng * lng +
0.1 * lng * lat + 0.1 * Math.sqrt(Math.abs(lng));
ret += (20.0 * Math.sin(6.0 * lng * pi) + 20.0 *
Math.sin(2.0 * lng * pi)) * 2.0 / 3.0;
ret += (20.0 * Math.sin(lng * pi) + 40.0 *
Math.sin(lng / 3.0 * pi)) * 2.0 / 3.0;
ret += (150.0 * Math.sin(lng / 12.0 * pi) + 300.0 *
Math.sin(lng / 30.0 * pi)) * 2.0 / 3.0;
return ret;
}
}
6378245 是克拉索夫斯基椭球定义的地球长半轴长度,这是一个很老的地球参考椭球参数,请问这里为什么选用这个椭球参数?
我觉得代码里的:
if out_of_china(lng, lat):
return lng, lat
写成:
if out_of_china(lng, lat):
return [lng, lat]
会更好些吧?其他情况都是返回列表类型,超出**范围返回元组,虽然在调用和引用值时基本没有问题,都可以用result[0],result[1]获取返回的经纬度,还是觉得return [lng, lat]更优雅些。
博主,这个坐标转换的原理,或者说公式在那里可以参考呀
网上流传的各种语言的版本都是相同的算法,有可靠出处吗?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.