Commit 6863aa70 authored by Akshat Tandon's avatar Akshat Tandon

Making script more general so that it runs for datasets other than Natural Earth.

The script uses some metadata key values which are specific only to the Natural Earth dataset. This change enables checking of specific keys before usage to prevent crashes at runtime in case the SHP dataset is not from Natural Earth.
parent c8503e1d
......@@ -426,11 +426,22 @@ def clean_attr(val):
val = val.replace("&", "&amp;").replace("'", "&quot;").replace("<", "&lt;").replace(">", "&gt;").strip()
return val
def check_featurecla(f):
Checks if featurecla field is present in the feature f.
If present it implies that shp data is from Natural Earth dataset
if 'featurecla' in f.keys():
return True
return False
def add_point(f):
"""Adds a point geometry to the OSM file"""
global id_counter
airport_metadata = None
pt = f.GetGeometryRef()
if check_featurecla(f):
if f['featurecla'] == 'Airport':
airport_metadata = f
f = None
......@@ -461,6 +472,7 @@ def add_relation_multipolygon(geom, f):
return None
rel_id = id_counter
if check_featurecla(f):
if f['featurecla'] in non_polygons:
return 0 #means no relation is there
relations.append((rel_id, rel_ways))
......@@ -503,6 +515,7 @@ def write_tags(f):
for name, value in fixed_tags.items():
print(" <tag k='%s' v='%s' />" % (name, clean_attr(value)) , end = '\n', file = open_file)
if f.GetGeometryRef().GetGeometryName() == 'POLYGON' or f.GetGeometryRef().GetGeometryName() == 'MULTIPOLYGON':
if check_featurecla(f):
if f['featurecla'] not in non_polygons:
print(" <tag k='area' v='yes' />" , end = '\n', file = open_file)
......@@ -780,3 +793,4 @@ if __name__ == "__main__":
if non_geom != 0:
print('Unknown geometry present in SHP file: ', non_geom)
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment