Beispiel #1
0
    def make(self, obj):
        admins = value_by_path(obj,
                               'properties.geocoding.administrative_regions',
                               [])
        if admins:

            def make_admin(admin):
                res = {
                    'id': admin['id'],
                    'insee': admin['insee'],
                    'name': admin['name'],
                    'label': admin['label'],
                    'level': admin['level'],
                    'coord': {
                        'lon': str(admin['coord']['lon']),
                        'lat': str(admin['coord']['lat'])
                    },
                }
                zip_codes = admin.get('zip_codes', [])
                if all(zip_code == "" for zip_code in zip_codes):
                    pass
                elif len(zip_codes) == 1:
                    res['zip_code'] = zip_codes[0]
                else:
                    res['zip_code'] = '{}-{}'.format(min(zip_codes),
                                                     max(zip_codes))
                return res

            return [make_admin(admin) for admin in admins]
        admins = obj.get('properties', {}).get('geocoding',
                                               {}).get('admin', {})
        return [{
            "insee": None,
            "name": name,
            "level": int(level.replace('level', '')),
            "coord": {
                "lat": None,
                "lon": None
            },
            "label": None,
            "id": None,
            "zip_code": None,
        } for level, name in admins.items()]
Beispiel #2
0
 def generate_coord_id(self, obj):
     coords = value_by_path(obj, 'geometry.coordinates')
     if coords and len(coords) >= 2:
         return '{};{}'.format(coords[0], coords[1])
     return None
Beispiel #3
0
 def generate_coord_field(self, obj):
     coords = value_by_path(obj, 'geometry.coordinates')
     res = {'lat': None, 'lon': None}
     if coords and len(coords) >= 2:
         res.update({'lat': str(coords[1]), 'lon': str(coords[0])})
     return res