Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BREAKING] X/Y coordinates can be given as input parameters (e.g. for testing!) & refactoring of GUI & CLI processing #99

Merged
merged 10 commits into from
Apr 7, 2022
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ osmconvert_tempfile.*
**/__pycache__/*
**/*.pyc
**/*.DS_Store
**/*.py*.tmp

# mac/unix

Expand Down
56 changes: 55 additions & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": [
"cli",
"-fi",
"${workspaceRoot}/tests/json/germany-only1.json",
"-md",
"100",
Expand All @@ -23,6 +25,8 @@
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": [
"cli",
"-fi",
"${workspaceRoot}/tests/json/germany-only1.json",
"-tag",
"tag-wahoo-hidrive2.xml",
Expand All @@ -40,6 +44,8 @@
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": [
"cli",
"-fi",
"${workspaceRoot}/tests/json/germany-only2.json",
"-md",
"100",
Expand All @@ -55,6 +61,8 @@
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": [
"cli",
"-co",
"germany"
]
},
Expand All @@ -65,6 +73,8 @@
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": [
"cli",
"-co",
"malta",
"-tag",
"tag-wahoo.xml",
Expand All @@ -81,6 +91,8 @@
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": [
"cli",
"-co",
"malta",
"-tag",
"tag-wahoo.xml",
Expand All @@ -97,7 +109,9 @@
"request": "launch",
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": []
"args": [
"gui"
]
},
{
"name": "cli help",
Expand All @@ -116,6 +130,8 @@
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": [
"cli",
"-co",
"malta",
"-tag",
"tag-wahoo.xml",
Expand All @@ -132,6 +148,8 @@
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": [
"cli",
"-co",
"liechtenstein",
"-tag",
"tag-wahoo.xml",
Expand Down Expand Up @@ -162,6 +180,42 @@
"C:\\VSCode\\python\\wahooMapsCreator\\output\\138\\100\\land.shp",
"C:\\VSCode\\python\\wahooMapsCreator\\output\\138\\100\\land1.osm"
]
},
{
"name": "x/y: 133/88",
"type": "python",
"request": "launch",
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": [
"cli",
"-xy",
"133/88"
]
},
{
"name": "x/y: 138/100 (malta)",
"type": "python",
"request": "launch",
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": [
"cli",
"-xy",
"138/100"
]
},
{
"name": "x/y: 138/100,133/88 (two tiles)",
"type": "python",
"request": "launch",
"program": "${workspaceRoot}/wahoo_map_creator.py",
"console": "integratedTerminal",
"args": [
"cli",
"-xy",
"138/100,133/88"
]
}
]
}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ Using Anaconda to setup a virtual Python environment is the fastest way to get w
## Run wahooMapsCreator
via GUI
```
python wahoo_map_creator.py
python wahoo_map_creator.py gui
```
via CLI
```
python wahoo_map_creator.py malta
python wahoo_map_creator.py cli -co malta
```

A detailled description of the usage is documented [:computer: here](docs/USAGE.md#usage-of-wahoomapscreator)
Expand Down
54 changes: 48 additions & 6 deletions common_python/file_directory_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# import official python packages
import json
import os
from os.path import isfile, join
import subprocess
import sys
import zipfile
Expand Down Expand Up @@ -83,11 +84,12 @@ def create_empty_directories(tiles_from_json):
os.makedirs(outdir)


def read_json_file(json_file_path):
def read_json_file(json_file_path, logging = True):
"""
read the tiles from the given json file
"""
print('\n# Read json file')
if logging:
print('\n# Read json file')

with open(json_file_path) as json_file:
tiles_from_json = json.load(json_file)
Expand All @@ -96,10 +98,11 @@ def read_json_file(json_file_path):
print('! Json file could not be opened.')
sys.exit()

# logging
print(
f'+ Use json file {json_file.name} with {len(tiles_from_json)} tiles')
print('# Read json file: OK')
if logging:
# logging
print(
f'+ Use json file {json_file.name} with {len(tiles_from_json)} tiles')
print('# Read json file: OK')

return tiles_from_json

Expand All @@ -124,3 +127,42 @@ def write_to_file(file_path, request):
with open(file_path, 'wb') as file_handle:
for chunk in request.iter_content(chunk_size=1024*100):
file_handle.write(chunk)


def get_folders_in_folder(folder):
"""
return foldernames of given folder without path as list
"""
onlyfolders = [f for f in os.listdir(
folder) if not isfile(join(folder, f))]

return onlyfolders


def get_files_in_folder(folder):
"""
return filenames of given folder without path as list
"""
onlyfiles = [f for f in os.listdir(folder) if isfile(join(folder, f))]

return onlyfiles


def get_filenames_of_jsons_in_folder(folder):
"""
return json-file filenames of given folder without path as list
"""
# log.debug('function: get_filenames_of_jsons_in_folder')
# log.debug('# Read available json files from directory: "%s"', folder)

json_files = []

for file in get_files_in_folder(folder):
if file.endswith('.json'):
# filename = file.split('.')[0]
filename = os.path.splitext(file)[0]
json_files.extend([filename])

# log.debug('# Read available json files from directory: "%s" : OK', folder)

return json_files
Loading