HOTOSM OpenStreetMap export (buildings)¶
Resolve a HOTOSM country building export, list its resources, then download the
GeoPackage. This is a live public HDX query, wrapped in try/except so it still
passes offline under nbval-lax. HOTOSM exports can be large, so Uruguay is used
here as a smaller example.
Setup¶
Imports plus the output directory. earthlens provides the unified EarthLens
entry point; HDX is a file-writing backend, so results land on disk under
hdx_output/.
from pathlib import Path
from earthlens import EarthLens
OUT_DIR = Path('hdx_output')
OUT_DIR.mkdir(exist_ok=True)
Inspect the resources¶
Before downloading anything, build the request and call _search() to list the
available resources for the hotosm-uruguay-buildings dataset. This is a cheap
metadata-only call. The construction and the search are kept on separate lines.
try:
backend = EarthLens(
data_source="hdx",
dataset='hotosm-uruguay-buildings',
variables=['Geopackage'],
path=str(OUT_DIR),
)
products = backend._search()
for p in products:
print(p.metadata['name'], '|', p.metadata['format'])
except Exception as exc:
print(f'skipped search: {type(exc).__name__}: {exc}')
Download the GeoPackage¶
Now build the same request and download() the Geopackage resource to
OUT_DIR. The constructor and the download() call are split onto separate
statements, and the whole thing stays wrapped in try/except for offline runs.
paths = None
try:
backend = EarthLens(
data_source='hdx',
dataset='hotosm-uruguay-buildings',
variables=['Geopackage'],
path=str(OUT_DIR),
)
paths = backend.download(progress_bar=False)
print('downloaded:', [Path(p).name for p in paths])
except Exception as exc:
print(f'skipped live query: {type(exc).__name__}: {exc}')