当前位置: 首页>>代码示例>>C++>>正文


C++ GDALRasterBand::RasterIO方法代码示例

本文整理汇总了C++中GDALRasterBand::RasterIO方法的典型用法代码示例。如果您正苦于以下问题:C++ GDALRasterBand::RasterIO方法的具体用法?C++ GDALRasterBand::RasterIO怎么用?C++ GDALRasterBand::RasterIO使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GDALRasterBand的用法示例。


在下文中一共展示了GDALRasterBand::RasterIO方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: CPLAssert

PLCLine *PLCContext::getOutputLine(int line)

{
    CPLAssert( outputDS != NULL );
    
    int  i, width = outputDS->GetRasterXSize();
    PLCLine *lineObj = new PLCLine(width);

    for( i=0; i < outputDS->GetRasterCount(); i++ )
    {
        CPLErr eErr;
        GDALRasterBand *band = outputDS->GetRasterBand(i+1);
        
        if( band->GetColorInterpretation() == GCI_AlphaBand )
            eErr = band->RasterIO(GF_Read, 0, line, width, 1, 
                                  lineObj->getAlpha(), width, 1, GDT_Byte,
                                  0, 0);
        else
            eErr = band->RasterIO(GF_Read, 0, line, width, 1, 
                                  lineObj->getBand(i), width, 1, GDT_Int16, 
                                  0, 0);

        if( eErr != CE_None )
            exit(1);
    }

    return lineObj;
}
开发者ID:barrycug,项目名称:plcompositor,代码行数:28,代码来源:plccontext.cpp

示例2: loadFile

void RasterImageLayer::loadFile()
{
    GDALDataset *ds = static_cast<GDALDataset*>(GDALOpen(m_filename.toLocal8Bit(), GA_ReadOnly));
    if (ds == nullptr)
    {
        qWarning() << "Error opening file:" << m_filename;
    }
    else
    {
        projection().setGeogCS(new OGRSpatialReference(ds->GetProjectionRef()));
        projection().setProjCS(new OGRSpatialReference(ds->GetProjectionRef()));
        projection().setDomain({-180., -90., 360., 180.});

        std::vector<double> geoTransform(6);
        int xsize = ds->GetRasterXSize();
        int ysize = ds->GetRasterYSize();
        ds->GetGeoTransform(geoTransform.data());
        vertData.resize(4);
        vertData[0] = QVector2D(geoTransform[0], geoTransform[3]);
        vertData[1] = QVector2D(geoTransform[0] + geoTransform[2] * ysize,
                geoTransform[3] + geoTransform[5] * ysize);
        vertData[2] = QVector2D(geoTransform[0] + geoTransform[1] * xsize + geoTransform[2] * ysize,
                geoTransform[3] + geoTransform[4] * xsize + geoTransform[5] * ysize);
        vertData[3] = QVector2D(geoTransform[0] + geoTransform[1] * xsize,
                geoTransform[3] + geoTransform[4] * xsize);
        texData = {{0., 0.}, {0., 1.}, {1., 1.}, {1., 0.}};

        int numBands = ds->GetRasterCount();
        qDebug() << "Bands:" << numBands;

        imData = QImage(xsize, ysize, QImage::QImage::Format_RGBA8888);
        imData.fill(QColor(255, 255, 255, 255));
        // Bands start at 1
        for (int i = 1; i <= numBands; ++i)
        {
            GDALRasterBand *band = ds->GetRasterBand(i);
            switch(band->GetColorInterpretation())
            {
            case GCI_RedBand:
                band->RasterIO(GF_Read, 0, 0, xsize, ysize, imData.bits(),
                               xsize, ysize, GDT_Byte, 4, 0);
                break;
            case GCI_GreenBand:
                band->RasterIO(GF_Read, 0, 0, xsize, ysize, imData.bits() + 1,
                               xsize, ysize, GDT_Byte, 4, 0);
                break;
            case GCI_BlueBand:
                band->RasterIO(GF_Read, 0, 0, xsize, ysize, imData.bits() + 2,
                               xsize, ysize, GDT_Byte, 4, 0);
                break;
            default:
                qWarning() << "Unhandled color interpretation:" << band->GetColorInterpretation();
            }
        }

        GDALClose(ds);
        newFile = true;
    }
}
开发者ID:lesserwhirls,项目名称:Wave,代码行数:59,代码来源:rasterimagelayer.cpp

