chm_zd.py
def match_size_dtm(dsm_fn, tmp_dtm_fn, dtm_fn):
    """Filling no data value in calculated DTM raster, also changing raster sizes matching it to
    DSM raster size (PDAL creates DSM a little bit smaller)"""

    driver_tiff = gdal.GetDriverByName("GTiff")
    dsm_ds = gdal.Open(dsm_fn)
    tmp_dtm_ds = gdal.Open(tmp_dtm_fn)

    cols = dsm_ds.RasterXSize
    rows = dsm_ds.RasterYSize

    # dtm_data = temp_dtm_ds.GetRasterBand(1).ReadAsArray()
    temp_dtm_data = tmp_dtm_ds.GetRasterBand(1).ReadAsArray()

    dtm_data = np.zeros((rows, cols))
    dtm_data[0:rows, 0:cols] = temp_dtm_data[0:rows, 0:cols]
    dtm_data[dtm_data == -9999] = np.NaN

    dtm_ds = driver_tiff.Create(dtm_fn,
                                dsm_ds.RasterXSize,
                                dsm_ds.RasterYSize,
                                1,
                                gdal.GDT_Float32)

    dtm_ds.SetProjection(dsm_ds.GetProjection())
    dtm_ds.SetGeoTransform(dsm_ds.GetGeoTransform())
    dtm_ds.GetRasterBand(1).WriteArray(dtm_data)
    dtm_ds.GetRasterBand(1).SetNoDataValue(np.NaN)

    # FILLING NO DATA VALUE IN GROUND RASTER
    # inplace, filling gaps under buildings/trees with interpolated values
    gdal.FillNodata(targetBand=dtm_ds.GetRasterBand(1),
                    maskBand=None,
                    maxSearchDist=10,
                    smoothingIterations=1)
    dtm_ds = None
    return dtm_data
Filling no data value in calculated DTM raster, also changing raster sizes matching it to
    DSM raster size (PDAL creates DSM a little bit smaller)
Filling no data value in calculated DTM raster, also changing raster sizes matching it to
DSM raster size (PDAL creates DSM a little bit smaller)
Filling no data value in calculated DTM raster also changing raster sizes matching it to DSM raster size ( PDAL creates DSM a little bit smaller )
def match_size_dtm(dsm_fn, tmp_dtm_fn, dtm_fn):
    driver_tiff = gdal.GetDriverByName("GTiff")
    dsm_ds = gdal.Open(dsm_fn)
    tmp_dtm_ds = gdal.Open(tmp_dtm_fn)
    cols = dsm_ds.RasterXSize
    rows = dsm_ds.RasterYSize
    temp_dtm_data = tmp_dtm_ds.GetRasterBand(1).ReadAsArray()
    dtm_data = np.zeros((rows, cols))
    dtm_data[0:rows, 0:cols] = temp_dtm_data[0:rows, 0:cols]
    dtm_data[dtm_data == -9999] = np.NaN
    dtm_ds = driver_tiff.Create(dtm_fn,
                                dsm_ds.RasterXSize,
                                dsm_ds.RasterYSize,
                                1,
                                gdal.GDT_Float32)
    dtm_ds.SetProjection(dsm_ds.GetProjection())
    dtm_ds.SetGeoTransform(dsm_ds.GetGeoTransform())
    dtm_ds.GetRasterBand(1).WriteArray(dtm_data)
    dtm_ds.GetRasterBand(1).SetNoDataValue(np.NaN)
    gdal.FillNodata(targetBand=dtm_ds.GetRasterBand(1),
                    maskBand=None,
                    maxSearchDist=10,
                    smoothingIterations=1)
    dtm_ds = None
    return dtm_data
def match_size_dtm ( dsm_fn , tmp_dtm_fn , dtm_fn ) : driver_tiff = gdal . GetDriverByName ( "GTiff" ) dsm_ds = gdal . Open ( dsm_fn ) tmp_dtm_ds = gdal . Open ( tmp_dtm_fn ) cols = dsm_ds . RasterXSize rows = dsm_ds . RasterYSize temp_dtm_data = tmp_dtm_ds . GetRasterBand ( 1 ) . ReadAsArray ( ) dtm_data = np . zeros ( ( rows , cols ) ) dtm_data [ 0 : rows , 0 : cols ] = temp_dtm_data [ 0 : rows , 0 : cols ] dtm_data [ dtm_data == - 9999 ] = np . NaN dtm_ds = driver_tiff . Create ( dtm_fn , dsm_ds . RasterXSize , dsm_ds . RasterYSize , 1 , gdal . GDT_Float32 ) dtm_ds . SetProjection ( dsm_ds . GetProjection ( ) ) dtm_ds . SetGeoTransform ( dsm_ds . GetGeoTransform ( ) ) dtm_ds . GetRasterBand ( 1 ) . WriteArray ( dtm_data ) dtm_ds . GetRasterBand ( 1 ) . SetNoDataValue ( np . NaN ) gdal . FillNodata ( targetBand = dtm_ds . GetRasterBand ( 1 ) , maskBand = None , maxSearchDist = 10 , smoothingIterations = 1 ) dtm_ds = None return dtm_data
Filling no data value in calculated DTM raster, also changing raster sizes matching it to
DSM raster size (PDAL creates DSM a little bit smaller)
Filling no data value in calculated DTM raster also changing raster sizes matching it to DSM raster size ( PDAL creates DSM a little bit smaller )
"""Filling no data value in calculated DTM raster, also changing raster sizes matching it to
    DSM raster size (PDAL creates DSM a little bit smaller)""" # dtm_data = temp_dtm_ds.GetRasterBand(1).ReadAsArray()
 # FILLING NO DATA VALUE IN GROUND RASTER
 # inplace, filling gaps under buildings/trees with interpolated values

dsm_fn
tmp_dtm_fn
dtm_fn