All Projects → datadesk → latimes-mappingla-geopy

datadesk / latimes-mappingla-geopy

Licence: MIT license
A fork of the geocoding library geopy. Returns accuracy scores. Allows viewport biasing.

Programming Languages

python
139335 projects - #7 most used programming language

This library is no longer supported and probably should not be used. If you would like to access Google’s v3 geocoder with Python, try python-googlegeocoder.

                                              ,,                                          
`7MMM.     ,MMF'                              db                           `7MMF'            db      
  MMMb    dPMM                                                               MM             ;MM:     
  M YM   ,M MM   ,6"Yb. `7MMpdMAo.`7MMpdMAo.`7MM  `7MMpMMMb.  .P"Ybmmm       MM            ,V^MM.    
  M  Mb  M' MM  8)   MM   MM   `Wb  MM   `Wb  MM    MM    MM :MI  I8         MM           ,M  `MM    
  M  YM.P'  MM   ,pm9MM   MM    M8  MM    M8  MM    MM    MM  WmmmP"         MM      ,    AbmmmqMA   
  M  `YM'   MM  8M   MM   MM   ,AP  MM   ,AP  MM    MM    MM 8M              MM     ,M   A'     VML  
.JML. `'  .JMML.`Moo9^Yo. MMbmmd'   MMbmmd' .JMML..JMML  JMML.YMMMMMb      .JMMmmmmMMM .AMA.   .AMMA.
                          MM        MM                       6'     dP                               
                        .JMML.    .JMML.                     Ybmmmd'                                 

A fork of the geocoding library geopy, modified, with a few new toys.

Includes:

  • An option to return an accuracy score along with the result

How it works

First fire up geopy and load the Google geocoder like you normally would.

$ python
>>> from geopy import geocoders
>>> g = geocoders.Google(BENS_GOOGLE_API_KEY)

Now run an address like you typically would and see the usual output. Let’s try the address of the Los Angeles Times.

>>> point_generator = g.geocode('202 W. 1st St., Los Angeles, Los Angeles, CA', exactly_one=False)
>>> from pprint import pprint
>>> pprint(list(point_generator))
[(u'202 W 1st St, Los Angeles, CA 90731, USA',
  (33.743286099999999, -118.28143780000001)),
 (u'202 W 1st St, Los Angeles, CA 90012, USA',
  (34.052993000000001, -118.24482500000001))]

Unfortunately, we get two results in LA for the same address. Let’s use my new optional keyword argument, ‘return_accuracy’ so see how good they are.

>>> point_generator = g.geocode('202 W. 1st St., Los Angeles, Los Angeles, CA', exactly_one=False, return_accuracy=True)

You’ll see that the generator now includes the accuracy score at the tail end. You can decode the number here. Eight is pretty good.

>>> pprint(list(point_generator))
[(u'202 W 1st St, Los Angeles, CA 90731, USA',
  (33.743286099999999, -118.28143780000001),
  u'8'),
 (u'202 W 1st St, Los Angeles, CA 90012, USA',
  (34.052993000000001, -118.24482500000001),
  u'8')]

But they’re both at the same high accuracy level. Why? Because that address occurs both in Downtown L.A. and in the long-ago annexed neighborhood of San Pedro.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].