示例3: Uniform

int Raster::Uniform(const char * pOutputRaster, double fValue)
{

    // Open up the Input File
    GDALDataset * pInputDS = (GDALDataset*) GDALOpen(m_sFilePath, GA_ReadOnly);
    if (pInputDS == NULL)
        throw RasterManagerException( INPUT_FILE_ERROR, "Input file could not be opened");

    GDALRasterBand * pRBInput = pInputDS->GetRasterBand(1);

    // Create the output dataset for writing
    GDALDataset * pOutputDS = CreateOutputDS(pOutputRaster, this);
    GDALRasterBand * pOutputRB = pOutputDS->GetRasterBand(1);

    // Assign our buffers
    double * pInputLine = (double*) CPLMalloc(sizeof(double) * GetCols());
    double * pOutputLine = (double*) CPLMalloc(sizeof(double) * GetCols());

    // Loop over rows
    for (int i=0; i < GetRows(); i++)
    {
        // Populate the buffer
        pRBInput->RasterIO(GF_Read, 0,  i, GetCols(), 1, pInputLine, GetCols(), 1, GDT_Float64, 0, 0);

        // Loop over columns
        for (int j=0; j < GetCols(); j++)
        {
            if (pInputLine[j] != GetNoDataValue()){
                pOutputLine[j] = fValue;
            }
            else {
                pOutputLine[j] = GetNoDataValue();
            }

        }
        // Write the row
        pOutputRB->RasterIO(GF_Write, 0, i, GetCols(), 1, pOutputLine, GetCols(), 1, GDT_Float64, 0, 0 );
    }

    CPLFree(pOutputLine);
    CPLFree(pInputLine);

    CalculateStats(pOutputDS->GetRasterBand(1));

    if ( pInputDS != NULL)
        GDALClose(pInputDS);
    if ( pOutputDS != NULL)
        GDALClose(pOutputDS);

    return PROCESS_OK;

}
开发者ID:JamesSLC,项目名称:rasterman,代码行数:52,代码来源:raster.cpp

示例4:

DataType
ImgReader<DataType>::getValue(const UTMCoordinateType& xCoord, 
                              const UTMCoordinateType& yCoord,
                              size_t band) const
{
    GDALRasterBand* rasterBand = dataset->GetRasterBand(band);
    const size_t pixel = static_cast<size_t>
                         ((xCoord - geoTransform[0]) / geoTransform[1]);
    const size_t line  = static_cast<size_t>
                         ((yCoord - geoTransform[3]) / geoTransform[5]);
    // XXX maybe do some error checking here to see if xCoord and yCoord are
    // even in the image; GDAL might do this already though

    DataType data; // The memory we'll read into

    CPLErr rasterIOError = 
        rasterBand->RasterIO(GF_Read,
                             pixel, line,
                             1, 1, // read just a single pixel
                             &data,
                             1, 1,
                             GDALDataTypeTraits<DataType>::dataType, 
                             0, 1);

    // XXX do something in case there's an error

    return data;
}
开发者ID:bpass,项目名称:cegis,代码行数:28,代码来源:ImgReader.hpp

示例5: CreateFile

void CreateFile(const char *srcfile,const char *dstfile)
{
	GDALAllRegister();
	CPLSetConfigOption("GDAL_FILENAME_IS_UTF8","NO");
	GDALDataset *pDataset=(GDALDataset *) GDALOpen( srcfile, GA_ReadOnly );
	int bandNum=pDataset->GetRasterCount();
	GDALRasterBand *pBand=pDataset->GetRasterBand(1);
	GDALDataType dataType=pBand->GetRasterDataType();

	GDALDriver *pDriver=GetGDALDriverManager()->GetDriverByName("GTiff");
	GDALDataset *dstDataset=pDriver->Create(dstfile,800,800,bandNum,dataType,NULL);
	GDALRasterBand *dstBand;
	//写入光栅数据
	ushort *buf= new ushort[800*800];
	for (int i=1;i<=bandNum;i++)
	{
		pBand=pDataset->GetRasterBand(i);
		pBand->RasterIO(GF_Read,3388,2204,800,800,buf,800,800,dataType,0,0);
		dstBand=dstDataset->GetRasterBand(i);
		dstBand->RasterIO(GF_Write,0,0,800,800,buf,800,800,dataType,0,0);
	}
	delete []buf;
	GDALClose(pDataset);
	GDALClose(dstDataset);
}
开发者ID:Slipperboy,项目名称:ImageDisplay,代码行数:25,代码来源:ImageDisplay.cpp

