"""DEM (digital elevation model) store: upload once, preview, sample, build from points. Rasters are kept under SPIPE_DEM_DIR (default: /data/dem) as GeoTIFF, keyed by a random id; only the newest SPIPE_DEM_KEEP files are retained. Elevations are returned in the raster's own units (normally metres). """ from __future__ import annotations import json import os import shutil import uuid import warnings import zipfile from pathlib import Path import numpy as np import rasterio import shapely import shapely.geometry from rasterio.enums import Resampling from rasterio.io import MemoryFile from rasterio.transform import from_origin from pyproj import CRS, Transformer from .batch import BatchError DEM_DIR = Path(os.environ.get("SPIPE_DEM_DIR", Path(__file__).resolve().parents[1] / "data" / "dem")) DEM_KEEP = int(os.environ.get("SPIPE_DEM_KEEP", "8")) # Server-provided DEMs (e.g. the national 90 m DEM), registered once with # `python -m backend.dem register