当前位置: 首页>>代码示例>>Python>>正文


Python Candidate.match_region方法代码示例

本文整理汇总了Python中omgeo.places.Candidate.match_region方法的典型用法代码示例。如果您正苦于以下问题:Python Candidate.match_region方法的具体用法?Python Candidate.match_region怎么用?Python Candidate.match_region使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在omgeo.places.Candidate的用法示例。


在下文中一共展示了Candidate.match_region方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _geocode

# 需要导入模块: from omgeo.places import Candidate [as 别名]
# 或者: from omgeo.places.Candidate import match_region [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
开发者ID:lliss,项目名称:python-omgeo,代码行数:51,代码来源:__init__.py


注:本文中的omgeo.places.Candidate.match_region方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。