Skip to content
Draft
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- Update years for DK (2025, 2026)
- Converter for Bavaria, Germany
- Update fr-converter to support 2021/2022 files
- Converter for Lithuania KŽS reference parcels (lt_kzs), reading the geoportal.lt ArcGIS REST service
- Support Esri JSON and server-side filters in EsriRESTConverterMixin (rest_format, rest_params["where"])

## [v0.21.0] - 2026-02-16

Expand Down
24 changes: 17 additions & 7 deletions fiboa_cli/conversion/converter_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class EsriRESTConverterMixin:
rest_base_url = None
rest_params = {}
rest_attribute = "OBJECTID" # orderable, filterable, indexed
rest_format = "geojson" # servers before ArcGIS 10.4 only offer Esri JSON: "json"

def rest_layer_filter(self, layers):
return next(iter(layers))
Expand All @@ -24,7 +25,7 @@ def get_urls(self):
return {"REST": self.rest_base_url}

def download_files(self, uris, cache_folder=None):
# Read-data will just stream alle pages of rest-service
# Read-data will just stream all pages of rest-service
if next(iter(uris), "").startswith("REST"):
self.cache_folder = cache_folder
return list(uris.values())
Expand All @@ -33,9 +34,14 @@ def download_files(self, uris, cache_folder=None):
return super().download_files(uris, cache_folder)

def get_data(self, paths, **kwargs):
if not paths[0].startswith("http"):
# This happens when input_file param is used
return super().get_data(paths, **kwargs)
if not (isinstance(paths[0], str) and paths[0].startswith("http")):
# This happens when input_file param is used. The pages are read here because
# this method is a generator (so it can't return super().get_data()) and the
# base implementation parses every .json file as GeoJSON, which Esri JSON isn't.
for path, uri in paths:
self.info(f"Reading {path} into GeoDataFrame")
yield gpd.read_file(path), path, uri, None
return

base_url = paths[0] # loop over paths to support more than 1 source
source_fs = get_fs(base_url)
Expand All @@ -45,21 +51,25 @@ def get_data(self, paths, **kwargs):
layer = self.rest_layer_filter(service_metadata["layers"])
page_size = service_metadata["maxRecordCount"]
layer_url = f"{base_url}/{layer['id']}/query"
get_dict = self.rest_params | {
rest_params = dict(self.rest_params)
base_where = rest_params.pop("where", None) # combined with the paging filter below
get_dict = rest_params | {
"outFields": "*",
"returnGeometry": "true",
"f": "geojson",
"f": self.rest_format,
"sortBy": self.rest_attribute,
"resultRecordCount": page_size,
}
gdfs = []
last_id = -1
while True:
get_dict["where"] = f"{self.rest_attribute}>{last_id}"
if base_where:
get_dict["where"] += f" AND ({base_where})"
url = f"{layer_url}?{urlencode(get_dict)}"
if cache_fs is not None:
cache_file = os.path.join(
cache_folder, f"{self.id}_{layer['id']}_{last_id}.geojson"
cache_folder, f"{self.id}_{layer['id']}_{last_id}.{self.rest_format}"
)
if not cache_fs.exists(cache_file):
with cache_fs.open(cache_file, mode="wb") as file:
Expand Down
55 changes: 55 additions & 0 deletions fiboa_cli/datasets/lt_kzs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from vecorel_cli.conversion.admin import AdminConverterMixin

from ..conversion.converter_rest import EsriRESTConverterMixin
from ..conversion.fiboa_converter import FiboaBaseConverter


class LTKZSConverter(AdminConverterMixin, EsriRESTConverterMixin, FiboaBaseConverter):
id = "lt_kzs"
short_name = "Lithuania, KŽS"
title = "Reference parcels (Lithuania, KŽS)"
description = """
KŽS (Kontroliniai žemės sklypai) is Lithuania's Land Parcel Identification System
(LPIS), maintained at scale 1:5000 as part of the Integrated Administration and
Control System (IACS).

This converter reads the blocks eligible for support (GKODAS `bl1` and `bl1b`),
269,355 of the 2,150,085 polygons published by the service. The remainder describe
ineligible land, forest, hydrography and landscape elements.

The dataset carries no crop information; crop declarations are published separately.
"""

provider = "VĮ Žemės ūkio duomenų centras <https://www.zudc.lt>"
attribution = "© VĮ Žemės ūkio duomenų centras"
license = (
"Copyright, no reuse licence stated "
"<https://www.geoportal.lt/metadata-catalog/catalog/search/resource/details.page?uuid=%7B5266D059-0781-4650-9BF6-B2618CF2915E%7D>"
)

rest_base_url = (
"https://www.geoportal.lt/arcgis/rest/services/nma/KZS5LT_kontroliniai_sklypai/MapServer"
)

rest_format = "json"
rest_params = {"where": "GKODAS IN ('bl1','bl1b')", "outSR": "4326"}

area_is_in_ha = False # Shape_Area is in m², not ha

columns = {
"OBJECTID": "id",
"geometry": "geometry",
"BLOKAS_ID": "blokas_id",
"GKODAS": "gkodas",
"Shape_Area": "metrics:area",
"Shape_Length": "metrics:perimeter",
}

column_migrations = {"OBJECTID": lambda col: col.astype(str)}

missing_schemas = {
"properties": {
"blokas_id": {"type": "string"},
"gkodas": {"type": "string"},
}
}
1 change: 1 addition & 0 deletions tests/data-files/convert/lt_kzs/lt_kzs.json

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions tests/test_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
"ec_ro",
"india_10k",
"it_1",
"lt_kzs",
]
test_path = "tests/data-files/convert"

Expand All @@ -71,6 +72,7 @@ def _input_files(converter, *names):
"lv": _input_files("lv", "1_100.xml"),
"nz": _input_files("nz", "irrigated-land-area-raw-2020-update.zip"),
"jecam": _input_files("jecam", "BD_JECAM_CIRAD_2023_feb.shp"),
"lt_kzs": _input_files("lt_kzs", "lt_kzs.json"),
}


Expand Down