Fix median filtering nodata handling

pull/1398/head
Piero Toffanin 2022-01-07 15:50:22 -05:00
rodzic 2c2ac29d49
commit 88326108e9
1 zmienionych plików z 4 dodań i 3 usunięć

Wyświetl plik

@ -186,7 +186,7 @@ def create_dem(input_point_cloud, dem_type, output_type='max', radiuses=['0.56']
for t in tiles:
if not os.path.exists(t['filename']):
raise Exception("Error creating %s, %s failed to be created" % (output_file, t['filename']))
# Create virtual raster
tiles_vrt_path = os.path.abspath(os.path.join(outdir, "tiles.vrt"))
tiles_file_list = os.path.abspath(os.path.join(outdir, "tiles_list.txt"))
@ -315,6 +315,8 @@ def median_smoothing(geotiff_path, output_path, smoothing_iterations=1):
dtype = img.dtypes[0]
arr = img.read()[0]
nodata_locs = numpy.where(arr == nodata)
# Median filter (careful, changing the value 5 might require tweaking)
# the lines below. There's another numpy function that takes care of
# these edge cases, but it's slower.
@ -330,8 +332,7 @@ def median_smoothing(geotiff_path, output_path, smoothing_iterations=1):
arr[-1][-2:] = arr[-2][-1] = arr[-2][-2]
# Median filter leaves a bunch of zeros in nodata areas
locs = numpy.where(arr == 0.0)
arr[locs] = nodata
arr[nodata_locs] = nodata
# write output
with rasterio.open(output_path, 'w', **img.profile) as imgout: