Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
30 changes: 29 additions & 1 deletion fiboa_cli/datasets/nz.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

import pandas as pd
from vecorel_cli.vecorel.extensions import ADMIN_DIVISION

Expand All @@ -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"
Expand All @@ -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 <https://environment.govt.nz/publications/national-irrigated-land-spatial-dataset-2020-update>"
license = "CC-BY-4.0"
extensions = {ADMIN_DIVISION}
Expand Down
Loading