Opened 3 years ago

Closed 7 months 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 3 years ago.
Patch file

Download all attachments as: .zip

Change History (2)

Changed 3 years ago by ShibaBandit

Attachment: reproject_band.patch added

Patch file

comment:1 Changed 7 months ago by Even Rouault

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.