Skip to content

Commit ddbe61e

Browse files
authored
[FEAT] Allow processing of multiple countries via CLI (#190)
* Allow input of multiple countries * move get_tiles_of_wanted_map into base class * unify xy processing with country processing - XYGeofabrik class takes raw into in _init_ method - get_xy_coordinates_from_input therefore moved to geofabrik.py - unittests adopted to new way of calling XYGeofabrik class * fix some pylint findings * Bump version to v4.0.0a1 * clarify -co and -xy cli arguments * Bump version to v4.0.0a2 * Bump version to v4.0.0a4 * enhance calc_border_countries if -nbc is given * Bump version to v4.0.0a6 * Bump version to v4.0.0a9 * calc_country_name for multiple countries
1 parent 97b4da6 commit ddbe61e

File tree

7 files changed

+208
-122
lines changed

7 files changed

+208
-122
lines changed

.vscode/launch.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,36 @@
238238
"100"
239239
]
240240
},
241+
{
242+
"name": "country: liechtenstein & suisse",
243+
"type": "python",
244+
"request": "launch",
245+
"module": "wahoomc",
246+
"console": "integratedTerminal",
247+
"args": [
248+
"cli",
249+
"-co",
250+
"liechtenstein,switzerland",
251+
"-c",
252+
"-md",
253+
"100"
254+
]
255+
},
256+
{
257+
"name": "country: malta & liechtenstein",
258+
"type": "python",
259+
"request": "launch",
260+
"module": "wahoomc",
261+
"console": "integratedTerminal",
262+
"args": [
263+
"cli",
264+
"-co",
265+
"malta,liechtenstein",
266+
"-c",
267+
"-md",
268+
"100"
269+
]
270+
},
241271
{
242272
"name": "co: france",
243273
"type": "python",

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
22
name = wahoomc
3-
version = 4.0.0a0
3+
version = 4.0.0a9
44
author = Benjamin Kreuscher
55
author_email = benni.kreuscher@gmail.com
66
description = Create maps for your Wahoo bike computer based on latest OSM maps

tests/test_geofabrik.py

Lines changed: 44 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
import os
55
# import sys
66
import unittest
7-
from shapely.geometry import shape # pylint: disable=import-error
7+
from shapely.geometry import shape # pylint: disable=import-error
88

99
# import custom python packages
1010
from wahoomc.geofabrik import CountryGeofabrik, XYGeofabrik
11-
from wahoomc.geofabrik import calc_bounding_box_tiles
11+
from wahoomc.geofabrik import calc_bounding_box_tiles, get_xy_coordinates_from_input
1212
from wahoomc.downloader import Downloader
1313
from wahoomc import constants
1414
from wahoomc.geofabrik_json import GeofabrikJson
@@ -73,8 +73,7 @@ def test_tiles_via_geofabrik_malta_xy(self):
7373
item_0 = [{'x': 138, 'y': 100, 'left': 14.0625, 'top': 36.59788913307021, 'right': 15.46875, 'bottom': 35.4606699514953, 'countries': [
7474
'italy', 'malta'], 'urls': ['https://download.geofabrik.de/europe/italy-latest.osm.pbf', 'https://download.geofabrik.de/europe/malta-latest.osm.pbf']}]
7575

76-
geofabrik_tiles = calc_tiles_via_geofabrik_json_xy(
77-
[{'x': 138, 'y': 100}])
76+
geofabrik_tiles = calc_tiles_via_geofabrik_json_xy('138/100')
7877

7978
self.assertEqual(item_0, geofabrik_tiles)
8079

@@ -97,8 +96,7 @@ def test_tiles_via_geofabrik_xy(self):
9796
'https://download.geofabrik.de/europe/germany-latest.osm.pbf']
9897
}]
9998

100-
geofabrik_tiles = calc_tiles_via_geofabrik_json_xy(
101-
[{"x": 133, "y": 88}])
99+
geofabrik_tiles = calc_tiles_via_geofabrik_json_xy('133/88')
102100

103101
self.assertEqual(geofabrik_tiles_exp, geofabrik_tiles)
104102

@@ -152,11 +150,50 @@ def test_bbox_and_shape_xy(self):
152150
bbox_tiles = calc_bounding_box_tiles(bbox)
153151
self.assertEqual(bbox_tiles_exp, bbox_tiles)
154152

155-
o_geofabrik = XYGeofabrik([{'x': 138, 'y': 100}])
153+
o_geofabrik = XYGeofabrik('138/100')
156154
wanted_region_string = str(o_geofabrik.compose_shape(bbox_tiles))
157155

158156
self.assertEqual(wanted_region_exp, wanted_region_string)
159157

