Giter Site home page Giter Site logo

wandergis / coordtransform_py Goto Github PK

View Code? Open in Web Editor NEW
1.1K 38.0 436.0 53 KB

提供百度坐标系(bd-09)、火星坐标系(国测局坐标系、gcj02)、WGS84坐标系直接的坐标互转,也提供了解析高德地址的方法的python版本

Home Page: http://wandergis.github.io/coordTransform_py

License: MIT License

Python 100.00%

coordtransform_py's Issues

out_of_china判断

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判断个人认为不能准确判断是否在国内,**形状不是规则矩形

python版地理编码的查询链接有误

原链接为:
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": "兴趣点"
}
]
}

bd09转WGS84

大神有没有百度坐标转WGS84坐标的方法啊

Python3 urllib报错

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

请问我可以在arcgis中用python将wgs1984转换到百度坐标么

Migrated coordTransform to a Java version

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;
}

}

返回类型一致性优化

我觉得代码里的:

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]更优雅些。

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.