示例6: IRasterIO

CPLErr RawDataset::IRasterIO( GDALRWFlag eRWFlag, 
                              int nXOff, int nYOff, int nXSize, int nYSize,
                              void *pData, int nBufXSize, int nBufYSize, 
                              GDALDataType eBufType,
                              int nBandCount, int *panBandMap, 
                              int nPixelSpace, int nLineSpace, int nBandSpace )

{
    const char* pszInterleave;

    /* The default GDALDataset::IRasterIO() implementation would go to */
    /* BlockBasedRasterIO if the dataset is interleaved. However if the */
    /* access pattern is compatible with DirectIO() we don't want to go */
    /* BlockBasedRasterIO, but rather used our optimized path in RawRasterBand::IRasterIO() */
    if (nXSize == nBufXSize && nYSize == nBufYSize && nBandCount > 1 &&
        (pszInterleave = GetMetadataItem("INTERLEAVE", "IMAGE_STRUCTURE")) != NULL &&
        EQUAL(pszInterleave, "PIXEL"))
    {
        int iBandIndex;
        for(iBandIndex = 0; iBandIndex < nBandCount; iBandIndex ++ )
        {
            RawRasterBand* poBand = (RawRasterBand*) GetRasterBand(panBandMap[iBandIndex]);
            if( !poBand->CanUseDirectIO(nXOff, nYOff, nXSize, nYSize, eBufType ) )
            {
                break;
            }
        }
        if( iBandIndex == nBandCount )
        {
            CPLErr eErr = CE_None;
            for( iBandIndex = 0; 
                iBandIndex < nBandCount && eErr == CE_None; 
                iBandIndex++ )
            {
                GDALRasterBand *poBand = GetRasterBand(panBandMap[iBandIndex]);
                GByte *pabyBandData;

                if (poBand == NULL)
                {
                    eErr = CE_Failure;
                    break;
                }

                pabyBandData = ((GByte *) pData) + iBandIndex * nBandSpace;
                
                eErr = poBand->RasterIO( eRWFlag, nXOff, nYOff, nXSize, nYSize, 
                                        (void *) pabyBandData, nBufXSize, nBufYSize,
                                        eBufType, nPixelSpace, nLineSpace );
            }

            return eErr;
        }
    }

    return  GDALDataset::IRasterIO( eRWFlag, nXOff, nYOff, nXSize, nYSize,
                                    pData, nBufXSize, nBufYSize, eBufType, 
                                    nBandCount, panBandMap, 
                                    nPixelSpace, nLineSpace, nBandSpace );
}
开发者ID:0004c,项目名称:node-gdal,代码行数:59,代码来源:rawdataset.cpp

示例7: spectrum

void HypSpecImage::spectrum(double x, double y, double *spectrum)
{
    int bands = m_data->GetRasterCount();
    float *line = (float *) CPLMalloc(sizeof(float));

    for (int b = 0; b < bands; b++) {
        GDALRasterBand  *rb = m_data->GetRasterBand(b + 1);

        int i0 = floor(x);
        int i1 = i0 + 1;
        int j0 = floor(y);
        int j1 = j0 + 1;

        rb->RasterIO( GF_Read, i0, j0, 1, 1,
                      line, 1, 1, GDT_Float32,
                      0, 0 );
        float v00 = line[0];

        rb->RasterIO( GF_Read, i1, j0, 1, 1,
                      line, 1, 1, GDT_Float32,
                      0, 0 );
        float v10 = line[0];

        rb->RasterIO( GF_Read, i0, j1, 1, 1,
                      line, 1, 1, GDT_Float32,
                      0, 0 );
        float v01 = line[0];

        rb->RasterIO( GF_Read, i1, j1, 1, 1,
                      line, 1, 1, GDT_Float32,
                      0, 0 );
        float v11 = line[0];

        float id = x - i0;
        float jd = y - j0;

        float vi0 = id * v00 + (1 - id) * v10;
        float vi1 = id * v01 + (1 - id) * v11;

        float v = jd * vi0 + (1 - jd) * vi1;

        spectrum[b] = v;
    }

    CPLFree(line);
}
开发者ID:cabeen,项目名称:hyperspectral-sections,代码行数:46,代码来源:hypspecimage.cpp

