示例#1
0
def get_coordinates(address, limit=10):
    """
    Returns a list of dict with keys:

        label (str)
        latitude (float)
        longitude (float)
    """
    if not address:
        return []

    features = []
    for result in datagouv.search(address, limit=limit):
        try:
            feature = {
                'latitude': result['geometry']['coordinates'][1],
                'longitude': result['geometry']['coordinates'][0],
                'label': result['properties']['label'],
                'zipcode': result['properties']['postcode'],
                'city': result['properties']['city']
            }
            # The zipcode is normally always present in the label,
            # but sometimes is inconsistently absent from it (e.g. Saint-Paul)
            # thus we add it if necessary.
            if feature['zipcode'] not in feature['label']:
                feature['label'] += " %s" % feature['zipcode']
            features.append(feature)
        except KeyError:
            continue

    return unique_elements(features,
                           key=lambda x: (x['latitude'], x['longitude']))
示例#2
0
def format_addresses(addresses):
    features = []
    for result in addresses:
        try:
            features.append({
                'label': result['properties']['label'],
                'zipcode': result['properties']['postcode'],
                'city': result['properties']['city'],
                'city_code': result['properties']['citycode'],
            })
        except KeyError:
            pass
    return unique_elements(features)
示例#3
0
def get_address(latitude, longitude, limit=10):
    """
    Returns a list of dict with keys:

        label (str)
        zipcode (str)
        city (str)
    """
    features = []
    for result in datagouv.reverse(latitude, longitude, limit=limit):
        try:
            features.append({
                'label': result['properties']['label'],
                'zipcode': result['properties']['postcode'],
                'city': result['properties']['city']
            })
        except KeyError:
            pass
    return unique_elements(features)
示例#4
0
def format_coordinates(addresses):
    features = []
    for result in addresses:
        try:
            feature = {
                'latitude': result['geometry']['coordinates'][1],
                'longitude': result['geometry']['coordinates'][0],
                'label': result['properties']['label'],
                'zipcode': result['properties']['postcode'],
                'city': result['properties']['city'],
                'city_code': result['properties']['citycode'],
                'score': result['properties']['score'],
            }
            # The zipcode is normally always present in the label,
            # but sometimes is inconsistently absent from it (e.g. Saint-Paul)
            # thus we add it if necessary.
            if feature['zipcode'] not in feature['label']:
                feature['label'] += " %s" % feature['zipcode']
            features.append(feature)
        except KeyError:
            continue

    return unique_elements(features,
                           key=lambda x: (x['latitude'], x['longitude']))