<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi list,<br>I'm having some issues with the Python ReprojectImage function not respecting nodata.<br><br>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.<br><br>Here's a snippet:<br><br> src_gt = src_ds.GetGeoTransform()<br> src_srs = geolib.get_srs(src_ds)<br> gra = gdal.GRA_CubicSpline<br><br> #Use GDAL memory driver<br> memdrv = gdal.GetDriverByName('MEM')<br> #Compute output image dimensions<br> dst_nl = int(round((extent[3] - extent[1])/res))<br> dst_ns = int(round((extent[2] - extent[0])/res))<br> #Create output dataset<br> src_b = src_ds.GetRasterBand(1)<br> src_dt = src_b.DataType<br> dst_ds = memdrv.Create('', dst_ns, dst_nl, src_ds.RasterCount, src_dt) <br> dst_ds.SetProjection(t_srs.ExportToWkt())<br> dst_gt = [extent[0], res, src_gt[2], extent[3], src_gt[4], -res]<br> dst_ds.SetGeoTransform(dst_gt)<br><br> for n in range(1, src_ds.RasterCount+1):<br> src_b = src_ds.GetRasterBand(n)<br><span class="Apple-tab-span" style="white-space: pre; "> </span>#Extract ndv from src_b, with defaults if undefined<br> src_ndv = malib.get_ndv(src_b)<br> if src_ndv is not None:<br> dst_ds.GetRasterBand(n).SetNoDataValue(src_ndv)<br><br> result = gdal.ReprojectImage(src_ds, dst_ds, src_srs.ExportToWkt(), t_srs.ExportToWkt(), \<br> gra, 0.0, 0.0, prog_func)<br><br> return dst_ds<br><div><br></div><div>I see that it should be possible to pass SrcNoDataReal and DstNoDataReal as GdalWarpOptions (<a href="http://www.gdal.org/structGDALWarpOptions.html">http://www.gdal.org/structGDALWarpOptions.html</a>), but this is not supported by ReprojectImage as far as I can tell. </div><div><br></div><div>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).<br>-David</div></body></html>