bingbing-apigeopygeocoder

Can geopy return geocoding quality? (using Bing API)


I've been reading the docs for the Bing geocoder using geopy and there doesn't seem to be a parameter for geocoding quality as an output.

In particular, I'm looking for 'matchCodes' and 'confidence' as outlined here.

Anyone know if this is possible?

Thanks in advance.


Solution

  • Location.raw attribute contains the raw geocoding response, from which these params can be retrieved:

    In [1]: import os
       ...: from geopy.geocoders import Bing
    
    In [2]: g = Bing(api_key=os.environ['BING_KEY'])
       ...: l = g.geocode("moscow")
    
    In [3]: l.raw
    Out[3]:
    {'__type': 'Location:http://schemas.microsoft.com/search/local/ws/rest/v1',
     'bbox': [55.493934631347656,
      37.31906509399414,
      55.9488410949707,
      37.94414520263672],
     'name': 'Moscow City',
     'point': {'type': 'Point',
      'coordinates': [55.55002975463867, 37.36982727050781]},
     'address': {'adminDistrict': 'Moscow City',
      'countryRegion': 'Russia',
      'formattedAddress': 'Moscow City'},
     'confidence': 'High',
     'entityType': 'AdminDivision1',
     'geocodePoints': [{'type': 'Point',
       'coordinates': [55.55002975463867, 37.36982727050781],
       'calculationMethod': 'Rooftop',
       'usageTypes': ['Display']}],
     'matchCodes': ['Ambiguous']}
    
    In [4]: l.raw['confidence']
    Out[4]: 'High'
    
    In [5]: l.raw['matchCodes']
    Out[5]: ['Ambiguous']