示例8: getRawValuesFromFile

bool getRawValuesFromFile(string fname,vector<vector<float>>& vecs)
{
   
   //vector<float> temp = vector<float>()
   GDALDataset *poDataset;
   GDALAllRegister();
   poDataset= (GDALDataset*) GDALOpen(fname.c_str(),GA_ReadOnly);
   if(poDataset == NULL)
   {
      cout << "OUCH!" << endl;
      return false;
   }
   cout << "Data size: " << GDALGetRasterXSize(poDataset) << " " << GDALGetRasterYSize(poDataset) << endl;

   GDALRasterBand  *poBand;
   int             nBlockXSize, nBlockYSize;
   int             bGotMin, bGotMax;
   double          adfMinMax[2];
        
   poBand = poDataset->GetRasterBand( 1 );
   poBand->GetBlockSize( &nBlockXSize, &nBlockYSize );
   printf( "Block=%dx%d Type=%s, ColorInterp=%s\n",
            nBlockXSize, nBlockYSize,
            GDALGetDataTypeName(poBand->GetRasterDataType()),
            GDALGetColorInterpretationName(
            poBand->GetColorInterpretation()) );

   adfMinMax[0] = poBand->GetMinimum( &bGotMin );
   adfMinMax[1] = poBand->GetMaximum( &bGotMax );
   if( ! (bGotMin && bGotMax) )
      GDALComputeRasterMinMax((GDALRasterBandH)poBand, TRUE, adfMinMax);
   int width = poBand->GetXSize(); 
   int height = poBand->GetYSize();
   int bands = poDataset->GetRasterCount();
   float *pafScanline;
   std::cout << "Before allocation" << adfMinMax[0] << " " << adfMinMax[1] << endl;
   int dsize = 256;
   pafScanline = (float *) CPLMalloc(sizeof(float)*width*height);
   vector<vector<float>> out = vector<vector<float>>(height,vector<float> (width,0));
   poBand->RasterIO(GF_Read,0,0,width,height,pafScanline,width,height,GDT_Float32,0,0);
   cout << "After allocation" << endl;
   for(int i = 0; i < height; i++)
   {
    for(int j = 0; j < width; j++)
    {
      //cout << i << j << endl << pafS;
      out[i][j] = pafScanline[i*width+j];
    }
   }
   CPLFree(pafScanline);
   //for(auto i : out)
   //for(auto j : i)
   //		cout << j << endl;
  cout << "After allocation" << endl;
  vecs = out;
   return true;
}
开发者ID:ChaseCarthen,项目名称:cs791a,代码行数:57,代码来源:gishandler.cpp

示例9: invertImage

void HazePerfection::invertImage(GDALDataset *pDataset, GDALDataset *dstDataset, float a)
{
	GDALRasterBand *band = pDataset->GetRasterBand(1);
	GDALDataType dataType = band->GetRasterDataType();
	float *pixelData = new float[nXSize*nYSize];
	band->RasterIO(GF_Read, 0, 0, nXSize, nYSize, pixelData, nXSize, nYSize, GDT_Float32, 0, 0);
	
	GDALRasterBand *dstBand = dstDataset->GetRasterBand(1);
	for (int j = 0; j < nYSize; j++)
	{
		for (int i = 0; i < nXSize; i++)
		{
			pixelData[j*nXSize + i] = a - pixelData[j*nXSize + i];
		}
	}
	dstBand->RasterIO(GF_Write, 0, 0, nXSize, nYSize, pixelData, nXSize, nYSize, GDT_Float32, 0, 0);
	delete[]pixelData;
}
开发者ID:MrXue,项目名称:removeHaze,代码行数:18,代码来源:RemoveHaze.cpp

