Skip to content

Commit

Permalink
Merge pull request #68 from rajadain/tt/67/fix-magickey-geocoding
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadain authored Jan 22, 2024
2 parents 329beed + de75706 commit 82d7363
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/continuous_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ jobs:

- name: Run tests
run: python setup.py test
env:
BING_MAPS_API_KEY: ${{ secrets.BING_MAPS_API_KEY }}
ESRI_CLIENT_ID: ${{ secrets.ESRI_CLIENT_ID }}
ESRI_CLIENT_SECRET: ${{ secrets.ESRI_CLIENT_SECRET }}
GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
MAPQUEST_API_KEY: ${{ secrets.MAPQUEST_API_KEY }}
PELIAS_API_KEY: ${{ secrets.PELIAS_API_KEY }}
# env:
# BING_MAPS_API_KEY: ${{ secrets.BING_MAPS_API_KEY }}
# ESRI_CLIENT_ID: ${{ secrets.ESRI_CLIENT_ID }}
# ESRI_CLIENT_SECRET: ${{ secrets.ESRI_CLIENT_SECRET }}
# GOOGLE_API_KEY: ${{ secrets.GOOGLE_API_KEY }}
# MAPQUEST_API_KEY: ${{ secrets.MAPQUEST_API_KEY }}
# PELIAS_API_KEY: ${{ secrets.PELIAS_API_KEY }}

7 changes: 5 additions & 2 deletions omgeo/services/esri.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,15 @@ class EsriWGS(GeocodeService):
DEFAULT_POSTPROCESSORS = [
AttrFilter(['PointAddress',
'StreetAddress',
'Locality',
# 'PostalExt',
# 'Postal'
],
'locator_type'),
# AttrExclude(['USA_Postal'], 'locator'), #accept postal from everywhere but US (need PostalExt)
AttrSorter(['PointAddress',
'StreetAddress',
'Locality',
# 'PostalExt',
# 'Postal'
],
Expand Down Expand Up @@ -195,7 +197,7 @@ def _geocode(self, pq):
c = Candidate()
attributes = location['attributes']
c.match_addr = attributes['Match_addr']
c.locator = attributes['Loc_name']
c.locator = attributes.get('Loc_name', '')
c.locator_type = attributes['Addr_type']
c.score = attributes['Score']
c.x = attributes['DisplayX'] # represents the actual location of the address.
Expand All @@ -210,7 +212,8 @@ def _geocode(self, pq):
setattr(c, out_key, attributes.get(in_key, ''))
setattr(c, 'match_streetaddr', self._street_addr_from_response(attributes))
returned_candidates.append(c)
except KeyError:
except KeyError as e:
logger.warning('Missing key: ' + e)
pass
return returned_candidates

Expand Down
15 changes: 13 additions & 2 deletions omgeo/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ def test_geocode_esri_wgs_340_12th_bounded(self):
self.assertEqual('340 N 12th' in candidates[0].match_addr, True,
'"340 N 12th" not found in match_addr. Got "%s"' % candidates[0].match_addr)

def test_geocode_esri_wgs_magicKey(self):
"""Check that geocoding New York, USA with a magicKey returns one result."""
esri = self.g_esri_wgs._sources[0]
suggestions = esri._get_json_obj(
f'{esri._endpoint}/suggest',
{'f': 'json', 'text': 'New York, USA'})['suggestions']
pq = PlaceQuery(suggestions[0]['text'], key=suggestions[0]['magicKey'])
candidates = self.g_esri_wgs.get_candidates(pq)
self.assertOneCandidate(candidates)

def test_geocode_esri_wgs_zip_plus_4(self):
"""Check that geocoding 19127-1112 returns one result."""
candidates = self.g_esri_wgs_postal_ok.get_candidates(self.pq['zip_plus_4_in_postal_plus_country'])
Expand All @@ -229,6 +239,7 @@ def test_esri_short_region(self):
candidate = self.g_esri_wgs.get_candidates(self.pq["azavea"])[0]
self.assertEqual(candidate.match_region, "PA")

@unittest.skipIf(GOOGLE_API_KEY is None, GOOGLE_KEY_REQUIRED_MSG)
def test_google_short_region(self):
"""Ensure that Google uses region abbreviations"""
candidate = self.g_google.get_candidates(self.pq["azavea"])[0]
Expand Down Expand Up @@ -272,8 +283,8 @@ def test_geocode_nom(self):
self.assertEqual(len(candidates) > 0, True, 'No candidates returned.')

def test_geocode_census(self):
"""Test Azavea's address using US Census geocoder."""
candidates = self.g_census.get_candidates(PlaceQuery('1200 Callowhill St, Philadelphia, PA'))
"""Test Element 84's address using US Census geocoder."""
candidates = self.g_census.get_candidates(PlaceQuery('210 N. Lee Street, Alexandria, VA'))
self.assertEqual(len(candidates) > 0, True, 'No candidates returned.')

def test_EsriWGS_address_components(self):
Expand Down

0 comments on commit 82d7363

Please sign in to comment.