Hi list,
I'm having some issues with the Python ReprojectImage function not respecting
nodata.
My input dataset has nodata value -32767. I am using ReprojectImage to
resample and warp the src_ds in memory to match the resolution and srs of a
second dataset. The output of ReprojectImage has nodata pixels filled with 0,
despite the fact that both the input src_ds and dst_ds nodata are specified to
-32767 before the warp.
Here's a snippet:
src_gt = src_ds.GetGeoTransform()
src_srs = geolib.get_srs(src_ds)
gra = gdal.GRA_CubicSpline
#Use GDAL memory driver
memdrv = gdal.GetDriverByName('MEM')
#Compute output image dimensions
dst_nl = int(round((extent[3] - extent[1])/res))
dst_ns = int(round((extent[2] - extent[0])/res))
#Create output dataset
src_b = src_ds.GetRasterBand(1)
src_dt = src_b.DataType
dst_ds = memdrv.Create('', dst_ns, dst_nl, src_ds.RasterCount, src_dt)
dst_ds.SetProjection(t_srs.ExportToWkt())
dst_gt = [extent[0], res, src_gt[2], extent[3], src_gt[4], -res]
dst_ds.SetGeoTransform(dst_gt)
for n in range(1, src_ds.RasterCount+1):
src_b = src_ds.GetRasterBand(n)
#Extract ndv from src_b, with defaults if undefined
src_ndv = malib.get_ndv(src_b)
if src_ndv is not None:
dst_ds.GetRasterBand(n).SetNoDataValue(src_ndv)
result = gdal.ReprojectImage(src_ds, dst_ds, src_srs.ExportToWkt(),
t_srs.ExportToWkt(), \
gra, 0.0, 0.0, prog_func)
return dst_ds
I see that it should be possible to pass SrcNoDataReal and DstNoDataReal as
GdalWarpOptions (http://www.gdal.org/structGDALWarpOptions.html), but this is
not supported by ReprojectImage as far as I can tell.
I can hack a dst_ds.GetRasterBand(n).SetNoDataValue(0) fix in the above loop,
and then replace the value of those pixels using numpy to obtain my desired
output ndv, but this is problematic because 0 is technically in my valid input
range. I'm using 1.11dev (4/13/2013).
-David_______________________________________________
gdal-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/gdal-dev