MCPcopy Index your code
hub / github.com/MapServer/MapServer / msGetGDALBandList

Function msGetGDALBandList

mapdrawgdal.c:2558–2640  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2556/************************************************************************/
2557
2558int *msGetGDALBandList( layerObj *layer, void *hDS,
2559 int max_bands, int *band_count )
2560
2561{
2562 int i, file_bands;
2563 int *band_list = NULL;
2564
2565 file_bands = GDALGetRasterCount( hDS );
2566 if( file_bands == 0 )
2567 {
2568 msSetError( MS_IMGERR,
2569 "Attempt to operate on GDAL file with no bands, layer=%s.",
2570 "msGetGDALBandList()",
2571 layer->name );
2572
2573 return NULL;
2574 }
2575
2576/* -------------------------------------------------------------------- */
2577/* Use all (or first) bands. */
2578/* -------------------------------------------------------------------- */
2579 if( CSLFetchNameValue( layer->processing, "BANDS" ) == NULL )
2580 {
2581 if( max_bands > 0 )
2582 *band_count = MIN(file_bands,max_bands);
2583 else
2584 *band_count = file_bands;
2585
2586 band_list = (int *) malloc(sizeof(int) * *band_count );
2587 MS_CHECK_ALLOC(band_list, sizeof(int) * *band_count, NULL);
2588
2589 for( i = 0; i < *band_count; i++ )
2590 band_list[i] = i+1;
2591 return band_list;
2592 }
2593
2594/* -------------------------------------------------------------------- */
2595/* get bands from BANDS processing directive. */
2596/* -------------------------------------------------------------------- */
2597 else
2598 {
2599 char **papszItems = CSLTokenizeStringComplex(
2600 CSLFetchNameValue(layer->processing,"BANDS"), " ,", FALSE, FALSE );
2601
2602 if( CSLCount(papszItems) == 0 )
2603 {
2604 CSLDestroy( papszItems );
2605 msSetError( MS_IMGERR, "BANDS PROCESSING directive has no items.",
2606 "msGetGDALBandList()" );
2607 return NULL;
2608 }
2609 else if( max_bands != 0 && CSLCount(papszItems) > max_bands )
2610 {
2611 msSetError( MS_IMGERR, "BANDS PROCESSING directive has wrong number of bands, expected at most %d, got %d.",
2612 "msGetGDALBandList()",
2613 max_bands, CSLCount(papszItems) );
2614 CSLDestroy( papszItems );
2615 return NULL;

Callers 3

msRasterQueryByRectLowFunction · 0.85
msDrawRasterLayerGDALFunction · 0.85

Calls 1

msSetErrorFunction · 0.85

Tested by

no test coverage detected