Skip to content

Commit

Permalink
Merge branch 'release-v4.0.0' into contour-lines
Browse files Browse the repository at this point in the history
  • Loading branch information
treee111 committed Apr 3, 2023
2 parents f8513af + 97b4da6 commit 95c8508
Show file tree
Hide file tree
Showing 6 changed files with 223 additions and 140 deletions.
2 changes: 1 addition & 1 deletion docs/FAQ.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ conda env remove -n gdal-user
```
followed by creating a new environment and install wahoomc into:
```
conda create -n gdal-user python=3.10 geojson=2.5 gdal=3.6 pip --channel conda-forge --override-channels
conda create -n gdal-user python=3.10 geojson=2.5 gdal=3.4 requests=2.28 shapely=1.8 pip --channel conda-forge --override-channels
conda activate gdal-user
pip install wahoomc
```
Expand Down
22 changes: 13 additions & 9 deletions tests/test_osm_maps.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import unittest

# import custom python packages
from wahoomc.osm_maps_functions import OsmData
from wahoomc.osm_maps_functions import CountryOsmData, XYOsmData
from wahoomc.osm_maps_functions import OsmMaps
from wahoomc.osm_maps_functions import get_xy_coordinates_from_input
# from wahoomc.osm_maps_functions import TileNotFoundError
Expand Down Expand Up @@ -106,14 +106,16 @@ def process_and_check_border_countries(self, inp_val, calc_border_c, exp_result,
"""

o_input_data = InputData()
o_input_data.process_border_countries = calc_border_c

if inp_mode == 'country':
o_input_data.country = inp_val
o_osm_data = CountryOsmData(o_input_data)
elif inp_mode == 'xy_coordinate':
o_input_data.xy_coordinates = inp_val
o_input_data.process_border_countries = calc_border_c
o_osm_data = XYOsmData(o_input_data)

o_osm_data = OsmData()
o_osm_data.process_input_of_the_tool(o_input_data)
o_osm_data.process_input_of_the_tool()

result = o_osm_data.border_countries

Expand All @@ -138,8 +140,8 @@ def test_input_country_malta(self):
o_input_data = InputData()
o_input_data.country = 'malta'

o_osm_data = OsmData()
o_osm_data.process_input_of_the_tool(o_input_data)
o_osm_data = CountryOsmData(o_input_data)
o_osm_data.process_input_of_the_tool()

result = o_osm_data.country_name
self.assertEqual(result, 'malta')
Expand Down Expand Up @@ -211,8 +213,10 @@ def test_version_and_tags_of_country_config_file(self):
# prevent from downloading land_polygons each time
o_input_data.max_days_old = 1000

o_osm_data = OsmData()
o_downloader = o_osm_data.process_input_of_the_tool(o_input_data)
o_osm_data = CountryOsmData(o_input_data)
o_osm_data.process_input_of_the_tool()

o_downloader = o_osm_data.get_downloader()

# download files marked for download to fill up map_file per country to write to config
o_downloader.download_files_if_needed()
Expand All @@ -224,7 +228,7 @@ def test_version_and_tags_of_country_config_file(self):
self.assertTrue(
o_osm_maps.tags_are_identical_to_last_run(o_input_data.country))

country_config = fd_fct.read_json_file(os.path.join(
country_config = fd_fct.read_json_file_country_config(os.path.join(
constants.USER_OUTPUT_DIR, o_input_data.country, ".config.json"))

self.assertEqual(constants.VERSION, country_config["version_last_run"])
Expand Down
18 changes: 8 additions & 10 deletions wahoomc/file_directory_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,26 +60,24 @@ def create_empty_directories(parent_dir, tiles_from_json, border_countries):
os.makedirs(outdir, exist_ok=True)


def read_json_file(json_file_path):
def read_json_file_country_config(json_file_path):
"""
read the tiles from the given json file
read the country config (of last run) from the given json file
"""

log.debug('-' * 80)
log.debug('# Read json file')
log.debug('# Read country config json file')

with open(json_file_path, encoding="utf-8") as json_file:
tiles_from_json = json.load(json_file)
json_file.close()
if tiles_from_json == '':
country_config = read_json_file_generic(json_file_path)
if country_config == '':
log.error('! Json file could not be opened.')
sys.exit()

log.debug(
'+ Use json file %s with %s tiles', json_file.name, len(tiles_from_json))
log.debug('+ Read json file: OK')
'+ Use country config file %s', json_file_path)
log.debug('+ Read country config json file: OK')

return tiles_from_json
return country_config


def read_json_file_generic(json_file_path):
Expand Down
13 changes: 9 additions & 4 deletions wahoomc/geofabrik.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ def compose_bouding_box(self, input) -> dict:
"""calculate bounding box based on geometry or X/Y combination"""
pass

def log_tile(self, counter, all):
"""
unified status logging for this class
"""
log.info(
'(+ tile %s of %s) Find needed countries ', counter, all)


class CountryGeofabrik(InformalGeofabrikInterface):
"""Geofabrik processing for countries"""
Expand Down Expand Up @@ -82,8 +89,7 @@ def find_needed_countries(self, bbox_tiles, wanted_map, wanted_region_polygon) -
for tile in bbox_tiles:
# Do progress indicator every 50 tiles
if counter % 50 == 0:
log.info(
'Processing tile %s of %s', counter, len(bbox_tiles)+1)
self.log_tile(counter, len(bbox_tiles)+1)
counter += 1

parent_added = 0
Expand Down Expand Up @@ -274,8 +280,7 @@ def find_needed_countries(self, bbox_tiles, wanted_map, wanted_region_polygon) -
for tile in bbox_tiles:
# Do progress indicator every 50 tiles
if counter % 50 == 0:
log.info(
'Processing tile %s of %s', counter, len(bbox_tiles)+1)
self.log_tile(counter, len(bbox_tiles)+1)
counter += 1

parent_added = 0
Expand Down
11 changes: 8 additions & 3 deletions wahoomc/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from wahoomc.downloader import download_tooling

from wahoomc.osm_maps_functions import OsmMaps
from wahoomc.osm_maps_functions import OsmData
from wahoomc.osm_maps_functions import CountryOsmData, XYOsmData

# logging used in the terminal output:
# # means top-level command
Expand Down Expand Up @@ -58,9 +58,14 @@ def run(run_level):
if o_input_data.contour:
check_installation_of_additional_programs()

o_osm_data = OsmData()
if o_input_data.country:
o_osm_data = CountryOsmData(o_input_data)
elif o_input_data.xy_coordinates:
o_osm_data = XYOsmData(o_input_data)

# Check for not existing or expired files. Mark for download, if dl is needed
o_downloader = o_osm_data.process_input_of_the_tool(o_input_data)
o_osm_data.process_input_of_the_tool()
o_downloader = o_osm_data.get_downloader()

# Download files marked for download
o_downloader.download_files_if_needed()
Expand Down
Loading

0 comments on commit 95c8508

Please sign in to comment.