Github: https://github.com/geopy/geopy
ジオピー
geopyは、いくつかの一般的なジオコーディングWebサービス用のPython 2および3クライアントです。
geopyを使用すると、Python開発者は、サードパーティのジオコーダやその他のデータソースを使用して、世界中の住所、都市、国、およびランドマークの座標を簡単に見つけることができます。
geopyには、 OpenStreetMap Nominatim 、 ESRI ArcGIS 、 Google Geocoding API(V3) 、 Baidu Maps 、 Bing Maps API 、 Yahoo!のジオコーダークラスが含まれています PlaceFinder 、 Yandex 、 IGN France 、 GeoNames 、 Mapzen Search 、 OpenMapQuest 、 What3Words 、 OpenCage 、 SmartyStreets 、 geocoder.us 、およびGeocodeFarmジオコーダーサービスが含まれます。 さまざまなジオコーダークラスは、 geopy.geocodersにあります。
geopyは、CPython(バージョン2.7,3.4,3.5、3.6)、PyPy、およびPyPy3に対してテストされています。 geopyはCPython 2.6をサポートせず、サポートしません。
MITライセンスの下で©geopy contributors 2006-2015(作者参照)。
インストール
pipでインストールする:
pip install geopy
または、 PyPIからホイールまたはソースアーカイブをダウンロードしてください 。
ジオコーディング
クエリを住所と座標にジオロケーション指定するには:
>>> 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', ...}
座標のセットに対応するアドレスを見つけるには:
>>> 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', ...}
測定距離
GeopyはVincenty距離または大円距離式を使用して2点間の測地線距離を計算できます。デフォルトのVincentyはclass geopy.distance.distance
として使用でき、計算された距離は属性として利用できます( miles
、 meters
など)。 )。
Vincenty距離の使用例を次に示します。
>>> 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
大円距離を使用する:
>>> 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
ドキュメンテーション
より多くのドキュメンテーションと例は、 Read the Docsにあります。