From 091584bb0dfeebb379ec0dc0439e378a81c02926 Mon Sep 17 00:00:00 2001 From: Fabian Neumann Date: Mon, 9 Oct 2023 16:22:27 +0200 Subject: [PATCH] add download rules for WDPA land and marine --- rules/retrieve.smk | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/rules/retrieve.smk b/rules/retrieve.smk index a122ffc7..f300b1aa 100644 --- a/rules/retrieve.smk +++ b/rules/retrieve.smk @@ -220,6 +220,65 @@ if config["enable"]["retrieve"]: RESOURCES + "Copernicus_LC100_global_v3.0.1_2019-nrt_Discrete-Classification-map_EPSG-4326.tif", run: move(input[0], output[0]) + +if config["enable"]["retrieve"]: + + from datetime import datetime + current_month = datetime.now().strftime('%b') + current_year = datetime.now().strftime('%Y') + bYYYY = f"{current_month}{current_year}" + + + # Downloading protected area database from WDPA + # extract the main zip and then merge the contained 3 zipped shapefiles + # Website: https://www.protectedplanet.net/en/thematic-areas/wdpa + rule download_wdpa: + input: + HTTP.remote( + f"d1gam3xoknrgr2.cloudfront.net/current/WDPA_{bYYYY}_Public_shp.zip", + static=True, + keep_local=True, + ) + params: + zip=RESOURCES + f"WDPA_{bYYYY}_shp.zip", + folder=directory(RESOURCES + f"WDPA_{bYYYY}"), + output: + gpkg=RESOURCES + f"WDPA_{bYYYY}.gpkg", + run: + shell("cp {input} {params.zip}") + shell("unzip -o {params.zip} -d {params.folder}") + for i in range(3): + # vsizip is special driver for directly working with zipped shapefiles in ogr2ogr + layer_path = f"/vsizip/{params.folder}/WDPA_{bYYYY}_Public_shp_{i}.zip" + print(f"Adding layer {i+1} of 3 to combined output file.") + shell("ogr2ogr -f gpkg -update -append {output.gpkg} {layer_path}") + + + # Downloading Marine protected area database from WDPA + # extract the main zip and then merge the contained 3 zipped shapefiles + # Website: https://www.protectedplanet.net/en/thematic-areas/marine-protected-areas + rule download_wdpa_marine: + input: + HTTP.remote( + f"d1gam3xoknrgr2.cloudfront.net/current/WDPA_WDOECM_{bYYYY}_Public_marine_shp.zip", + static=True, + keep_local=True, + ), + params: + zip=RESOURCES + f"WDPA_WDOECM_{bYYYY}_marine.zip", + folder=directory(RESOURCES + f"WDPA_WDOECM_{bYYYY}_marine"), + output: + gpkg=RESOURCES + f"WDPA_WDOECM_{bYYYY}_marine.gpkg", + run: + shell("cp {input} {params.zip}") + shell("unzip -o {params.zip} -d {params.folder}") + for i in range(3): + # vsizip is special driver for directly working with zipped shapefiles in ogr2ogr + layer_path = f"/vsizip/{params.folder}/WDPA_WDOECM_{bYYYY}_Public_marine_shp_{i}.zip" + print(f"Adding layer {i+1} of 3 to combined output file.") + shell("ogr2ogr -f gpkg -update -append {output.gpkg} {layer_path}") + + if config["enable"]["retrieve"]: rule retrieve_monthly_co2_prices: