def location_from_dictionary(d):
    """
    Builds a *Location* object out of a data dictionary. Only certain
    properties of the dictionary are used: if these properties are not
    found or cannot be read, an error is issued.

    :param d: a data dictionary
    :type d: dict
    :returns: a *Location* instance
    :raises: *KeyError* if it is impossible to find or read the data
        needed to build the instance

    """
    country = None
    if 'sys' in d and 'country' in d['sys']:
        country = d['sys']['country']
    if 'city' in d:
        data = d['city']
    else:
        data = d
    if 'name' in data:
        name = data['name']
    else:
        name = None
    if 'id' in data:
        ID = int(data['id'])
    else:
        ID = None
    if 'coord' in data:
        lon = data['coord'].get('lon', 0.0)
        lat = data['coord'].get('lat', 0.0)
    elif 'coord' in data['station']:
        if 'lon' in data['station']['coord']:
            lon = data['station']['coord'].get('lon', 0.0)
        elif 'lng' in data['station']['coord']:
            lon = data['station']['coord'].get('lng', 0.0)
        else:
            lon = 0.0
        lat = data['station']['coord'].get('lat', 0.0)
    else:
        raise KeyError("Impossible to read geographical coordinates from JSON")
    if 'country' in data:
        country = data['country']
    return Location(name, lon, lat, ID, country)
Builds a *Location* object out of a data dictionary. Only certain
    properties of the dictionary are used: if these properties are not
    found or cannot be read, an error is issued.

    :param d: a data dictionary
    :type d: dict
    :returns: a *Location* instance
    :raises: *KeyError* if it is impossible to find or read the data
        needed to build the instance