http://blog.csdn.net/pipisorry/article/details/52205266

python地理位置处理

python地理编码地址以及用来处理经纬度的库

GeoDjango – 世界级地理图形 web 框架。
GeoIP – MaxMind GeoIP Legacy 数据库的Python API。
geojson – GeoJSON 的 Python 绑定及工具。
geopy – Python 地址编码工具箱。
pygeoip – 纯 Python GeoIP API。
django-countries – 一个 Django应用程序,提供用于表格的国家选择功能,国旗图标静态文件以及模型中的国家字段。

其它:

shapely,是geos的python封装,而geos是jts的c++移植版本。

python地理数据处理相关代码

[Python计算地图上两点经纬度间的距离]

皮皮blog

Python 地址编码工具箱geopy

geopy is a Python 2 and 3 client for several popular geocoding web services.
geopy makes it easy for Python developers to locate the coordinates of addresses, cities, countries, and landmarks across the globe using third-party geocoders and other data sources.
geopy includes geocoder classes for the OpenStreetMap Nominatim, ESRI ArcGIS, Google Geocoding API (V3), Baidu Maps, Bing Maps API, Mapzen Search, Yandex, IGN France, GeoNames, NaviData, OpenMapQuest, What3Words, OpenCage, SmartyStreets, geocoder.us, and GeocodeFarm geocoder services. The various geocoder classes are located in geopy.geocoders.

安装

pip install geopy

基本使用

Note: 函数参数都是纬度latitude在前,经度longitude在后。

查询地名转换为具体地址和经纬度Geocoding

To geolocate a query to an address and coordinates:
>>> from geopy.geocoders import Nominatim
>>> geolocator = Nominatim()
>>> location = geolocator.geocode("175 5th Avenue NYC")
>>> print(location.address)
Flatiron Building, 175, 5th Avenue, Flatiron, New York, NYC, New York, ...
>>> print((location.latitude, location.longitude))
(40.7410861, -73.9896297241625)
>>> print(location.raw)
{'place_id': '9167009604', 'type': 'attraction', ...}
To find the address corresponding to a set of coordinates:

>>> from geopy.geocoders import Nominatim
>>> geolocator = Nominatim()
>>> location = geolocator.reverse("52.509669, 13.376294")
>>> print(location.address)
Potsdamer Platz, Mitte, Berlin, 10117, Deutschland, European Union
>>> print((location.latitude, location.longitude))
(52.5094982, 13.3765983)
>>> print(location.raw)
{'place_id': '654513', 'osm_type': 'node', ...}

计算两地距离Measuring Distance

通过经纬度计算两地距离的两种方法。Geopy can calculate geodesic distance between two points using the Vincenty distance or great-circle distance formulas, with a default of Vincenty available as the class geopy.distance.distance, and the computed distance available as attributes (e.g., miles, meters,kilometers,etc.).

输入数据类型可以是tuple, list, array...,元素类型可以是float, str...

Vincenty distance

>>> from geopy.distance import vincenty
>>> newport_ri = (41.49008, -71.312796)
>>> cleveland_oh = (41.499498, -81.695391)
>>> print(vincenty(newport_ri, cleveland_oh).miles)
538.3904451566326

Vincenty distance (vincenty) uses a more accurate ellipsoidal modelof the earth. This is the default distance formula, and is thus aliased asdistance.distance. There are multiple popular ellipsoidal models, andwhich one will be the most accurate depends on where your points are locatedon the earth. The default is the WGS-84 ellipsoid, which is the most globallyaccurate. geopy includes a few othermodels in the distance.ELLIPSOIDS dictionary:

              model             major (km)   minor (km)     flattening
ELLIPSOIDS = {'WGS-84':        (6378.137,    6356.7523142,  1 / 298.257223563),
              'GRS-80':        (6378.137,    6356.7523141,  1 / 298.257222101),
              'Airy (1830)':   (6377.563396, 6356.256909,   1 / 299.3249646),
              'Intl 1924':     (6378.388,    6356.911946,   1 / 297.0),
              'Clarke (1880)': (6378.249145, 6356.51486955, 1 / 293.465),
              'GRS-67':        (6378.1600,   6356.774719,   1 / 298.25),
              }

