What3Words is an innovative, plain simple and multilingual addressing scheme:
"w3w is a giant grid of the world made up of 57 trillion squares of 3 metres x 3 metres. Each square has been given a 3 word address comprised of 3 words from the dictionary. An example of a w3w address is gazed.across.like"
(source: What3Words)
I recently added a What3Words geocoder to the geopy package.
So now its possible to geocode and reverse geocode What3Words from python, as shown in this example:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
# | |
# What3Words geocoding / reverse geocoding examples. Turning addresses into WGS84 coordintes and vice versa | |
from geopy.geocoders import What3Words | |
def main(): | |
# setting the What3Word-API-Key | |
w3w_key = "XXXXXXXX" | |
# What3Word string | |
w3w_address = u"piped.gains.jangle" | |
# OneWord string | |
oneword_address= u"*LibertyTech" | |
# lat/lon for reverse exmaple | |
x = 53.037611 | |
y = 11.565012 | |
# setting up the geocoder | |
geolocator = What3Words(w3w_key) | |
# Points from address | |
print geolocator.geocode(w3w_address,lang='EN').point # --> 53 2m 15.3996s N, 11 33m 54.0432s E | |
print geolocator.geocode(oneword_address,lang='EN').point # --> 51 30m 45.2628s N, 0 8m 41.5644s W | |
# lat/lon | |
print geolocator.geocode(w3w_address,lang='EN').latitude # --> 53.037611 | |
print geolocator.geocode(w3w_address,lang='EN').longitude # --> 11.565012 | |
# raw output geocoder | |
print geolocator.geocode(w3w_address,lang='EN').raw # --> {u'position': [53.037611, 11.565012], u'type': u'3 words', u'language': u'en', u'words': [u'piped', u'gains', u'jangle']} | |
# Address from lat/lon | |
print geolocator.reverse([x, y], lang='EN').address # --> piped.gains.jangle | |
# raw output reverse | |
print geolocator.reverse([x, y], lang='EN').raw # --> {u'position': [53.037611, 11.565012], u'language': u'en', u'words': [u'piped', u'gains', u'jangle']} | |
if __name__ == '__main__': | |
main() |
[Edit: 2014-12-10]
My pull request has been accepted and the what3words geocoder became part of geopy 1.5.0!
Follow @spatialbits
Keine Kommentare:
Kommentar veröffentlichen