diff --git a/CHANGELOG.md b/CHANGELOG.md index 0a727a13..041bed54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,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 +- ES-CM: read the year-named SIGPAC service, whose id field is OBJECTID_1, with the determination date from the variant - ES-CN: the seven island files each kept their own row index, and the region was declared as Cantabria - EC-EE: name the shapefile inside the archive, migrate the year column the release actually has, and require only what every parcel carries - ES-CAT: the 2024 download is a shapefile package, and 34 crop names new in that edition are mapped diff --git a/fiboa_cli/datasets/es_cm.py b/fiboa_cli/datasets/es_cm.py index 789ce436..ded133bb 100644 --- a/fiboa_cli/datasets/es_cm.py +++ b/fiboa_cli/datasets/es_cm.py @@ -8,7 +8,7 @@ class ESCMConverter(EsriRESTConverterMixin, ESBaseConverter): id = "es_cm" - short_name = "Spain " + short_name = "Spain Castilla-La Mancha" title = "Spain Castilla-La Mancha Crop fields" description = """ SIGPAC is a Geographic Information System dedicated to the control of agricultural aid under @@ -19,16 +19,18 @@ class ESCMConverter(EsriRESTConverterMixin, ESBaseConverter): attribution = "Unidad de Cartografía. Secretaría General. Consejería de Agricultura, Ganadería y Desarrollo Rural." provider = "Unidad de Cartografía. Secretaría General. Consejería de Agricultura, Ganadería y Desarrollo Rural. " columns = { - "dn_oid": "id", + "DN_OID": "id", "geometry": "geometry", - "provincia": "admin_province_code", - "municipio": "admin_municipality_code", - "dn_surface": "metrics:area", - "uso_sigpac": "crop:code", + "PROVINCIA": "admin_province_code", + "MUNICIPIO": "admin_municipality_code", + "DN_SURFACE": "metrics:area", + "USO_SIGPAC": "crop:code", "crop:name": "crop:name", "crop:name_en": "crop:name_en", } + use_code_attribute = "USO_SIGPAC" area_is_in_ha = False + use_variant_as_determination = True missing_schemas = { "properties": { "admin_province_code": {"type": "string"}, @@ -38,19 +40,17 @@ class ESCMConverter(EsriRESTConverterMixin, ESBaseConverter): variants = {str(year): str(year) for year in range(2024, 2018 - 1, -1)} rest_base_url = "https://geoservicios.castillalamancha.es/arcgis/rest/services/Vector" - rest_attribute = "objectid_1" + rest_attribute = "OBJECTID_1" def get_urls(self): - latest_year = next(iter(self.variants)) if not self.variant: - self.variant = latest_year - if self.variant == latest_year: - layer = "Vector/Recintos_sigpac" - else: - services = requests.get(self.rest_base_url, {"f": "pjson"}).json()["services"] - layer = next( - s["name"] - for s in services - if re.search(f"Recintos_sigpac_{self.variant}", s["name"], re.IGNORECASE) - ) + self.variant = next(iter(self.variants)) + # Always use the year-named service: the unnamed "Recintos_sigpac" service is + # whatever year is current (2025 in August 2026) and keys on OBJECTID instead. + services = requests.get(self.rest_base_url, {"f": "pjson"}).json()["services"] + layer = next( + s["name"] + for s in services + if re.search(f"Recintos_sigpac_{self.variant}$", s["name"], re.IGNORECASE) + ) return {"REST": self.rest_base_url.replace("Vector", layer + "/MapServer")} diff --git a/tests/data-files/convert/es_cm/es_cm_0.gpkg b/tests/data-files/convert/es_cm/es_cm_0.gpkg new file mode 100644 index 00000000..d99d2891 Binary files /dev/null and b/tests/data-files/convert/es_cm/es_cm_0.gpkg differ diff --git a/tests/test_convert.py b/tests/test_convert.py index 9af3eb30..df46fb89 100644 --- a/tests/test_convert.py +++ b/tests/test_convert.py @@ -46,6 +46,7 @@ "ie", "es_cat", "es_cl", + "es_cm", "es", "nz", "lt", @@ -85,6 +86,7 @@ def _input_files(converter, *names): "variant": "2025", "input_files": {f"{test_path}/es_cl/AVILA.zip": ["replaceme.zip"]}, }, + "es_cm": {"variant": "2024", **_input_files("es_cm", "es_cm_0.gpkg")}, "es_an": { "variant": "2025", "input_files": {f"{test_path}/es_an/SP25_REC_PROV_04.zip": ["SP25_REC_04.shp"]},