[gdal-dev] Bindings for the histogram method of band
Ari Jolma
ari.jolma at tkk.fi
Tue Jul 22 10:48:27 EDT 2008
The trac.osgeo.org does not answer so I'll put this here.
Hobu, would it be ok to have (int len, int *output) typemap. They can be
used in GetHistogram method like this (note that the API is same for C#
but it must use different typemaps. From Band.i:
#ifndef SWIGCSHARP
%feature( "kwargs" ) GetHistogram;
%apply (int len, int *output) {(int nBuckets, int *panHistogram)};
%apply (IF_ERROR_RETURN_NONE) { (CPLErr) };
#else
%apply (int inout[ANY]) {int *panHistogram};
#endif /* SWIGCSHARP */
CPLErr GetHistogram( double dfMin=-0.5,
double dfMax=255.5,
int nBuckets=256, /* as in GDAL docs */
int *panHistogram = NULL,
int bIncludeOutOfRange = 0,
int bApproxOk = 1,
GDALProgressFunc callback = NULL,
void* callback_data=NULL ) {
return GDALGetRasterHistogram( self,
dfMin,
dfMax,
nBuckets,
panHistogram,
bIncludeOutOfRange,
bApproxOk,
callback,
callback_data);
}
#ifndef SWIGCSHARP
%clear (int nBuckets, int *panHistogram);
%clear (CPLErr);
#else
%clear int *panHistogram;
#endif /* SWIGCSHARP */
And the typemaps for Perl: Note the slight abuse of check for malloc.
This is tested and works.
%typemap(in,numinputs=1) (int len, int *output)
{
/* %typemap(in,numinputs=1) (int len, int *output) */
$1 = SvIV($input);
}
%typemap(check) (int len, int *output)
{
/* %typemap(check) (int len, int *output) */
if ($1 < 1) $1 = 1; /* stop idiocy */
$2 = (int *)CPLMalloc( $1 * sizeof(int) );
}
%typemap(argout,fragment="CreateArrayFromIntArray") (int len, int *output)
{
/* %typemap(argout) (int len, int *output) */
$result = CreateArrayFromIntArray( $2, $1 );
argvi++;
}
%typemap(freearg) (int len, int *output)
{
/* %typemap(freearg) (int len, int *output) */
CPLFree($2);
}
Ari
--
Prof. Ari Jolma
Geoinformatiikka / Geoinformatics
Teknillinen Korkeakoulu / Helsinki University of Technology
tel: +358 9 451 3886 address: POBox 1200, 02015 TKK, Finland
Email: ari.jolma at tkk.fi URL: http://www.tkk.fi/~jolma
More information about the gdal-dev
mailing list