⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qgsrasterlayer.cpp

📁 一个非常好的GIS开源新版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
  }  double myMinimumValue = 0.0;  double myMaximumValue = 0.0;  //Use standard deviations if set, otherwise, use min max of band  if (mStandardDeviations > 0)  {    myMinimumValue = (myRasterBandStats.mean - (mStandardDeviations * myRasterBandStats.stdDev));    myMaximumValue = (myRasterBandStats.mean + (mStandardDeviations * myRasterBandStats.stdDev));  }  else  {    myMinimumValue = myRasterBandStats.minVal;    myMaximumValue = myRasterBandStats.maxVal;  }  mRasterShader->setMinimumValue(myMinimumValue);  mRasterShader->setMaximumValue(myMaximumValue);    int myRedValue = 255;  int myGreenValue = 255;  int myBlueValue = 255;  double myPixelValue = 0.0;  int myAlphaValue = 0;  for (int myColumn = 0; myColumn < theRasterViewPort->drawableAreaYDim; ++myColumn)  {    for (int myRow = 0; myRow < theRasterViewPort->drawableAreaXDim; ++myRow)    {      myPixelValue = readValue ( myGdalScanData, myDataType,          myColumn * theRasterViewPort->drawableAreaXDim + myRow );      if ( mValidNoDataValue && (myPixelValue == mNoDataValue || myPixelValue != myPixelValue ))      {        continue;      }            myAlphaValue = mRasterTransparency.getAlphaValue(myPixelValue, mTransparencyLevel);      if(0 == myAlphaValue)      {        continue;      }            if(!mRasterShader->generateShadedValue(myPixelValue, &myRedValue, &myGreenValue, &myBlueValue))      {        continue;      }      if (mInvertPixelsFlag)      {        //Invert flag, flip blue and read        myQImage.setPixel(myRow, myColumn, qRgba(myBlueValue, myGreenValue, myRedValue, myAlphaValue));      }      else      {        //Normal        myQImage.setPixel(myRow, myColumn, qRgba(myRedValue, myGreenValue, myBlueValue, myAlphaValue));      }    }                       //end of columnwise loop  }                           //end of rowwise loop  CPLFree ( myGdalScanData );  //render any inline filters  filterLayer(&myQImage);  paintImageToCanvas(theQPainter, theRasterViewPort, theQgsMapToPixel, &myQImage);}/** * This method is used to render a paletted raster layer as a colour image. * @param theQPainter - pointer to the QPainter onto which the layer should be drawn. * @param theRasterViewPort - pointer to the ViewPort struct containing dimensions of viewable area and subset area to be extracted from data file. * @param theGdalBand - pointer to the GDALRasterBand which should be rendered. */void QgsRasterLayer::drawPalettedSingleBandColor(QPainter * theQPainter, QgsRasterViewPort * theRasterViewPort,     QgsMapToPixel * theQgsMapToPixel, int theBandNo){  QgsDebugMsg("QgsRasterLayer::drawPalettedSingleBandColor called");  //Invalid band number, segfault prevention  if(0 >= theBandNo)  {    return;  }    GDALRasterBandH myGdalBand = GDALGetRasterBand(mGdalDataset,theBandNo);  GDALDataType myDataType = GDALGetRasterDataType(myGdalBand);  void *myGdalScanData = readData ( myGdalBand, theRasterViewPort );  /* Check for out of memory error */  if (myGdalScanData == NULL)  {    return;  }  QgsColorTable *myColorTable = colorTable ( theBandNo );  QImage myQImage = QImage(theRasterViewPort->drawableAreaXDim, theRasterViewPort->drawableAreaYDim, 32);  myQImage.setAlphaBuffer(true);  myQImage.fill(qRgba(255,255,255,0 )); // fill transparent    double myPixelValue = 0.0;  int myRedValue = 0;  int myGreenValue = 0;  int myBlueValue = 0;  bool found = false;  int myAlphaValue = 0;  for (int myColumn = 0; myColumn < theRasterViewPort->drawableAreaYDim; ++myColumn)  {    for (int myRow = 0; myRow < theRasterViewPort->drawableAreaXDim; ++myRow)    {      //Reinitalize values;            myRedValue = 0;      myGreenValue = 0;      myBlueValue = 0;      found = false;      myPixelValue = readValue ( myGdalScanData, (GDALDataType)myDataType,          myColumn * theRasterViewPort->drawableAreaXDim + myRow );      if ( mValidNoDataValue && (myPixelValue == mNoDataValue || myPixelValue != myPixelValue ))      {        continue;      }      myAlphaValue = mRasterTransparency.getAlphaValue(myPixelValue, mTransparencyLevel);      if(0 == myAlphaValue)      {        continue;      }            found = myColorTable->color ( myPixelValue, &myRedValue, &myGreenValue, &myBlueValue );      if ( !found ) continue;      if (mInvertPixelsFlag)      {        myRedValue = 255 - myRedValue;        myGreenValue = 255 - myGreenValue;        myBlueValue = 255 - myBlueValue;      }      myQImage.setPixel(myRow, myColumn, qRgba(myRedValue, myGreenValue, myBlueValue, myAlphaValue));    }  }  CPLFree(myGdalScanData);  //render any inline filters  filterLayer(&myQImage);  paintImageToCanvas(theQPainter, theRasterViewPort, theQgsMapToPixel, &myQImage);}/** * This method is used to render a paletted raster layer as a gray image. * @param theQPainter - pointer to the QPainter onto which the layer should be drawn. * @param theRasterViewPort - pointer to the ViewPort struct containing dimensions of viewable area and subset area to be extracted from data file. * @param theGdalBand - pointer to the GDALRasterBand which should be rendered. * @param theColorQString - QString containing either 'Red' 'Green' or 'Blue' indicating which part of the rgb triplet will be used to render gray. */void QgsRasterLayer::drawPalettedSingleBandGray(QPainter * theQPainter, QgsRasterViewPort * theRasterViewPort,     QgsMapToPixel * theQgsMapToPixel, int theBandNo,    QString const & theColorQString){  QgsDebugMsg("QgsRasterLayer::drawPalettedSingleBandGray called");  //Invalid band number, segfault prevention  if(0 >= theBandNo)  {    return;  }    QgsRasterBandStats myRasterBandStats = getRasterBandStats(theBandNo);  GDALRasterBandH myGdalBand = GDALGetRasterBand(mGdalDataset,theBandNo);  GDALDataType myDataType = GDALGetRasterDataType(myGdalBand);  void *myGdalScanData = readData ( myGdalBand, theRasterViewPort );  /* Check for out of memory error */  if (myGdalScanData == NULL)  {    return;  }  QgsColorTable *myColorTable = &(myRasterBandStats.colorTable);  QImage myQImage = QImage(theRasterViewPort->drawableAreaXDim, theRasterViewPort->drawableAreaYDim, 32);  myQImage.setAlphaBuffer(true);  myQImage.fill(qRgba(255,255,255,0 )); // fill transparent   bool found = false;  double myPixelValue = 0.0;  int myRedLUTValue = 0;  int myGreenLUTValue = 0;  int myBlueLUTValue = 0;  int myAlphaValue = 0;    //Set a pointer to the LUT color channel  int* myGrayValue;  if (theColorQString == mRedBandName)  {    myGrayValue = &myRedLUTValue;  }  else if (theColorQString == mGreenBandName)  {    myGrayValue = &myGreenLUTValue;  }  else  {    myGrayValue = &myBlueLUTValue;  }      for (int myColumn = 0; myColumn < theRasterViewPort->drawableAreaYDim; ++myColumn)  {    for (int myRow = 0; myRow < theRasterViewPort->drawableAreaXDim; ++myRow)    {      myRedLUTValue = 0;      myGreenLUTValue = 0;      myBlueLUTValue = 0;      found = false;      myPixelValue = readValue ( myGdalScanData, (GDALDataType)myDataType,          myColumn * theRasterViewPort->drawableAreaXDim + myRow );      if ( mValidNoDataValue && (myPixelValue == mNoDataValue || myPixelValue != myPixelValue ))      {        continue;      }      myAlphaValue = mRasterTransparency.getAlphaValue(myPixelValue, mTransparencyLevel);      if(0 == myAlphaValue)      {        continue;      }      found = myColorTable->color ( myPixelValue, &myRedLUTValue, &myGreenLUTValue, &myBlueLUTValue );      if ( !found ) continue;      if (mInvertPixelsFlag)      {        *myGrayValue = 255 - *myGrayValue;      }      myQImage.setPixel(myRow, myColumn, qRgba(*myGrayValue, *myGrayValue, *myGrayValue, myAlphaValue));    }  }  CPLFree ( myGdalScanData );  //render any inline filters  filterLayer(&myQImage);  paintImageToCanvas(theQPainter, theRasterViewPort, theQgsMapToPixel, &myQImage);}/** * This method is used to render a paletted raster layer as a pseudocolor image. * @param theQPainter - pointer to the QPainter onto which the layer should be drawn. * @param theRasterViewPort - pointer to the ViewPort struct containing dimensions of viewable area and subset area to be extracted from data file. * @param theGdalBand - pointer to the GDALRasterBand which should be rendered. * @param theColorQString - QString containing either 'Red' 'Green' or 'Blue' indicating which part of the rgb triplet will be used to render gray. */void QgsRasterLayer::drawPalettedSingleBandPseudoColor(QPainter * theQPainter, QgsRasterViewPort * theRasterViewPort,    QgsMapToPixel * theQgsMapToPixel, int theBandNo,     QString const & theColorQString){  QgsDebugMsg("QgsRasterLayer::drawPalettedSingleBandPseudoColor called");  //Invalid band number, segfault prevention  if(0 >= theBandNo)  {    return;  }    QgsRasterBandStats myRasterBandStats = getRasterBandStats(theBandNo);  GDALRasterBandH myGdalBand = GDALGetRasterBand(mGdalDataset,theBandNo);  GDALDataType myDataType = GDALGetRasterDataType(myGdalBand);  void *myGdalScanData = readData ( myGdalBand, theRasterViewPort );  /* Check for out of memory error */  if (myGdalScanData == NULL)  {    return;  }  QImage myQImage = QImage(theRasterViewPort->drawableAreaXDim, theRasterViewPort->drawableAreaYDim, 32);  myQImage.setAlphaBuffer(true);  myQImage.fill(qRgba(255,255,255,0 )); // fill transparent  if (NULL == mRasterShader)  {    return;  }  double myMinimumValue = 0.0;  double myMaximumValue = 0.0;  //Use standard deviations if set, otherwise, use min max of band  if (mStandardDeviations > 0)  {    myMinimumValue = (myRasterBandStats.mean - (mStandardDeviations * myRasterBandStats.stdDev));    myMaximumValue = (myRasterBandStats.mean + (mStandardDeviations * myRasterBandStats.stdDev));  }  else  {    myMinimumValue = myRasterBandStats.minVal;    myMaximumValue = myRasterBandStats.maxVal;  }  mRasterShader->setMinimumValue(myMinimumValue);  mRasterShader->setMaximumValue(myMaximumValue);  QgsColorTable *myColorTable = &(myRasterBandStats.colorTable);  int myRedLUTValue = 0;  int myGreenLUTValue = 0;  int myBlueLUTValue;    double myPixelValue = 0.0;  int myRedValue = 0;  int myGreenValue = 0;  int myBlueValue = 0;  int myAlphaValue = 0;    //Set a pointer to the LUT color channel  int* myGrayValue;  if (theColorQString == mRedBandName)  {    myGrayValue = &myRedLUTValue;  }  else if (theColorQString == mGreenBandName)  {    myGrayValue = &myGreenLUTValue;  }  else  {    myGrayValue = &myBlueLUTValue;  }     for (int myColumn = 0; myColumn < theRasterViewPort->drawableAreaYDim; ++myColumn)  {    for (int myRow = 0; myRow < theRasterViewPort->drawableAreaXDim; ++myRow)    {      myRedValue = 0;      myGreenValue = 0;      myBlueValue = 0;      myPixelValue = readValue ( myGdalScanData, (GDALDataType)myDataType,          myColumn * theRasterViewPort->drawableAreaXDim + myRow );      if ( mValidNoDataValue && (myPixelValue == mNoDataValue || myPixelValue != myPixelValue ))      {        continue;      }      myAlphaValue = mRasterTransparency.getAlphaValue(myPixelValue, mTransparencyLevel);      if(0 == myAlphaValue)      {        continue;      }            bool found = myColorTable->color ( myPixelValue, &myRedLUTValue, &myGreenLUTValue, &myBlueLUTValue );      if ( !found ) continue;      if(!mRasterShader->generateShadedValue((double)*myGrayValue, &myRedValue, &myGreenValue, &myBlueValue))      {        continue;      }      if (mInvertPixelsFlag)      {        //Invert flag, flip blue and read        myQImage.setPixel(myRow, myColumn, qRgba(myBlueValue, myGreenValue, myRedValue, myAlphaValue));      }      else      {        //Normal        myQImage.setPixel(myRow, myColumn, qRgba(myRedValue, myGreenValue, myBlueValue, myAlphaValue));      }    }  }  CPLFree ( myGdalScanData );  //render any inline filters  filterLayer(&myQImage);  paintImageToCanvas(theQPainter, theRasterViewPort, theQgsMapToPixel, &myQImage);}/** * This method is used to render a paletted raster layer as a colour image. * @param theQPainter - pointer to the QPainter onto which the layer should be drawn. * @param theRasterViewPort - pointer to the ViewPort struct containing dimensions of viewable area and subset area to be extracted from data file. * @param theGdalBand - pointer to the GDALRasterBand which should be r

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -