Opened 7 years ago

Closed 5 years ago

#6824 closed enhancement (wontfix)

Add SWIG Binding for Reprojecting Single Band

Reported by: ShibaBandit Owned by: hobu
Priority: normal Milestone: closed_because_of_github_migration
Component: SWIG (all bindings) Version: unspecified
Severity: normal Keywords: SWIG, Reproject
Cc:

Description

I have a SWIG binding I would like to add that can reproject a single band, rather than all bands. I have tested this locally in my own fork / gdal builds. The method is similar to ReprojectImage, but takes in the src_band_index and dst_band_index parameters.

See below for the binding (added to Operations.i).

/************************************************************************/
/*                           ReprojectImageBand()                       */
/************************************************************************/
%apply Pointer NONNULL {GDALDatasetShadow *src_ds, GDALDatasetShadow *dst_ds};
#ifndef SWIGJAVA
%feature( "kwargs" ) ReprojectImageBand;
#endif
%inline %{
CPLErr  ReprojectImageBand ( GDALDatasetShadow *src_ds,
                             GDALDatasetShadow *dst_ds,
                             int src_band_index,
                             int dst_band_index,
                             const char *src_wkt=NULL,
                             const char *dst_wkt=NULL,
                             GDALResampleAlg eResampleAlg=GRA_NearestNeighbour,
                             double WarpMemoryLimit=0.0,
                             double maxerror = 0.0,
                             GDALProgressFunc callback = NULL,
                             void* callback_data=NULL,
                             char** options = NULL ) {

    CPLErrorReset();

    GDALWarpOptions* psOptions = GDALCreateWarpOptions();

    if( options != NULL )
    {
        psOptions->papszWarpOptions = CSLDuplicate(options);
    }

    int srcBandCount = GDALGetRasterCount(src_ds);
    int dstBandCount = GDALGetRasterCount(dst_ds);

    psOptions->nBandCount = MIN(1, MIN(srcBandCount, dstBandCount));

    if(psOptions->nBandCount == 1) {
        psOptions->panSrcBands = (int *) CPLMalloc(sizeof(int));
        psOptions->panDstBands = (int *) CPLMalloc(sizeof(int));
        psOptions->panSrcBands[0] = src_band_index;
        psOptions->panDstBands[0] = dst_band_index;
    }

    CPLErr err = GDALReprojectImage( src_ds,
                                     src_wkt,
                                     dst_ds,
                                     dst_wkt,
                                     eResampleAlg,
                                     WarpMemoryLimit,
                                     maxerror,
                                     callback,
                                     callback_data,
                                     psOptions);

    if( psOptions != NULL )
        GDALDestroyWarpOptions(psOptions);

    return err;
}
%}
%clear GDALDatasetShadow *src_ds, GDALDatasetShadow *dst_ds;

Attachments (1)

reproject_band.patch (3.2 KB ) - added by ShibaBandit 7 years ago.
Patch file

Download all attachments as: .zip

Change History (2)

by ShibaBandit, 7 years ago

Attachment: reproject_band.patch added

Patch file

comment:1 by Even Rouault, 5 years ago

Milestone: closed_because_of_github_migration
Resolution: wontfix
Status: newclosed

This ticket has been automatically closed because Trac is no longer used for GDAL bug tracking, since the project has migrated to GitHub. If you believe this ticket is still valid, you may file it to https://github.com/OSGeo/gdal/issues if it is not already reported there.

Note: See TracTickets for help on using tickets.