DenisCarriere / geocoder

:earth_asia: Python Geocoder
http://geocoder.readthedocs.org
MIT License
1.63k stars 288 forks source link

Opencage geocoder circular lookup for Town #276

Closed nyejon closed 7 years ago

nyejon commented 7 years ago

There is a circular lookup on the Opencage geocoder which makes it unusable. The problem was introduced with merge request: #257

The following line was changed:

 @property
  def town(self):
      return self.parse['components'].get('town')

to

 return self.city

The problem is city returns town... and so the circle continues.

I will fix the issue and submit it. While I'm at it I will check that the other aliases are also configured for https://github.com/OpenCageData/address-formatting/blob/master/conf/components.yaml

nyejon commented 7 years ago

What is the best behavior for getting a component? Should all aliases return one of the other aliases if it does not exist?

For example:

@property
def city(self):
    city = self.parse['components'].get('city')
    if city:
        return city
    elif self.town:
        return self.town
    elif self.village:
        return self.village
    elif self.county:
        return self.county

Will return the town if city does not exist, but:

@property
def town(self):
    return self.parse['components'].get('town')

will only return the town if it exists. Should it be changed to:

@property
def city_aliases(self):
    town = self.parse['components'].get('town')
    city = self.parse['components'].get('city')
    village = self.parse['components'].get('village')
    county = self.parse['components'].get('county')
    if city:
        return city
    elif town :
        return town 
    elif village:
        return village
    elif county:
        return county

@property
def city(self):
    city = self.parse['components'].get('city')
    if city:
        return city
    else:
        return self.city_aliases

and then likewise for town, county and village..

ebreton commented 7 years ago

@nyejon , thanks again for your PR, the fix and improvements 👍

I guess we can close the issue, right? Feel free to open it again in any other cases! Manu

DenisCarriere commented 7 years ago

👍