Commit 0a5d84d9 authored by Eric Duminil's avatar Eric Duminil
Browse files

Allow to specify output folder.

parent 6c2f4d01
Showing with 12 additions and 9 deletions
+12 -9
......@@ -221,7 +221,7 @@ def parse_arguments():
epilog="""
Examples:
python download_LoD2_from_LGL_BW.py StuttgartCenter "POLYGON((9.175287 48.780916, 9.185501 48.777522, 9.181467 48.773704, 9.174429 48.768472, 9.168807 48.773902, 9.175287 48.780916))"
python download_LoD2_from_LGL_BW.py Freiburg "79098,79102"
python download_LoD2_from_LGL_BW.py Freiburg "79098,79102" --output-folder="/path/to/FreiburgFolder"
python download_LoD2_from_LGL_BW.py Möhringen "70567" --download-only
"""
)
......@@ -239,21 +239,24 @@ Examples:
help='Path to SimStadt installation folder. By default, tries to find it on the Desktop.')
parser.add_argument('--output-folder', type=Path, default=None,
help='Folder in which the tiles should be downloaded and extracted. By default, use the folder of the current script.')
help='Folder in which the tiles should be downloaded and extracted. By default, use the folder of the current script / name.proj.')
return parser.parse_args()
def main(location_name: str, wkt_or_zipcode: str, download_only: bool = False, simstadt_folder: Path | None = None):
def main(location_name: str, wkt_or_zipcode: str, download_only: bool = False,
simstadt_folder: Path | None = None, output_folder: Path | None = None):
"""Main function to process arguments and run the download/extraction"""
# Validate location name
if ' ' in location_name:
raise ValueError("Location name should not contain spaces: 'Some City' -> 'SomeCity'")
# Create output directory
output_dir = SCRIPT_DIR / (location_name + '.proj')
output_dir.mkdir(parents=True, exist_ok=True)
if not output_folder:
# Create output directory
output_folder = SCRIPT_DIR / (location_name + '.proj')
output_folder.mkdir(parents=True, exist_ok=True)
# Get WKT string
wkt_str = get_wkt(wkt_or_zipcode)
......@@ -262,7 +265,7 @@ def main(location_name: str, wkt_or_zipcode: str, download_only: bool = False, s
x1, x2, y1, y2 = wkt_polygon_to_grid_coords(location_name, wkt_str)
# Download region
download_whole_region(output_dir, wkt_str, x1, x2, y1, y2)
download_whole_region(output_folder, wkt_str, x1, x2, y1, y2)
# Extract region if not download-only
if not download_only:
......@@ -272,7 +275,7 @@ def main(location_name: str, wkt_or_zipcode: str, download_only: bool = False, s
"No SimStadt installation found! Please provide --simstadt-folder or use --download-only.")
return
extract_region(output_dir, location_name, wkt_str, simstadt_folder)
extract_region(output_folder, location_name, wkt_str, simstadt_folder)
else:
logger.info("Download-only mode: Skipping region extraction.")
......@@ -281,4 +284,4 @@ def main(location_name: str, wkt_or_zipcode: str, download_only: bool = False, s
if __name__ == '__main__':
args = parse_arguments()
main(args.name, args.region, args.download_only, args.simstadt_folder)
main(args.name, args.region, args.download_only, args.simstadt_folder, args.output_folder)
Supports Markdown
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