LCOV - code coverage report
Current view: directory - frmts/pcraster - pcrasterrasterband.cpp (source / functions) Found Hit Coverage
Test: gdal_filtered.info Lines: 77 18 23.4 %
Date: 2010-01-09 Functions: 7 5 71.4 %

       1                 : /******************************************************************************
       2                 :  * $Id: pcrasterrasterband.cpp 15453 2008-10-03 11:00:02Z kdejong $
       3                 :  *
       4                 :  * Project:  PCRaster Integration
       5                 :  * Purpose:  PCRaster raster band implementation.
       6                 :  * Author:   Kor de Jong, k.dejong at geog.uu.nl
       7                 :  *
       8                 :  ******************************************************************************
       9                 :  * Copyright (c) 2004, Kor de Jong
      10                 :  *
      11                 :  * Permission is hereby granted, free of charge, to any person obtaining a
      12                 :  * copy of this software and associated documentation files (the "Software"),
      13                 :  * to deal in the Software without restriction, including without limitation
      14                 :  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
      15                 :  * and/or sell copies of the Software, and to permit persons to whom the
      16                 :  * Software is furnished to do so, subject to the following conditions:
      17                 :  *
      18                 :  * The above copyright notice and this permission notice shall be included
      19                 :  * in all copies or substantial portions of the Software.
      20                 :  *
      21                 :  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
      22                 :  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
      23                 :  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
      24                 :  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
      25                 :  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
      26                 :  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
      27                 :  * DEALINGS IN THE SOFTWARE.
      28                 :  ****************************************************************************/
      29                 : 
      30                 : #ifndef INCLUDED_PCRASTERRASTERBAND
      31                 : #include "pcrasterrasterband.h"
      32                 : #define INCLUDED_PCRASTERRASTERBAND
      33                 : #endif
      34                 : 
      35                 : // PCRaster library headers.
      36                 : #ifndef INCLUDED_CSF
      37                 : #include "csf.h"
      38                 : #define INCLUDED_CSF
      39                 : #endif
      40                 : 
      41                 : // Module headers.
      42                 : #ifndef INCLUDED_PCRASTERDATASET
      43                 : #include "pcrasterdataset.h"
      44                 : #define INCLUDED_PCRASTERDATASET
      45                 : #endif
      46                 : 
      47                 : #ifndef INCLUDED_PCRASTERUTIL
      48                 : #include "pcrasterutil.h"
      49                 : #define INCLUDED_PCRASTERUTIL
      50                 : #endif
      51                 : 
      52                 : 
      53                 : 
      54                 : /*!
      55                 :   \file
      56                 :   This file contains the implementation of the PCRasterRasterBand class.
      57                 : */
      58                 : 
      59                 : 
      60                 : 
      61                 : //------------------------------------------------------------------------------
      62                 : // DEFINITION OF STATIC PCRRASTERBAND MEMBERS
      63                 : //------------------------------------------------------------------------------
      64                 : 
      65                 : 
      66                 : 
      67                 : //------------------------------------------------------------------------------
      68                 : // DEFINITION OF PCRRASTERBAND MEMBERS
      69                 : //------------------------------------------------------------------------------
      70                 : 
      71                 : //! Constructor.
      72                 : /*!
      73                 :   \param     dataset The dataset we are a part of.
      74                 : */
      75               6 : PCRasterRasterBand::PCRasterRasterBand(
      76                 :          PCRasterDataset* dataset)
      77                 : 
      78               6 :   : GDALPamRasterBand(), d_dataset(dataset)
      79                 : 
      80                 : {
      81               6 :   this->poDS = dataset;
      82               6 :   this->nBand = 1;
      83               6 :   this->eDataType = cellRepresentation2GDALType(dataset->cellRepresentation());
      84               6 :   this->nBlockXSize = dataset->GetRasterXSize();
      85               6 :   this->nBlockYSize = 1;
      86               6 : }
      87                 : 
      88                 : 
      89                 : 
      90                 : //! Destructor.
      91                 : /*!
      92                 : */
      93              12 : PCRasterRasterBand::~PCRasterRasterBand()
      94                 : {
      95              12 : }
      96                 : 
      97                 : 
      98                 : 
      99               1 : double PCRasterRasterBand::GetNoDataValue(
     100                 :          int* success)
     101                 : {
     102               1 :   if(success) {
     103               1 :     *success = 1;
     104                 :   }
     105                 : 
     106               1 :   return d_dataset->missingValue();
     107                 : }
     108                 : 
     109                 : 
     110                 : 
     111               0 : double PCRasterRasterBand::GetMinimum(
     112                 :          int* success)
     113                 : {
     114                 :   double result;
     115                 :   int isValid;
     116                 : 
     117               0 :   switch(d_dataset->cellRepresentation()) {
     118                 :     // CSF version 2. ----------------------------------------------------------
     119                 :     case CR_UINT1: {
     120                 :       UINT1 min;
     121               0 :       isValid = RgetMinVal(d_dataset->map(), &min);
     122               0 :       result = static_cast<double>(min);
     123               0 :       break;
     124                 :     }
     125                 :     case CR_INT4: {
     126                 :       INT4 min;
     127               0 :       isValid = RgetMinVal(d_dataset->map(), &min);
     128               0 :       result = static_cast<double>(min);
     129               0 :       break;
     130                 :     }
     131                 :     case CR_REAL4: {
     132                 :       REAL4 min;
     133               0 :       isValid = RgetMinVal(d_dataset->map(), &min);
     134               0 :       result = static_cast<double>(min);
     135               0 :       break;
     136                 :     }
     137                 :     case CR_REAL8: {
     138                 :       REAL8 min;
     139               0 :       isValid = RgetMinVal(d_dataset->map(), &min);
     140               0 :       result = static_cast<double>(min);
     141               0 :       break;
     142                 :     }
     143                 :     // CSF version 1. ----------------------------------------------------------
     144                 :     case CR_INT1: {
     145                 :       INT1 min;
     146               0 :       isValid = RgetMinVal(d_dataset->map(), &min);
     147               0 :       result = static_cast<double>(min);
     148               0 :       break;
     149                 :     }
     150                 :     case CR_INT2: {
     151                 :       INT2 min;
     152               0 :       isValid = RgetMinVal(d_dataset->map(), &min);
     153               0 :       result = static_cast<double>(min);
     154               0 :       break;
     155                 :     }
     156                 :     case CR_UINT2: {
     157                 :       UINT2 min;
     158               0 :       isValid = RgetMinVal(d_dataset->map(), &min);
     159               0 :       result = static_cast<double>(min);
     160               0 :       break;
     161                 :     }
     162                 :     case CR_UINT4: {
     163                 :       UINT4 min;
     164               0 :       isValid = RgetMinVal(d_dataset->map(), &min);
     165               0 :       result = static_cast<double>(min);
     166               0 :       break;
     167                 :     }
     168                 :     default: {
     169               0 :       result = 0.0;
     170               0 :       isValid = 0;
     171                 :       break;
     172                 :     }
     173                 :   }
     174                 : 
     175               0 :   if(success) {
     176               0 :     *success = isValid ? 1 : 0;
     177                 :   }
     178                 : 
     179               0 :   return result;
     180                 : }
     181                 : 
     182                 : 
     183                 : 
     184               0 : double PCRasterRasterBand::GetMaximum(
     185                 :          int* success)
     186                 : {
     187                 :   double result;
     188                 :   int isValid;
     189                 : 
     190               0 :   switch(d_dataset->cellRepresentation()) {
     191                 :     case CR_UINT1: {
     192                 :       UINT1 max;
     193               0 :       isValid = RgetMaxVal(d_dataset->map(), &max);
     194               0 :       result = static_cast<double>(max);
     195               0 :       break;
     196                 :     }
     197                 :     case CR_INT4: {
     198                 :       INT4 max;
     199               0 :       isValid = RgetMaxVal(d_dataset->map(), &max);
     200               0 :       result = static_cast<double>(max);
     201               0 :       break;
     202                 :     }
     203                 :     case CR_REAL4: {
     204                 :       REAL4 max;
     205               0 :       isValid = RgetMaxVal(d_dataset->map(), &max);
     206               0 :       result = static_cast<double>(max);
     207               0 :       break;
     208                 :     }
     209                 :     // CSF version 1. ----------------------------------------------------------
     210                 :     case CR_INT1: {
     211                 :       INT1 max;
     212               0 :       isValid = RgetMaxVal(d_dataset->map(), &max);
     213               0 :       result = static_cast<double>(max);
     214               0 :       break;
     215                 :     }
     216                 :     case CR_INT2: {
     217                 :       INT2 max;
     218               0 :       isValid = RgetMaxVal(d_dataset->map(), &max);
     219               0 :       result = static_cast<double>(max);
     220               0 :       break;
     221                 :     }
     222                 :     case CR_UINT2: {
     223                 :       UINT2 max;
     224               0 :       isValid = RgetMaxVal(d_dataset->map(), &max);
     225               0 :       result = static_cast<double>(max);
     226               0 :       break;
     227                 :     }
     228                 :     case CR_UINT4: {
     229                 :       UINT4 max;
     230               0 :       isValid = RgetMaxVal(d_dataset->map(), &max);
     231               0 :       result = static_cast<double>(max);
     232               0 :       break;
     233                 :     }
     234                 :     default: {
     235               0 :       result = 0.0;
     236               0 :       isValid = 0;
     237                 :       break;
     238                 :     }
     239                 :   }
     240                 : 
     241               0 :   if(success) {
     242               0 :     *success = isValid ? 1 : 0;
     243                 :   }
     244                 : 
     245               0 :   return result;
     246                 : }
     247                 : 
     248                 : 
     249                 : 
     250             100 : CPLErr PCRasterRasterBand::IReadBlock(
     251                 :          int nBlockXoff,
     252                 :          int nBlockYoff,
     253                 :          void* buffer)
     254                 : {
     255             100 :   size_t nrCellsRead = RgetRow(d_dataset->map(), nBlockYoff, buffer);
     256                 : 
     257                 :   // Now we have raw values, missing values are set according to the CSF
     258                 :   // conventions. This means that floating points should not be evaluated.
     259                 :   // Since this is done by the GDal library we replace these with valid
     260                 :   // values. Non-MV values are not touched.
     261                 : 
     262                 :   // Replace in-file MV with in-app MV which may be different.
     263                 :   alterFromStdMV(buffer, nrCellsRead, d_dataset->cellRepresentation(),
     264             100 :          d_dataset->missingValue());
     265                 : 
     266             100 :   return CE_None;
     267                 : }
     268                 : 
     269                 : 
     270                 : 
     271                 : //------------------------------------------------------------------------------
     272                 : // DEFINITION OF FREE OPERATORS
     273                 : //------------------------------------------------------------------------------
     274                 : 
     275                 : 
     276                 : 
     277                 : //------------------------------------------------------------------------------
     278                 : // DEFINITION OF FREE FUNCTIONS
     279                 : //------------------------------------------------------------------------------
     280                 : 
     281                 : 
     282                 : 

Generated by: LCOV version 1.7