From 22face4e7b11564c4414b156640870541f4343f6 Mon Sep 17 00:00:00 2001 From: Aun Johnsen Date: Sat, 2 Sep 2017 21:06:02 +0300 Subject: [PATCH] relation without shape -> None --- fetch_kml.py | 10 ++++++++-- gpx/gpx_data.py | 4 ++++ gpx/gpx_store.py | 3 +++ gpx/gpx_utils.py | 2 ++ 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/fetch_kml.py b/fetch_kml.py index 05438cb..4deea7e 100755 --- a/fetch_kml.py +++ b/fetch_kml.py @@ -25,13 +25,19 @@ gpx_store.init_cache() -tags = gpx_data.load_tags(args.obj_id, args.obj_level) +try: + tags = gpx_data.load_tags(args.obj_id, args.obj_level) +except: + tags = dict({ 'name': 'unknown', }) name = str(args.obj_id) if 'name:en' in tags: name = tags['name:en'] else: - name = tags['name'] + try: + name = tags['name'] + except: + pass geos = gpx_data.load_geo_shape(args.obj_id, args.obj_level, name) gpx_store.store_kml(geos, args.obj_id, args.obj_level, name) diff --git a/gpx/gpx_data.py b/gpx/gpx_data.py index cc363de..1d20be4 100644 --- a/gpx/gpx_data.py +++ b/gpx/gpx_data.py @@ -36,6 +36,10 @@ def geojson_to_geometry(data, name): ########################### + if len(my_ways) == 0: + __LOG.critical("Relation have no shape: %s" % name ) + return None + rings = [] lines = [] diff --git a/gpx/gpx_store.py b/gpx/gpx_store.py index 5e87ea2..7fb9129 100644 --- a/gpx/gpx_store.py +++ b/gpx/gpx_store.py @@ -148,6 +148,9 @@ def store_wkb(obj, obj_id, admin_level): :param int admin_level: The subdir (usually the administrative level) :return: None """ + if obj == None: + return None + filename = '%s/geos/%s/%s.wkb' % (cache_dir, admin_level, obj_id) __LOG.info(u'store_wkb: storing a %s with size: %s ', obj.geom_type, obj.area) diff --git a/gpx/gpx_utils.py b/gpx/gpx_utils.py index b2c1b84..d81885f 100644 --- a/gpx/gpx_utils.py +++ b/gpx/gpx_utils.py @@ -109,6 +109,8 @@ def test_object(track, obj): :param obj: The polygon object to test against. :return bool: If the object """ + if obj == None: + return False if track.within(obj): return True if track.intersects(obj):