示例10: read_image

bool rgb_image::read_image()
{
    int fd;
    int i;
    unsigned char header[16];
    unsigned char jfif[] = {
        0xff, 0xd8, 0xff, 0xe0, 0x00, 0x10, 0x4a, 0x46,
        0x49, 0x46, 0x00, 0x01, 0x01, 0x00, 0x00, 0x01
    };
    GDALDataset *df;
    GDALRasterBand *bd;
    int bands;

    fd = open ( pathname.c_str(), O_RDWR );
    if ( fd < 0 ) {
        fprintf(stderr,"Could not open %s to patch jpeg header\n",
                pathname.c_str() );
        return false;
    }
    read ( fd, header, 16 );
    if ( bcmp(header,jfif,4) != 0 ) {
        fprintf(stderr,"Apparently %s is not a jpeg file\n",
                pathname.c_str() );
        return false;
    }
    if ( bcmp(header,jfif,16) != 0 ) {
        lseek ( fd, (off_t)0, SEEK_SET );
        write ( fd, jfif, 16 );
    }
    close ( fd );

    df = (GDALDataset *) GDALOpen( pathname.c_str(), GA_ReadOnly );
    if( df == NULL ) {
        fprintf(stderr,"Could not open %s\n", pathname.c_str() );
        exit(1);
    }

    rows = df->GetRasterYSize();
    cols = df->GetRasterXSize();
    bands = df->GetRasterCount();
    //create_image(rows,cols);

    if ( bands < 3 ) {
        fprintf(stderr,"%s does not have 3 bands\n",
                pathname.c_str() );
        delete df;
        return false;
    }

    for ( i = 0; i < 3; i++ ) {
        bd = df->GetRasterBand(i+1);
        bd->RasterIO ( GF_Read, 0,0, cols, rows, img[i].data, cols, rows,
                       GDT_Byte, 0,0);
    }
    delete df;
}
开发者ID:dmagiccys,项目名称:pfmabe,代码行数:56,代码来源:rgb_image.cpp

示例11: bin2ascii

void bin2ascii(char *binFile, char *asciiFile){
    GDALDataset *layer;
    GDALAllRegister();
    layer = (GDALDataset *)GDALOpen(binFile, GA_ReadOnly);
    
    int bandNumber = 1;
    GDALRasterBand *band = layer->GetRasterBand(bandNumber);
    GDALDataType type    = band->GetRasterDataType();

    double ranges[6];
    layer->GetGeoTransform(ranges);

    ofstream outFile;
    outFile.open(asciiFile);
     
    outFile<<"ncols "<<layer->GetRasterXSize()<<"\n";
    outFile<<"nrows "<<layer->GetRasterYSize()<<"\n";
    outFile<<"xllcorner "<<ranges[0]<<"\n";
    outFile<<"yllcorner "<<(ranges[3] + layer->GetRasterXSize() * ranges[4] + layer->GetRasterYSize() * ranges[5])<<"\n";
    outFile<<"cellsize " <<ranges[1]<<"\n";
    outFile<<"nodata_value "<<"-9999"<<"\n";
    //getchar(); getchar();

    int cols = layer->GetRasterXSize();
    int rows = layer->GetRasterYSize();
    double NODATA_VAL = band->GetNoDataValue();

    cout<<"NODATA_VALUE= "<<NODATA_VAL<<"\n";

    int size = GDALGetDataTypeSize(type) / 8;
    void *data = CPLMalloc(size);
    //CPLErr err = band->RasterIO(GF_Read, 0, 0, cols, rows, data, cols, rows, type, 0, 0);
	//getchar(); getchar();
    //for(int j=0; j<rows*cols; j++){
	//int col, row;
    for(int row=0; row<rows; row++){
	for(int col=0; col<cols; col++){	
	 
	CPLErr err = band->RasterIO(GF_Read, col, row, 1, 1, data, 1, 1, type, 0, 0);
	double tempVal = readValueB2A(data, type, 0);
	outFile<<( tempVal != NODATA_VAL ? tempVal : -9999)<<" "; 
	
    	    //if((j+1)%cols == 0){
	//	cout<<"\n";
		//getchar(); getchar();
	//	}
	}
	outFile<<"\n"; 
	//getchar();
    }
	cout<<"Bin2Ascii.. Done!\n";
	outFile.close();
	//getchar(); getchar();
}
开发者ID:HydroCouple,项目名称:FVHMComponent,代码行数:54,代码来源:bin2ascii.cpp

