本文整理汇总了Python中omgeo.places.Candidate类的典型用法代码示例。如果您正苦于以下问题:Python Candidate类的具体用法?Python Candidate怎么用?Python Candidate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Candidate类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _geocode
def _geocode(self, pq):
query = {"format": "json", "benchmark": "Public_AR_Current"}
if pq.query:
_this_endpoint = "%s%s" % (self._endpoint_base, "onelineaddress")
query["address"] = pq.query
else:
_this_endpoint = "%s%s" % (self._endpoint_base, "address")
query["street"] = pq.address
query["city"] = pq.city
query["state"] = pq.state
query["zip"] = pq.postal
logger.debug("CENSUS QUERY: %s", query)
response_obj = self._get_json_obj(_this_endpoint, query)
logger.debug("CENSUS RESPONSE: %s", response_obj)
returned_candidates = [] # this will be the list returned
for r in response_obj["result"]["addressMatches"]:
c = Candidate()
c.match_addr = r["matchedAddress"]
c.x = r["coordinates"]["x"]
c.y = r["coordinates"]["y"]
c.geoservice = self.__class__.__name__
# Optional address component fields.
for in_key, out_key in [("city", "match_city"), ("state", "match_region"), ("zip", "match_postal")]:
setattr(c, out_key, r["addressComponents"].get(in_key, ""))
setattr(c, "match_subregion", "") # No county from Census geocoder.
setattr(c, "match_country", "USA") # Only US results from Census geocoder
setattr(c, "match_streetaddr", self._street_addr_from_response(r))
returned_candidates.append(c)
return returned_candidates
示例2: _geocode
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
示例3: _geocode
def _geocode(self, location):
query = {
'SingleLine':location.query,
'Address':location.address,
'City':location.city,
'State':location.state,
'Zip':location.postal,
'Country':location.country,
'outfields':'Loc_name,Addr_Type,Zip4_Type',
'f':'json'}
query = self.append_token_if_needed(query)
response_obj = self._get_json_obj(self._endpoint, query)
try:
wkid = response_obj['spatialReference']['wkid']
except KeyError:
pass
returned_candidates = [] # this will be the list returned
try:
for rc in response_obj['candidates']:
c = Candidate()
c.locator = rc['attributes']['Loc_name']
c.score = rc['score']
c.match_addr = rc['address']
c.x = rc['location']['x']
c.y = rc['location']['y']
c.wkid = wkid
c.geoservice = self.__class__.__name__
returned_candidates.append(c)
except KeyError:
pass
return returned_candidates
示例4: _geocode
def _geocode(self, location):
query = {
'Address':location.address,
'City':location.city,
'Postcode':location.postal,
'Country':location.country,
'outfields':'Loc_name',
'f':'json'}
query = self.append_token_if_needed(query)
response_obj = self._get_json_obj(self._endpoint, query)
if response_obj is False: return []
returned_candidates = [] # this will be the list returned
try:
for rc in response_obj['candidates']:
c = Candidate()
c.locator = rc['attributes']['Loc_name']
c.score = rc['score']
c.match_addr = rc['address']
c.x = rc['location']['x']
c.y = rc['location']['y']
c.wkid = self._wkid
c.geoservice = self.__class__.__name__
returned_candidates.append(c)
except KeyError as ex:
print "I'm not what you expected, but hey, I'm still JSON! %s" % ex #TODO: put on error stack
return []
return returned_candidates
示例5: _get_candidates_from_record_set
def _get_candidates_from_record_set(self, record_set):
"""
Given a RecordSet, create a list of Candidate objects for processing
"""
candidates = []
for record in record_set.Records.Record:
c_dict = {}
for field, value in zip(record_set.Fields.FieldArray.Field,
record.Values.Value):
if field.Name in self._mapping:
c_dict[self._mapping[field.Name]] = value
candidate = Candidate(**c_dict)
candidate.wkid = self._wkid
candidate.geoservice = self.__class__.__name__
candidates.append(candidate)
return candidates
示例6: _create_candidate_from_intersection_element
def _create_candidate_from_intersection_element(intersection_element, source_operation):
c = Candidate()
c.locator = source_operation
c.match_addr = _get_text_from_nodelist(
intersection_element.getElementsByTagName("FULLINTERSECTION")[0].childNodes) + ", WASHINGTON, DC"
c.y = float(_get_text_from_nodelist(intersection_element.getElementsByTagName("LATITUDE")[0].childNodes))
c.x = float(_get_text_from_nodelist(intersection_element.getElementsByTagName("LONGITUDE")[0].childNodes))
confidence_level_elements = intersection_element.getElementsByTagName("ConfidenceLevel")
c.score = float(_get_text_from_nodelist(confidence_level_elements[0].childNodes))
c.geoservice = self.__class__.__name__
return c
示例7: _create_candidate_from_address_element
def _create_candidate_from_address_element(match, source_operation):
if match.getElementsByTagName("FULLADDRESS").length > 0:
full_address = _get_text_from_nodelist(match.getElementsByTagName("FULLADDRESS")[0].childNodes)
else:
full_address = _get_text_from_nodelist(
match.getElementsByTagName("STNAME")[0].childNodes) + " " + _get_text_from_nodelist(match.getElementsByTagName("STREET_TYPE")[0].childNodes)
city = _get_text_from_nodelist(match.getElementsByTagName("CITY")[0].childNodes)
state = _get_text_from_nodelist(match.getElementsByTagName("STATE")[0].childNodes)
zipcode = _get_text_from_nodelist(match.getElementsByTagName("ZIPCODE")[0].childNodes)
c = Candidate()
c.match_addr = full_address + ", " + city + ", " + state + ", " + zipcode
confidence_level_elements = match.getElementsByTagName("ConfidenceLevel")
c.score = float(_get_text_from_nodelist(confidence_level_elements[0].childNodes))
c.y = float(_get_text_from_nodelist(match.getElementsByTagName("LATITUDE")[0].childNodes))
c.x = float(_get_text_from_nodelist(match.getElementsByTagName("LONGITUDE")[0].childNodes))
c.locator = source_operation
c.geoservice = self.__class__.__name__
return c
示例8: _geocode
def _geocode(self, pq):
def get_appended_location(location, **kwargs):
"""Add key/value pair to given dict only if value is not empty string."""
for kw in kwargs:
if kwargs[kw] != '':
location = dict(location, **{kw: kwargs[kw]})
return location
if pq.address.strip() != '':
location = {}
location = get_appended_location(location, street=pq.query)
if location == {}:
location = get_appended_location(location, street=pq.address)
location = get_appended_location(location, city=pq.city, county=pq.subregion, state=pq.state,
postalCode=pq.postal, country=pq.country)
json_ = dict(location=location)
json_ = json.dumps(json_)
query = dict(key=unquote(self._settings['api_key']),
json=json_)
else:
query = dict(key=unquote(self._settings['api_key']),
location=pq.query)
if pq.viewbox is not None:
query = dict(query, viewbox=pq.viewbox.to_mapquest_str())
response_obj = self._get_json_obj(self._endpoint, query)
returned_candidates = [] # this will be the list returned
for r in response_obj['results'][0]['locations']:
c = Candidate()
c.locator=r['geocodeQuality']
c.confidence=r['geocodeQualityCode'] #http://www.mapquestapi.com/geocoding/geocodequality.html
match_addr_elements = ['street', 'adminArea5', 'adminArea3',
'adminArea2', 'postalCode'] # similar to ESRI
c.match_addr = ', '.join([r[k] for k in match_addr_elements if k in r])
c.x = r['latLng']['lng']
c.y = r['latLng']['lat']
c.wkid = 4326
c.geoservice = self.__class__.__name__
returned_candidates.append(c)
return returned_candidates
示例9: _make_candidate_from_result
def _make_candidate_from_result(self, result):
""" Make a Candidate from a Google geocoder results dictionary. """
candidate = Candidate()
candidate.match_addr = result['formatted_address']
candidate.x = result['geometry']['location']['lng']
candidate.y = result['geometry']['location']['lat']
candidate.locator = self.LOCATOR_MAPPING.get(result['geometry']['location_type'], '')
component_lookups = {
'city': {'type': 'locality', 'key': 'long_name'},
'subregion': {'type': 'administrative_area_level_2', 'key': 'long_name'},
'region': {'type': 'administrative_area_level_1', 'key': 'short_name'},
'postal': {'type': 'postal_code', 'key': 'long_name'},
'country': {'type': 'country', 'key': 'short_name'},
}
for (field, lookup) in component_lookups.iteritems():
setattr(candidate, 'match_' + field, self._get_component_from_result(result, lookup))
candidate.geoservice = self.__class__.__name__
return candidate