You can change the ellipsoid model used by the Vincenty formula like so:

>>> distance.vincenty(ne, cl, ellipsoid='GRS-80').miles

The above model name will automatically be retrieved from theELLIPSOIDS dictionary. Alternatively, you can specify the model valuesdirectly:

>>> distance.vincenty(ne, cl, ellipsoid=(6377., 6356., 1 / 297.)).miles

[class geopy.distance.vincenty(*args, **kwargs)]

[https://en.wikipedia.org/wiki/Vincenty’s_formulae]

great-circle distance

>>> from geopy.distance import great_circle
>>> newport_ri = (41.49008, -71.312796)
>>> cleveland_oh = (41.499498, -81.695391)
>>> print(great_circle(newport_ri, cleveland_oh).miles)
537.1485284062816

[class geopy.distance.great_circle(*args, **kwargs)]

[https://en.wikipedia.org/wiki/Great-circle_distance]

两种经纬度距离度量方法的区别

Vincenty's formulae are two related iterative methods used in geodesy to calculate the distance between two points on the surface of a spheroid, developed by Thaddeus Vincenty (1975a) They are based on the assumption that the figure of the Earth is an oblate spheroid(扁球形体), and hence are more accurate than methods such as great-circle distance which assume a spherical(球状的) Earth.

[What's the difference between vincenty and great circle distance calculations?]

计算出错

TypeError: __new__() takes from 1 to 4 positional arguments but 5 were given

可能是某个坐标的维度不对,如[[ ]]二维就不对,应该是[]或者()。

ValueError: Vincenty formula failed to converge!

vincenty算法可以不收敛,可能是因为中间有一些三角函数的计算是通过迭代计算出来的,超过最大迭代次数就当作不收敛了。the basic iterative technique for the inverse method is just Vincenty (regular + his antipodal method); so it may fail to converge in some cases.

Examples where the solution of the inverse problem fails to converge:

lat1 lon1  lat2 lon2
     0.7   0   -0.3 179.7
     2.2   0   -1.8 179.6
     2.3   0   -2.0 179.6

[Talk:Geodesics on an ellipsoid]

def c():
    from geopy import distance
    xs ], [], [], [, ]]
    ys , ]]
    for x, y in zip(xs, ys):
        try:
            d = distance.vincenty(x, y)
            print(d)
        except:
)

解决:
It may be preferable to use  :class:`.great_circle`, which is marginally less accurate, but always produces a result.