示例12: ReadBlock

int GDAL_EDBFile::ReadBlock( int channel,
                             int block_index, void *buffer,
                             int win_xoff, int win_yoff,
                             int win_xsize, int win_ysize )

{
    GDALRasterBand *poBand = poDS->GetRasterBand(channel);
    int nBlockXSize, nBlockYSize;
    int nBlockX, nBlockY;
    int nWidthInBlocks;
    int nPixelOffset;
    int nLineOffset;

    if( GetType(channel) == CHN_UNKNOWN )
    {
        ThrowPCIDSKException("%s channel type not supported for PCIDSK access.",
                             GDALGetDataTypeName(poBand->GetRasterDataType()) );
    }

    poBand->GetBlockSize( &nBlockXSize, &nBlockYSize );

    nWidthInBlocks = (poBand->GetXSize() + nBlockXSize - 1) / nBlockXSize;
    
    nBlockX = block_index % nWidthInBlocks;
    nBlockY = block_index / nWidthInBlocks;

    nPixelOffset = GDALGetDataTypeSize(poBand->GetRasterDataType()) / 8;
    nLineOffset = win_xsize * nPixelOffset;

/* -------------------------------------------------------------------- */
/*      Are we reading a partial block at the edge of the database?     */
/*      If so, ensure we don't read off the database.                   */
/* -------------------------------------------------------------------- */
    if( nBlockX * nBlockXSize + win_xoff + win_xsize > poBand->GetXSize() )
        win_xsize = poBand->GetXSize() - nBlockX * nBlockXSize - win_xoff;

    if( nBlockY * nBlockYSize + win_yoff + win_ysize > poBand->GetYSize() )
        win_ysize = poBand->GetYSize() - nBlockY * nBlockYSize - win_yoff;

    CPLErr eErr = poBand->RasterIO( GF_Read, 
                                    nBlockX * nBlockXSize + win_xoff, 
                                    nBlockY * nBlockYSize + win_yoff,
                                    win_xsize, win_ysize, 
                                    buffer, win_xsize, win_ysize, 
                                    poBand->GetRasterDataType(),
                                    nPixelOffset, nLineOffset, NULL );

    if( eErr != CE_None )
    {
        ThrowPCIDSKException( "%s", CPLGetLastErrorMsg() );
    }

    return 1;
}
开发者ID:AbdelghaniDr,项目名称:mirror,代码行数:54,代码来源:gdal_edb.cpp

示例13: createMark

void HazePerfection::createMark(float b)
{
	const char *pszFormat = "GTiff";
	const char *markfile = m_markfilename.c_str();
	GDALDriver *poDriver = (GDALDriver*)GDALGetDriverByName(pszFormat);
	markDataset = poDriver->Create(markfile, nXSize, nYSize, 1, GDT_Float32, NULL);
	markDataset->SetGeoTransform(sGeoTrans);
	markDataset->SetProjection(hotDataset->GetProjectionRef());
	float *pixelData = new float[nXSize*nYSize];
	GDALRasterBand *maskBand = maskDataset->GetRasterBand(1);
	maskBand->RasterIO(GF_Read, 0, 0, nXSize, nYSize, pixelData, nXSize, nYSize, GDT_Float32, 0, 0);
	for (int i = 1; i < nYSize-1; i++)
	{
		for (int j = 1; j < nXSize - 1; j++)
			pixelData[i*nXSize + j] = b;
	}
	GDALRasterBand *markBand = markDataset->GetRasterBand(1);
	markBand->RasterIO(GF_Write, 0, 0, nXSize, nYSize, pixelData, nXSize, nYSize, GDT_Float32, 0, 0);
	delete[]pixelData;
}
开发者ID:MrXue,项目名称:removeHaze,代码行数:20,代码来源:RemoveHaze.cpp

