]> ToastFreeware Gitweb - philipp/winterrodeln/mediawiki_extensions/wrmap.git/blobdiff - tools/austria_simplified.py
Support countries other than Austria as well.
[philipp/winterrodeln/mediawiki_extensions/wrmap.git] / tools / austria_simplified.py
index 6b3cdbcdab945c2575487779e4c3f2dc0579d27b..653e5f40f384b6157399dcbfa1f5c54893d8bb35 100644 (file)
@@ -9,14 +9,13 @@ from shapely.wkt import dumps
 # data from https://www.naturalearthdata.com/downloads/50m-cultural-vectors/
 ZIP_FILE = '/home/philipp/daten/GeoData/naturalearth/v5.1/ne_50m_admin_0_countries.zip'
 LAYER_NAME = 'ne_50m_admin_0_countries'
-COUNTRY_NAME = 'Austria'
 
 
-def load_austria():
+def load_country(country_name: str):
     with fiona.open(f'zip://{ZIP_FILE}', layer=LAYER_NAME) as src:
         for feature in src:
             properties = feature['properties']
-            if properties['NAME'] == COUNTRY_NAME:
+            if properties['NAME'] == country_name:
                 return feature['geometry'], src.crs
 
 
@@ -49,17 +48,18 @@ def print_wkt(country):
     print(dumps(country, rounding_precision=3))
 
 
-def main(shapefile):
-    country, crs = load_austria()
+def main(country_name: str, shapefile: str | None):
+    country, crs = load_country(country_name)
     simplified_country = simplify_inner(country, crs)
     if shapefile:
-        save_country(simplified_country, crs, COUNTRY_NAME, shapefile)
+        save_country(simplified_country, crs, country_name, shapefile)
     print_wkt(simplified_country)
 
 
 if __name__ == '__main__':
-    parser = argparse.ArgumentParser(description='Creates a simplified version of Austria')
+    parser = argparse.ArgumentParser(description='Creates a simplified version of a country')
+    parser.add_argument('--country', default='Austria', help='Country to simplify (e.g. Switzerland)')
     parser.add_argument('--shapefile', default='simplified_austria.shp',
                         help='Write result to shape file with this name')
     args = parser.parse_args()
-    main(args.shapefile)
+    main(args.country, args.shapefile)