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


Python Candidate.entity方法代码示例

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


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

示例1: _geocode

# 需要导入模块: from omgeo.places import Candidate [as 别名]
# 或者: from omgeo.places.Candidate import entity [as 别名]
    def _geocode(self, pq):
        if pq.query.strip() == '':
            # No single line query string; use address elements:
            query = {'addressLine':pq.address,
                     'locality':pq.city,
                     'adminDistrict':pq.state,
                     'postalCode':pq.postal,
                     'countryRegion':pq.country}
        else:
            query = {'query':pq.query}
        
        if pq.viewbox is not None:
            query = dict(query, **{'umv':pq.viewbox.to_bing_str()})
        if hasattr(pq, 'culture'): query = dict(query, c=pq.culture)
        if hasattr(pq, 'user_ip'): query = dict(query, uip=pq.user_ip)
        if hasattr(pq, 'user_lat') and hasattr(pq, 'user_lon'):
            query = dict(query, **{'ul':'%f,%f' % (pq.user_lat, pq.user_lon)})

        addl_settings = {'key':self._settings['api_key']}
        query = dict(query, **addl_settings)
        response_obj = self._get_json_obj(self._endpoint, query)
        returned_candidates = [] # this will be the list returned
        for r in response_obj['resourceSets'][0]['resources']:    
            c = Candidate()
            c.entity = r['entityType']
            c.locator = r['geocodePoints'][0]['calculationMethod'] # ex. "Parcel"
            c.confidence = r['confidence'] # High|Medium|Low
            c.match_addr = r['name'] # ex. "1 Microsoft Way, Redmond, WA 98052"
            c.x = r['geocodePoints'][0]['coordinates'][1] # long, ex. -122.13
            c.y = r['geocodePoints'][0]['coordinates'][0] # lat, ex. 47.64
            c.wkid = 4326
            c.geoservice = self.__class__.__name__
            returned_candidates.append(c)
        return returned_candidates
开发者ID:joetric,项目名称:python-omgeo,代码行数:36,代码来源:__init__.py

示例2: _geocode

# 需要导入模块: from omgeo.places import Candidate [as 别名]
# 或者: from omgeo.places.Candidate import entity [as 别名]
    def _geocode(self, pq):
        query = {'q':pq.query,
                 'countrycodes':pq.country, # only takes ISO-2
                 'format':'json'}

        if pq.viewbox is not None:
            query = dict(query, **{'viewbox':pq.viewbox.to_mapquest_str(), 'bounded':pq.bounded})

        response_obj = self._get_json_obj(self._endpoint, query)

        returned_candidates = [] # this will be the list returned
        for r in response_obj:
            c = Candidate()
            c.locator = 'parcel' # we don't have one but this is the closest match
            c.entity = '%s.%s' % (r['class'], r['type']) # ex.: "place.house"
            c.match_addr = r['display_name'] # ex. "Wolf Building, 340, N 12th St, Philadelphia, Philadelphia County, Pennsylvania, 19107, United States of America" #TODO: shorten w/ pieces
            c.x = float(r['lon']) # long, ex. -122.13 # cast to float in 1.3.4
            c.y = float(r['lat']) # lat, ex. 47.64 # cast to float in 1.3.4
            c.wkid = self._wkid
            c.geoservice = self.__class__.__name__
            returned_candidates.append(c)
        return returned_candidates
开发者ID:lliss,项目名称:python-omgeo,代码行数:24,代码来源:__init__.py


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