158+
def test_splitting_of_single_xy_coordinate(self):
159+
"""
160+
use static json files in the repo to calculate relevant tiles
161+
"""
162+
163+
xy_tuple = get_xy_coordinates_from_input("133/88")
164+
self.assertEqual(xy_tuple, [{"x": 133, "y": 88}])
165+
166+
xy_tuple = get_xy_coordinates_from_input("11/92")
167+
self.assertEqual(xy_tuple, [{"x": 11, "y": 92}])
168+
169+
xy_tuple = get_xy_coordinates_from_input("138/100")
170+
self.assertEqual(xy_tuple, [{"x": 138, "y": 100}])
171+
172+
def test_splitting_of_multiple_xy_coordinate(self):
173+
"""
174+
use static json files in the repo to calculate relevant tiles
175+
"""
176+
177+
xy_tuple = get_xy_coordinates_from_input("133/88,138/100")
178+
expected_result = [{"x": 133, "y": 88}, {"x": 138, "y": 100}]
179+
180+
self.assertEqual(xy_tuple, expected_result)
181+
182+
# def test_get_tile_via_xy_coordinate_error(self):
183+
# """
184+
# use static json files in the repo to calculate a not-existing tile.
185+
186+
# does not error out due to new Geofabrik Json processing. Nevertheless, the tile is not existing
187+
# only +/- 180 -/+90: https://epsg.io/4326
188+
# """
189+
190+
# o_geofabrik = XYGeofabrik([{"x": 200, "y": 1}])
191+
192+
# # tiles =
193+
194+
# with self.assertRaises(TileNotFoundError):
195+
# o_geofabrik.get_tiles_of_wanted_map()
196+
160197

161198
if __name__ == '__main__':
162199
unittest.main()

tests/test_osm_maps.py

Lines changed: 17 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
# import custom python packages
99
from wahoomc.osm_maps_functions import CountryOsmData, XYOsmData
1010
from wahoomc.osm_maps_functions import OsmMaps
11-
from wahoomc.osm_maps_functions import get_xy_coordinates_from_input
1211
# from wahoomc.osm_maps_functions import TileNotFoundError
1312
from wahoomc.input import InputData
1413
from wahoomc import file_directory_functions as fd_fct
@@ -40,6 +39,13 @@ def test_calc_border_countries_input_country(self):
4039
self.process_and_check_border_countries(
4140
'germany', True, expected_result, 'country')
4241

42+
# germany,malta
43+
expected_result = {'czech-republic': {}, 'germany': {}, 'austria': {}, 'liechtenstein': {},
44+
'switzerland': {}, 'italy': {}, 'netherlands': {}, 'belgium': {},
45+
'luxembourg': {}, 'france': {}, 'poland': {}, 'denmark': {}, 'sweden': {}, 'malta': {}}
46+
self.process_and_check_border_countries(
47+
'germany,malta', True, expected_result, 'country')
48+
4349
def test_calc_border_countries_input_xy_coordinates_1tile(self):
4450
"""
4551
Test initialized border countries
@@ -78,7 +84,15 @@ def test_calc_without_border_countries_input_country(self):
7884
self.process_and_check_border_countries(
7985
'china', False, {'china': {}}, 'country')
8086

81-
def test_calc_without_border_countries__xy_coordinates_1tile(self):
87+
# malta,liechtenstein
88+
self.process_and_check_border_countries(
89+
'malta,liechtenstein', False, {'malta': {}, 'liechtenstein': {}}, 'country')
90+
91+
# malta,tunisia
92+
self.process_and_check_border_countries(
93+
'malta,tunisia', False, {'malta': {}, 'tunisia': {}}, 'country')
94+
95+
def test_calc_without_border_countries_xy_coordinates_1tile(self):
8296
"""
8397
Test initialized countries without border countries
8498
- of one tile
@@ -89,7 +103,7 @@ def test_calc_without_border_countries__xy_coordinates_1tile(self):
89103
self.process_and_check_border_countries(
90104
"133/88", False, expected_result, 'xy_coordinate')
91105

92-
def test_calc_without_border_countries__xy_coordinates_2tiles(self):
106+
def test_calc_without_border_countries_xy_coordinates_2tiles(self):
93107
"""
94108
Test initialized countries without border countries
95109
- of two tiles
@@ -146,45 +160,6 @@ def test_input_country_malta(self):
146160
result = o_osm_data.country_name
147161
self.assertEqual(result, 'malta')
148162

149-
def test_splitting_of_single_xy_coordinate(self):
150-
"""
151-
use static json files in the repo to calculate relevant tiles
152-
"""
153-
154-
xy_tuple = get_xy_coordinates_from_input("133/88")
155-
self.assertEqual(xy_tuple, [{"x": 133, "y": 88}])
156-
157-
xy_tuple = get_xy_coordinates_from_input("11/92")
158-
self.assertEqual(xy_tuple, [{"x": 11, "y": 92}])
159-
160-
xy_tuple = get_xy_coordinates_from_input("138/100")
161-
self.assertEqual(xy_tuple, [{"x": 138, "y": 100}])
162-
163-
def test_splitting_of_multiple_xy_coordinate(self):
164-
"""
165-
use static json files in the repo to calculate relevant tiles
166-
"""
167-
168-
xy_tuple = get_xy_coordinates_from_input("133/88,138/100")
169-
expected_result = [{"x": 133, "y": 88}, {"x": 138, "y": 100}]
170-
171-
self.assertEqual(xy_tuple, expected_result)
172-
173-
# def test_get_tile_via_xy_coordinate_error(self):
174-
# """
175-
# use static json files in the repo to calculate a not-existing tile.
176-
177-
# does not error out due to new Geofabrik Json processing. Nevertheless, the tile is not existing
178-
# only +/- 180 -/+90: https://epsg.io/4326
179-
# """
180-
181-
# o_geofabrik = XYGeofabrik([{"x": 200, "y": 1}])
182-
183-
# # tiles =
184-
185-
# with self.assertRaises(TileNotFoundError):
186-
# o_geofabrik.get_tiles_of_wanted_map()
187-
188163
def test_encoding_open_sea_osm(self):
189164
"""
190165
use static json files in the repo to calculate relevant tile

0 commit comments

Comments
 (0)