示例14: writeOutputLine

void PLCContext::writeOutputLine(int line, PLCLine *lineObj)

{
    CPLAssert( outputDS != NULL );
    
    int  i, width = outputDS->GetRasterXSize();

    for( i=0; i < outputDS->GetRasterCount(); i++ )
    {
        CPLErr eErr;
        GDALRasterBand *band = outputDS->GetRasterBand(i+1);
        
        if( band->GetColorInterpretation() == GCI_AlphaBand )
            eErr = band->RasterIO(GF_Write, 0, line, width, 1, 
                                  lineObj->getAlpha(), width, 1, GDT_Byte,
                                  0, 0);
        else
            eErr = band->RasterIO(GF_Write, 0, line, width, 1, 
                                  lineObj->getBand(i), width, 1, GDT_Int16, 
                                  0, 0);

        if( eErr != CE_None )
            exit(1);

        if( sourceTraceDS != NULL )
        {
            eErr = sourceTraceDS->GetRasterBand(1)->
                RasterIO(GF_Write, 0, line, width, 1, 
                         lineObj->getSource(), width, 1, GDT_UInt16, 
                         0, 0);
        }
        if( qualityDS != NULL )
        {
            eErr = qualityDS->GetRasterBand(1)->
                RasterIO(GF_Write, 0, line, width, 1, 
                         lineObj->getQuality(), width, 1, GDT_Float32, 
                         0, 0);
        }
    }
}
开发者ID:barrycug,项目名称:plcompositor,代码行数:40,代码来源:plccontext.cpp

示例15: topLeft

int
NBHeightMapper::loadTiff(const std::string& file) {
#ifdef HAVE_GDAL
    GDALAllRegister();
    GDALDataset* poDataset = (GDALDataset*)GDALOpen(file.c_str(), GA_ReadOnly);
    if (poDataset == 0) {
        WRITE_ERROR("Cannot load GeoTIFF file.");
        return 0;
    }
    const int xSize = poDataset->GetRasterXSize();
    const int ySize = poDataset->GetRasterYSize();
    double adfGeoTransform[6];
    if (poDataset->GetGeoTransform(adfGeoTransform) == CE_None) {
        Position topLeft(adfGeoTransform[0], adfGeoTransform[3]);
        mySizeOfPixel.set(adfGeoTransform[1], adfGeoTransform[5]);
        const double horizontalSize = xSize * mySizeOfPixel.x();
        const double verticalSize = ySize * mySizeOfPixel.y();
        myBoundary.add(topLeft);
        myBoundary.add(topLeft.x() + horizontalSize, topLeft.y() + verticalSize);
    } else {
        WRITE_ERROR("Could not parse geo information from " + file + ".");
        return 0;
    }
    const int picSize = xSize * ySize;
    myRaster = (int16_t*)CPLMalloc(sizeof(int16_t) * picSize);
    for (int i = 1; i <= poDataset->GetRasterCount(); i++) {
        GDALRasterBand* poBand = poDataset->GetRasterBand(i);
        if (poBand->GetColorInterpretation() != GCI_GrayIndex) {
            WRITE_ERROR("Unknown color band in " + file + ".");
            clearData();
            break;
        }
        if (poBand->GetRasterDataType() != GDT_Int16) {
            WRITE_ERROR("Unknown data type in " + file + ".");
            clearData();
            break;
        }
        assert(xSize == poBand->GetXSize() && ySize == poBand->GetYSize());
        if (poBand->RasterIO(GF_Read, 0, 0, xSize, ySize, myRaster, xSize, ySize, GDT_Int16, 0, 0) == CE_Failure) {
            WRITE_ERROR("Failure in reading " + file + ".");
            clearData();
            break;
        }
    }
    GDALClose(poDataset);
    return picSize;
#else
    UNUSED_PARAMETER(file);
    WRITE_ERROR("Cannot load GeoTIFF file since SUMO was compiled without GDAL support.");
    return 0;
#endif
}
开发者ID:fieryzig,项目名称:sumo,代码行数:52,代码来源:NBHeightMapper.cpp


注:本文中的GDALRasterBand::RasterIO方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。