本文整理汇总了Python中omgeo.places.Candidate.match_city方法的典型用法代码示例。如果您正苦于以下问题:Python Candidate.match_city方法的具体用法?Python Candidate.match_city怎么用?Python Candidate.match_city使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类omgeo.places.Candidate
的用法示例。
在下文中一共展示了Candidate.match_city方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _geocode
# 需要导入模块: from omgeo.places import Candidate [as 别名]
# 或者: from omgeo.places.Candidate import match_city [as 别名]
def _geocode(self, pq):
query = {'text':pq.query}
if pq.country:
query = dict(query, **{'boundary.country':pq.country})
if pq.viewbox is not None:
box = pq.viewbox.to_mapzen_dict()
query = dict(query, **box)
if hasattr(pq, 'key'):
# Swap to the place endpoint and return a single result.
self._endpoint = self._key_endpoint
query = { 'ids':pq.key }
if self._settings.has_key('api_key'):
query['api_key'] = self._settings['api_key']
response_obj = self._get_json_obj(self._endpoint, query)
returned_candidates = [] # this will be the list returned
features_in_response = response_obj['features']
for r in features_in_response:
properties = r['properties']
geometry = r['geometry']
score = 100 * float(properties['confidence']) \
if properties.has_key('confidence') else 0
locality = properties['locality'] \
if properties.has_key('locality') else ''
region = properties['region'] \
if properties.has_key('region') else ''
label = properties['label'] \
if properties.has_key('label') else ''
layer = properties['layer'] \
if properties.has_key('layer') else ''
c = Candidate()
c.locator = layer
c.match_addr = label
c.match_region = region
c.match_city = locality
c.locator_type = layer
c.x = float(geometry['coordinates'][0])
c.y = float(geometry['coordinates'][1])
c.score = score
c.wkid = self._wkid
c.geoservice = self.__class__.__name__
returned_candidates.append(c)
return returned_candidates