diff --git a/CHANGELOG.md b/CHANGELOG.md index a654d7dd..cffb04b2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - ES-CL: the ITACyL server is https-only, the 2025 shapefiles sit in province subfolders, and C_REFREC is the identifier - A test refuses a fixture above 5 MB, committed or merely lying in the fixture folder, because a failing convert test downloads the real source there - ES-MD: find RECINTO.shp wherever the archive puts it +- NZ: 2017 and 2020 as variants, resolving the manual downloads from the cache folder - Update vecorel-cli to v0.2.17: - GeoJSON is read as UTF-8 as the format mandates, instead of the platform locale (cp1252 on Windows mangled umlauts) - GeoJSON files with a byte order mark no longer fail to read diff --git a/fiboa_cli/datasets/nz.py b/fiboa_cli/datasets/nz.py index 524085a0..9f66a50f 100644 --- a/fiboa_cli/datasets/nz.py +++ b/fiboa_cli/datasets/nz.py @@ -1,3 +1,5 @@ +import os + import pandas as pd from vecorel_cli.vecorel.extensions import ADMIN_DIVISION @@ -6,7 +8,17 @@ class NZCropConverter(FiboaBaseConverter): - data_access = "Download manually from https://data.mfe.govt.nz/layer/105407-irrigated-land-area-raw-2020-update/" + data_access = """ + Download manually (Koordinates login required) and place the zip in the cache folder: + - 2020: https://data.mfe.govt.nz/layer/105407-irrigated-land-area-raw-2020-update/ (mfe-irrigated-land-area-raw-2020-update-SHP.zip) + - 2017: https://data.mfe.govt.nz/layer/90838-irrigated-land-area-2017/ (mfe-irrigated-land-area-2017-SHP.zip) + Alternatively pass the zip with the `-i` CLI parameter. + """ + variants = { + # keys are the cache filenames vecorel resolves before attempting a download + "2020": {"mfe-irrigated-land-area-raw-2020-update-SHP.zip": ["*.shp"]}, + "2017": {"mfe-irrigated-land-area-2017-SHP.zip": ["*.shp"]}, + } id = "nz" short_name = "New Zealand" @@ -20,6 +32,22 @@ class NZCropConverter(FiboaBaseConverter): created in 2017. The current update has incorporated data from the 2019 – 2020 irrigation season. """ + def download_files(self, uris, cache_folder=None): + """The sources are manual downloads (Koordinates login): resolve the bare + filenames from ``variants`` against the cache folder instead of the cwd.""" + _, cache_dir = self.get_cache(cache_folder) + resolved = {} + for uri, target in uris.items(): + if "://" not in uri and not os.path.isabs(uri) and not os.path.exists(uri): + cached = os.path.join(cache_dir, uri) + if not os.path.exists(cached): + raise FileNotFoundError( + f"{uri} is a manual download; place it in {cache_dir} (see data_access)" + ) + uri = cached + resolved[uri] = target + return super().download_files(resolved, cache_folder) + provider = "Aqualinc Research Limited " license = "CC-BY-4.0" extensions = {ADMIN_DIVISION}