[https://github.com/geopy/geopy/pull/144/files]

[geopy documents]

[geopy/geopy]

from: http://blog.csdn.net/pipisorry/article/details/52205266

ref:

python地理数据处理库geopy的更多相关文章

  1. python地理处理包——geopy使用之地理编码与反地理编码

    由于专业需要,经常接触一些地理处理的工具包,文档都是英文的,自己看的同时将其翻译一下,一方面自己学习的同时有个记录,要是能同时给一起的学习的童鞋们一些帮助,想想也是极好的.以下的文档内容主要翻译自官方 ...

  2. python常用数据处理库

    Python之所以能够成为数据分析与挖掘领域的最佳语言,是有其独特的优势的.因为他有很多这个领域相关的库可以用,而且很好用,比如Numpy.SciPy.Matploglib.Pandas.Scikit ...

  3. Python 数据处理库 pandas 入门教程

    Python 数据处理库 pandas 入门教程2018/04/17 · 工具与框架 · Pandas, Python 原文出处: 强波的技术博客 pandas是一个Python语言的软件包,在我们使 ...

  4. Python 数据处理库pandas教程(最后附上pandas_datareader使用实例)

    0 简单介绍 pandas是一个Python语言的软件包,在我们使用Python语言进行机器学习编程的时候,这是一个非常常用的基础编程库.本文是对它的一个入门教程. pandas提供了快速,灵活和富有 ...

  5. python 各种开源库

    测试开发 来源:https://www.jianshu.com/p/ea6f7fb69501 Web UI测试自动化 splinter - web UI测试工具,基于selnium封装. 链接 sel ...

  6. Python常用的库简单介绍一下

    Python常用的库简单介绍一下fuzzywuzzy ,字符串模糊匹配. esmre ,正则表达式的加速器. colorama 主要用来给文本添加各种颜色,并且非常简单易用. Prettytable ...

  7. Python的常用库

    读者您好.今天我将介绍20个属于我常用工具的Python库,我相信你看完之后也会觉得离不开它们.他们是: Requests.Kenneth Reitz写的最富盛名的http库.每个Python程序员都 ...

  8. python地理处理包——pySAL使用

    Pysal是基于Python的开源地理处理库,能提供高层次的空间分析功能.

  9. python 爬虫第三方库

    这个列表包含与网页抓取和数据处理的Python库 网络 通用 urllib -网络库(stdlib). requests -网络库. grab – 网络库(基于pycurl). pycurl – 网络 ...

随机推荐

  1. [WC 2014]紫荆花之恋

    Description 强强和萌萌是一对好朋友.有一天他们在外面闲逛,突然看到前方有一棵紫荆树.这已经是紫荆花飞舞的季节了,无数的花瓣以肉眼可见的速度从紫荆树上长了出来. 仔细看看的话,这个大树实际上 ...

  2. [Codeforces]856C - Eleventh Birthday

    题目大意:给出n个数,问有多少种排列把数字接起来是11的倍数.(n<=2000) 做法:一个数后面接一个数等同于乘上10的若干次幂然后加上这个数,10模11等于-1,所以10的若干次幂是-1或1 ...

  3. 【bzoj4570 scoi2016】妖怪

    题目描述 邱老师是妖怪爱好者,他有n只妖怪,每只妖怪有攻击力atk和防御力dnf两种属性.邱老师立志成为妖怪大师,于是他从真新镇出发,踏上未知的旅途,见识不同的风景. 环境对妖怪的战斗力有很大影响,在 ...

  4. poj 1265 Area 面积+多边形内点数

    Area Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5861   Accepted: 2612 Description ...

  5. [BZOJ]1085 骑士精神(SCOI2005)

    这种鲜明的玄学风格很明显就是十几年前的题目. Description 在一个5×5的棋盘上有12个白色的骑士和12个黑色的骑士, 且有一个空位.在任何时候一个骑士都能按照骑士的走法(它可以走到和它横坐 ...

  6. bzoj2006 NOI2010 数据结构+堆维护区间和最大

    2006: [NOI2010]超级钢琴 Time Limit: 20 Sec  Memory Limit: 552 MBSubmit: 3431  Solved: 1686[Submit][Statu ...

  7. Nginx+uWSGI+Django环境配置

    通常项目会部署在虚拟环境,虚拟环境的使用可以参考这里,点击前往 当然你也可以直接部署,这里不多说. 一.安装uWSGI 1.通过pip安装 pip install uwsgi 这里只说明了一种安装方式 ...

  8. 多线程join(加入)

    package cn.itcast.thread;/* join方法. 加入 */ //老妈class Mon extends Thread{ public void run() { System.o ...

  9. vue环境搭建过程中,遇到的坑爹的问题

    1,在配置package.json下载node依赖包时,执行$cnpm install过程中,这个过程是比较漫长的,尤其的这种core i5配置的电脑,简直有点卡的人怀疑人生,后来动了下有消息输出,我 ...

  10. 用一个div模拟textarea的实现

    <textarea> 标签定义一个多行的文本输入控件.但是它不能像div一样随着内容增加而自动增加,一言不合就出现滚动条,有是有为了更好的交互,可能需要使用div来模拟textarea的实 ...