AHN
AHNService
Bases: BaseModel
get_tiles(model='dtm', cell_size='05', ahn_version=4, timeout=DEFAULT_HTTP_TIMEOUT)
Fetch the AHN tile index from the configured service.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
(dtm, dsm)
|
Terrain or surface model, by default "dtm". |
"dtm"
|
cell_size
|
('05', 5)
|
Raster resolution of 0.5 or 5 metres, by default "05". |
"05"
|
ahn_version
|
(3, 4, 5, 6)
|
AHN version, by default 4. PDOK only supports version 4. |
3
|
timeout
|
float
|
Connection and read inactivity timeout in seconds. Defaults to
|
DEFAULT_HTTP_TIMEOUT
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
Tile geometries and download attributes indexed by tile identifier. |
Raises:
| Type | Description |
|---|---|
RequestException
|
If the index request fails or times out. This request is not retried. |
get_tiles_url(model='dtm', cell_size='05', ahn_version=4)
Get tiles url of AHN download service
create_download_dir(root_dir, model='dtm', cell_size='05', ahn_version=4)
Create a logic/unique download_dir as sub-directory of root_dir
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
root_dir
|
Path
|
Root directory to create sub-directory for |
required |
model
|
Literal["dtm", "dsm"]
|
ahn model-type, by default "dtm" |
'dtm'
|
cell_size
|
Literal["05", "5"]
|
ahn cell_size, by default "05" |
'05'
|
ahn_version
|
Literal[1, 2, 3, 4, 5, 6]
|
ahn version, by default 4 |
4
|
Returns:
| Type | Description |
|---|---|
Path
|
ahn_directory |
download_ahn(ahn_dir=datastore.ahn_dir, poly_mask=None, select_indices=None, model='dtm', cell_size='05', ahn_version=4, service='ahn_pdok', missing_only=True, create_vrt=True, save_tiles_index=False, *, tile_index=None, retries=10, timeout=DEFAULT_HTTP_TIMEOUT)
Download AHN rasters with validated, atomic tile replacement.
Downloads AHN DTM or DSM rasters on 0.5 m or 5 m resolution. Each
response is written to a temporary TIFF beside its target, processed,
closed, reopened, and validated before it atomically replaces the final
tile. A valid existing tile is reused with missing_only=True. An
invalid existing tile is removed and downloaded again.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ahn_dir
|
Path
|
Directory to store ahn-files. Defaults to datastore.ahn_dir |
ahn_dir
|
poly_mask
|
Polygon | None
|
Mask to select ahn-tiles, by default None |
None
|
select_indices
|
list[str] | None
|
Indices to select, by default None |
None
|
service
|
Literal['ahn_pdok', 'ahn_nl']
|
Switch for using pdok.nl or ahn.nl for downloading ahn_data |
'ahn_pdok'
|
missing_only
|
bool
|
Only download rasters not yet existing in download_dir, by default True |
True
|
create_vrt
|
bool
|
Create a vrt-file so all tiles can be opened as one, by default True |
True
|
save_tiles_index
|
bool
|
Save the tile index as a GeoPackage in the download-dir, by default False |
False
|
tile_index
|
GeoDataFrame
|
Prepared index with tile identifiers and service download URLs. Avoids an index network request; source data and CRS must match the service. |
None
|
retries
|
int
|
Maximum total download attempts for each tile, by default 10. Set to 0 to make every requested tile fail without an HTTP request. |
10
|
timeout
|
float
|
HTTP connection and read inactivity timeout in seconds for the tile
index and each tile request. Defaults to |
DEFAULT_HTTP_TIMEOUT
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to download dir or vrt_file, being a sub-directory of ahn_root_dir |
get_ahn_rasters(*args, **kwargs)
Compatibility alias for :func:download_ahn.
get_tiles_features(ahn_service, poly_mask=None, select_indices=None, model='dtm', cell_size='05', ahn_version=4, timeout=DEFAULT_HTTP_TIMEOUT)
Fetch the AHN tile index and select tiles by geometry or identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ahn_service
|
AHNService
|
Service providing the tile index. |
required |
poly_mask
|
Polygon or None
|
Select intersecting tiles. Must use the same CRS as the index. |
None
|
select_indices
|
list of str or None
|
Tile identifiers to select after applying the optional spatial filter. |
None
|
model
|
(dtm, dsm)
|
Terrain or surface model, by default "dtm". |
"dtm"
|
cell_size
|
('05', 5)
|
Raster resolution of 0.5 or 5 metres, by default "05". |
"05"
|
ahn_version
|
(3, 4, 5, 6)
|
AHN version, by default 4. |
3
|
timeout
|
float
|
Connection and read inactivity timeout in seconds for the index request.
Defaults to |
DEFAULT_HTTP_TIMEOUT
|
Returns:
| Type | Description |
|---|---|
GeoDataFrame
|
Selected tile geometries and download attributes. |
interpolate_ahn_tiles(ahn_vrt_file, indices=None, max_search_distance=100, dir_name='ahn_filled', create_vrt=True, missing_only=False)
Interpolate ahn raster tiles
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ahn_vrt_file
|
Path
|
VRT file referring to AHN tiles |
required |
indices
|
list[str] | None
|
Optional selection of AHN tiles to interpolate, by default None |
None
|
max_search_distance
|
float
|
Set search_distance for neighbor search and interpolation distance. By default set to 100 |
100
|
dir_name
|
str
|
Optional output dir-name within datastore to store result, by default "ahn_filled" |
'ahn_filled'
|
create_vrt
|
bool
|
Switch for generating a vrt-file for resulting rasters, by default True |
True
|
missing_only
|
bool
|
Interpolate only rasters that haven't been interpolated yet, by default False |
False
|
Returns:
| Type | Description |
|---|---|
Path
|
Path to VRT-file (create_vrt=True) or destination directory |
Fill selected cells from original donors without changing other cells.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
values
|
ndarray
|
Two-dimensional values. NoData eligibility is supplied by the masks. |
required |
target_mask
|
ndarray
|
Disjoint Boolean masks. Donors need not lie within the target area. Newly filled cells never become donors. |
required |
donor_mask
|
ndarray
|
Disjoint Boolean masks. Donors need not lie within the target area. Newly filled cells never become donors. |
required |
max_distance_m
|
float
|
Maximum search distance in metres; zero disables interpolation. |
required |
pixel_width
|
float
|
Positive pixel dimensions in metres. Inverse distance requires squares. |
required |
pixel_height
|
float
|
Positive pixel dimensions in metres. Inverse distance requires squares. |
required |
method
|
(inverse_distance, nearest)
|
Continuous elevation interpolation or categorical nearest copying. |
"inverse_distance"
|
Returns:
| Type | Description |
|---|---|
InterpolationResult
|
A copy of the values, successful-fill mask, and (nearest only) flattened donor indices in row-major filled-cell order. Nearest ties prefer north, then west. Unfilled and non-target cells retain their original values. |
Redactie: AI