As a result of professional needs, often access to some geoprocessing toolkit, documents are in English, their own look at the same time to translate it, on the one hand to learn at the same time there is a record, if you can at the same time to learn some of the children's shoes help, think is also excellent. The following document content is mainly translated from official documents, the level is limited, the wrong place wants everybody to point out.
Working with geographic data often involves geocoding issues. Geocoding refers to the process of transforming geographic information into coordinate relationships. The encoding is divided into forward and reverse. Forward refers to the conversion of address information to coordinate points, for example: Wuhan University-----(114.3594147, 30.5401222); reverse geocoding is the conversion of geographic coordinates to a specific address, which is the opposite of the previous process.
The Python-based geocoding library geopy is a common tool for geocoding, which allows you to obtain the coordinates of multiple map services. Currently supported under both Python2 and Python3. Python developers can use Geopy to easily get the global geographic coordinates of a street address, city, country, and parcel, which is parsed by a third-party geocoding and data source.
The geo-location services that geopy can use are as follows:
openstreetmapnominatim,esriarcgis, googlegeocodingapi (V3), baidumaps, Bingmapsapi,yahoo!placefinder, Yandex, ignfrance, GeoNames, Navidata,openmapquest, what3words, opencage, smartystreets, geocoder.us , andGeocodefarmAnd so on. These rich geocoding are located under the Geopy.geocoders module, which provides the API classes for each geolocation service. Each geocoding defines at least one GeoCode method that converts a string to a geographic location, and also defines a reverse method for converting geographic coordinates to specific addresses. Each geocoding needs to accept authentication and settings to use its services, for example: an API key or locale is required at initialization time.
Geopy passed the test under CPython 2.7, CPython 3.2, CPython 3.4, PyPy, and PyPy3.
Installation:
Can be installed by PIP or Easy_install:
Pip Install Geopy
Easy_install geopy
or install by downloading wheel or source files from PyPI
The following example demonstrates the use of geopy
Geo-coding
>>> fromGeopy.geocodersImportNominatim>>> 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', ...}
Anti-geo-coding
>>> fromGeopy.geocodersImportNominatim>>> 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', ...}
Calculate distance
Geopy can use the latitude distance formula (Vincenty distance) or the spherical distance (great-circle distance) formula to calculate the geodesic distance between two points. The latitude and longitude distance used in Geopy is the default way, the class is geopy.distance.distance, and the distance is calculated as its properties (e.g., miles, meters, etc).
The following examples are given for calculating the distance between latitude and longitude:
from Import vincenty>>> Newport_ri = (41.49008, -71.312796)>>> Cleveland_oh = (41.499498,- 81.695391)print(Vincenty (Newport_ri, Cleveland_oh). Miles)538.3904451566326
Use spherical 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
Geopy use of the detailed