Skip to content

Commit

Permalink
Add option to specify temp file driver.
Browse files Browse the repository at this point in the history
  • Loading branch information
Sean Gillies committed Jan 20, 2015
1 parent 5c1e9eb commit 62cc916
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
14 changes: 13 additions & 1 deletion rasterio/_fill.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def _fillnodata(image, mask, double max_search_distance=100.0, int smoothing_ite
cdef void *image_band
cdef void *mask_dataset
cdef void *mask_band
cdef char **alg_options = NULL

if isinstance(image, np.ndarray):
# copy numpy ndarray into an in-memory dataset
Expand Down Expand Up @@ -58,13 +59,24 @@ def _fillnodata(image, mask, double max_search_distance=100.0, int smoothing_ite
raise ValueError("Invalid source image mask")

with cpl_errs:
_gdal.GDALFillNodata(image_band, mask_band, max_search_distance, 0, smoothing_iterations, NULL, NULL, NULL)
alg_options = _gdal.CSLSetNameValue(
alg_options, "TEMP_FILE_DRIVER", "MEM")
_gdal.GDALFillNodata(

This comment has been minimized.

Copy link
@brendan-ward

brendan-ward Jan 21, 2015

Contributor

@sgillies Please add a newline here; with two parameter lists that wrap like this it is hard to see breaks between function calls.

image_band,
mask_band,
max_search_distance,
0,
smoothing_iterations,
alg_options,
NULL,
NULL)

# read the result into a numpy ndarray
result = np.empty(image.shape, dtype=image.dtype)
_io.io_auto(result, image_band, False)

_gdal.GDALClose(image_dataset)
_gdal.GDALClose(mask_dataset)
_gdal.CSLDestroy(alg_options)

return result
18 changes: 14 additions & 4 deletions rasterio/rasterfill.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ if( quad_value != nNoDataVal ) \
* @param bDeprecatedOption unused argument, should be zero.
* @param nSmoothingIterations the number of 3x3 smoothing filter passes to
* run (0 or more).
* @param papszOptions additional name=value options in a string list (none
* supported at this time - just pass NULL).
* @param papszOptions additional name=value options in a string list (the
* temporary file driver can be specified like TEMP_FILE_DRIVER=MEM).
* @param pfnProgress the progress function to report completion.
* @param pProgressArg callback data for progress function.
*
Expand Down Expand Up @@ -451,7 +451,9 @@ GDALFillNodata( GDALRasterBandH hTargetBand,
/* -------------------------------------------------------------------- */
/* Create a work file to hold the Y "last value" indices. */
/* -------------------------------------------------------------------- */
GDALDriverH hDriver = GDALGetDriverByName( "MEM" );
CPLString osTmpFileDriver = CSLFetchNameValueDef(
papszOptions, "TEMP_FILE_DRIVER", "GTiff");
GDALDriverH hDriver = GDALGetDriverByName(osTmpFileDriver);
if (hDriver == NULL)
{
CPLError(CE_Failure, CPLE_AppDefined,
Expand All @@ -461,7 +463,13 @@ GDALFillNodata( GDALRasterBandH hTargetBand,

GDALDatasetH hYDS;
GDALRasterBandH hYBand;
static const char *apszOptions[] = {};

char **apszOptions = NULL;
if (osTmpFileDriver == "GTiff") {
CSLSetNameValue(apszOptions, "COMPRESS", "LZW");
CSLSetNameValue(apszOptions, "BIGTIFF", "IF_SAFER");
}

CPLString osTmpFile = CPLGenerateTempFilename("");
CPLString osYTmpFile = osTmpFile + "fill_y_work.tif";

Expand Down Expand Up @@ -851,6 +859,8 @@ GDALFillNodata( GDALRasterBandH hTargetBand,
GDALClose( hValDS );
GDALClose( hFiltMaskDS );

CSLDestroy(apszOptions);

GDALDeleteDataset( hDriver, osYTmpFile );
GDALDeleteDataset( hDriver, osValTmpFile );
GDALDeleteDataset( hDriver, osFiltMaskTmpFile );
Expand Down

0 comments on commit 62cc916

Please sign in to comment.