dgm1 package¶
Submodules¶
dgm1.dgm1_nrw module¶
-
class
dgm1.dgm1_nrw.
DGM1NRW
(dgm1_dir, shp_region=None)¶ Bases:
object
The class DGM1NRW downloads and processes dem rasters found in https://www.opengeodata.nrw.de/produkte/geobasis/hm/dgm1_xyz/dgm1_xyz/.
- Parameters
dgm1_dir (str) – directory to save downloaded 1 meter rasters as well as its shapefile and resampled rasters.
shp_region (str) – shapefile with the region of interest. If defined, all processes refer to this shapefile.
-
nodata
= -9999.0¶ nodata for the created rasters
-
url_dgm1_xyz
= 'https://www.opengeodata.nrw.de/produkte/geobasis/hm/dgm1_xyz/dgm1_xyz/'¶ URL of dem rasters with one meter resolution and 2000x2000 \(m^2\) size.
-
compress_options
= ['COMPRESS=LZW', 'PREDICTOR=2']¶ Compress options used in gdal driver.Create().
-
creation_options
= ['BIGTIFF=YES', 'COMPRESS=LZW', 'ZSTD_LEVEL=1', 'TILED=YES', 'PREDICTOR=2']¶
-
shp_region
= None¶ Shapefile with the region of interest. If defined, all processes refer to this shapefile. Otherwise all rasters are downloaded and processed
-
dgm1_dir
= None¶ Directory to save the original 1 meter products as well as its shapefile and resampled rasters.
-
shp_filename_tiles
= None¶ Shapefile dgm1_2_nw.shp contaning all tiles found on the server as 2x2 \(km^2\) squares. It is saved in
dgm1_dir
/gis.
-
tif_dir
(pixel_size)¶ Return the directory name of rasters with the given pixel_size. pixel_size = 1 corresponds to the downloaded rasters with 1 meter resolution.
- Parameters
pixel_size (int) – pixel size in meters. It must be a divisor of 2000 (2, 4, 5, 8, 10, 16, 20, 25, 40, 50, 80, 100, 125, 200, 250, 400, 500, 1000, 2000).
- Returns
(str) full path of the directory.
-
static
vrt_filename
(pixel_size)¶ Return the basename of the vrt-file for the given pixel size.
- Parameters
pixel_size (int) – pixel size in meters. It must be a divisor of 2000 (2, 4, 5, 8, 10, 16, 20, 25, 40, 50, 80, 100, 125, 200, 250, 400, 500, 1000, 2000).
- Returns
(str) basename of the vrt-file
-
tif_filenames
(pixel_size)¶ Return the names of the downloaded files with the given pixel files in tif-format.
- Parameters
pixel_size (int) – pixel size in meters. It must be a divisor of 2000 (2, 4, 5, 8, 10, 16, 20, 25, 40, 50, 80, 100, 125, 200, 250, 400, 500, 1000, 2000).
- Returns
(list) full path file names.
-
static
srs
()¶ Return the compound coordinate reference system using EPSG 25832 for the horizontal component and EPSG 7837 for the vertical component. The compound srs is labeled as
ETRS89 / UTM zone 32N + DHHN2016 height
.- Returns
(osr.SpatialReference) spatial reference system.
-
region_envelope
()¶ Return [x_min, y_min, x_max, y_max] for
shp_region
- Returns
(list) envelope of
shp_region
-
tif_filenames_intersecting
(envelope=False)¶ Return a list of file names *.xyz.gz transformed into *.tif found on the server, which intersect the region
shp_region
. Return an empty list if the region is not defined or it is outside the domainshp_filename_tiles
.- Parameters
envelope – if True use envelopes of regions, otherwise use regions to get intersections. Default False.
- Returns
(list) list of files with the suffix tif.
Example:
>>> dgm1 = DGM1NRW('~/dgm1', '~/study_area/region.shp') >>> dgm1.tif_filenames_intersecting() ['dgm1_32350_5672_2_nw.tif', 'dgm1_32350_5674_2_nw.tif', ...
-
gz_filenames_intersecting
(envelope=False)¶ Return a list of gzipped file names (dgm1_XXXXX_YYYY_2_nw.xyz.gz) found on the server, which intersect the region
shp_region
. Return an empty list if the region is not defined or it is outside the domainshp_filename_tiles
.- Parameters
envelope – if True use envelopes of regions, otherwise use regions to get intersections. Default False.
- Returns
(list) list of files with the suffix xyz.gz.
Example:
>>> dgm1 = DGM1NRW('~/dgm1', '~/study_area/region.shp') >>> dgm1.gz_filenames_intersecting() ['dgm1_32350_5672_2_nw.xyz.gz', 'dgm1_32350_5674_2_nw.xyz.gz', ...
-
create_shapefile
()¶ Create a shapefile with squares of 2x2 km² using raster file names from
url_dgm1_xyz
. The shapefileshp_filename_tiles
is saved indgm1_dir
. The shapefile attribute Filename indicates the gz-file name found on the server. The spatial coordinate system is defined increate_spatial_reference()
.
-
download
(n_cores=1)¶ Download rasters from
url_dgm1_xyz
intersectingshp_region
. Download all rasters ifregion
is not defined.- Parameters
n_cores – number of cores for parallel downloading and transformation into tif-files. n_core is limited to \(n\_cores \leq n - 1\), where n ist the total number of cores found on the computer. n_cores can be intentionally be high in order to use \(n - 1\) cores.
-
resample
(pixel_size, force=False)¶ Resample dowloaded TIF files with 1 meter resolution into TIF files with a resolution of pixel_size.
- Parameters
pixel_size (int) – pixel size in meters. It must be a divisor of 2000 (2, 4, 5, 8, 10, 16, 20, 25, 40, 50, 80, 100, 125, 200, 250, 400, 500, 1000, 2000)
force (bool) – if True, resample also existing files, otherwise skip them. Default force=False
-
create_vrt
(vrt_filename, pixel_size=1, n_cores=1)¶ Create a raster named
vrt_filename
in vrt-format. A folder without the suffix .vrt will be created together with the and populated with rasters of the givenpixel_size
intersecting with the region.Example:
>>> dgm1 = DGM1NRW('~/dgm1', '~/study_area/region.shp') >>> dgm1.create_vrt('~/study_area/dgm1/dgm1_region_02m.vrt', pixel_size=2)
- Parameters
vrt_filename (str) – full path vrt file name (.vrt)
pixel_size – pixel size in meters. It must be a divisor of 2000 (1, 2, 4, 5, 8, 10, 16, 20, 25, 40, 50, 80, 100, 125, 200, 250, 400, 500, 1000, 2000)
n_cores (int) – number of cores for parallel downloading and transformation into TIF files. n_core is limited to \(n\_cores \leq n - 1\), where n ist the total number of cores found on the computer. n_cores can be intentionally be high in order to use \(n - 1\) cores.
-
mosaic
(tif_filename, pixel_size, extent='region', n_cores=1, **kwargs)¶ Mosaic TIF files intersecting with the
shp_region
.- Parameters
tif_filename (str) – output file name (.tif)
pixel_size (int) – pixel size in meters. It must be a divisor of 2000 (1, 2, 4, 5, 8, 10, 16, 20, 25, 40, 50, 80, 100, 125, 200, 250, 400, 500, 1000, 2000)
extent (str) – clip to clip
shp_region
; region for a raster covering the envelope ofshp_region
; rasters for a raster extended to full tiles. Default region. extent=None corresponds to extent=`rasters`n_cores (int) – number of cores for parallel downloading and transformation into TIF files. n_core is limited to \(n\_cores \leq n - 1\), where n ist the total number of cores found on the computer. n_cores can be intentionally be high in order to use \(n - 1\) cores.
- Keyword Arguments
See https://gdal.org/python/osgeo.gdal-module.html#WarpOptions