本文整理汇总了C++中GDALRasterBand::GetXSize方法的典型用法代码示例。如果您正苦于以下问题:C++ GDALRasterBand::GetXSize方法的具体用法?C++ GDALRasterBand::GetXSize怎么用?C++ GDALRasterBand::GetXSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类GDALRasterBand
的用法示例。
在下文中一共展示了GDALRasterBand::GetXSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Init
/*
* Initializes the object, assuming that filename, origin, size, etc are already set on the
* member variables. Makes sure the raster can be opened, sets the block size, NODATA value,
* pixel size, and the extent of the raster. If not using the full image then makes sure that
* the subset chosen (based on origin and size) is valid. If using the full image then sets the
* size and origin is assumed to be 0,0 and is set in the constructor.
* @param fullImage True if using the full image, False if using a subset.
*/
void Raster::Init(bool bFullImage)
{
Init();
GDALDataset * ds = (GDALDataset*) GDALOpen(m_sFilePath, GA_ReadOnly);
if (ds == NULL)
throw RasterManagerException(INPUT_FILE_NOT_VALID, CPLGetLastErrorMsg());
GDALRasterBand * band = ds->GetRasterBand(1);
double dRMin, dRMax, dRMean, dRStdDev;
// Get some easy stats that GDAL gives us
band->GetStatistics( 0 , true, &dRMin, &dRMax, &dRMean, &dRStdDev );
m_dRasterMax = dRMax;
m_dRasterMin = dRMin;
m_dRasterMean = dRMean;
m_dRasterStdDev = dRStdDev;
OGRLinearRing ring = OGRLinearRing();
if (bFullImage)
{
SetCols( band->GetXSize() );
SetRows( band->GetYSize() );
ring.addPoint(GetLeft(), GetTop());
ring.addPoint(GetLeft(), GetTop() + (GetCellHeight() * GetRows()));
ring.addPoint(GetLeft() + (GetCellWidth() * GetCols()), GetTop() + (GetCellHeight() * GetRows()));
ring.addPoint(GetLeft() + (GetCellWidth() * GetCols()), GetTop());
ring.closeRings();
}
else
{
if ((GetLeft() + GetCols() > band->GetXSize()) || (GetTop() + GetRows() > band->GetYSize()))
{
QString sErr = QString("Invalid origin ( %1, %2 ) and size ( %5, %6 ) for file: %7")
.arg(GetLeft())
.arg(GetTop())
.arg(GetCols())
.arg(GetRows())
.arg(FilePath());
throw RasterManagerException(INPUT_FILE_NOT_VALID, sErr);
}
double xMapOrigin = GetLeft() + (GetLeft() * GetCellWidth());
double yMapOrigin = GetTop() + (GetTop() * GetCellHeight());
ring.addPoint(xMapOrigin, yMapOrigin);
ring.addPoint(xMapOrigin, yMapOrigin + (GetCellHeight() * GetRows()));
ring.addPoint(xMapOrigin + (GetCellWidth() * GetCols()), yMapOrigin + (GetCellHeight() * GetRows()));
ring.addPoint(xMapOrigin + (GetCellWidth() * GetCols()), yMapOrigin);
ring.closeRings();
}
GDALClose(ds);
}
示例2: 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;
}
示例3: WriteBlock
int GDAL_EDBFile::WriteBlock( int channel, int block_index, void *buffer)
{
GDALRasterBand *poBand = poDS->GetRasterBand(channel);
int nBlockXSize, nBlockYSize;
int nBlockX, nBlockY;
int nWinXSize, nWinYSize;
int nWidthInBlocks;
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;
/* -------------------------------------------------------------------- */
/* 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 + nBlockXSize > poBand->GetXSize() )
nWinXSize = poBand->GetXSize() - nBlockX * nBlockXSize;
else
nWinXSize = nBlockXSize;
if( nBlockY * nBlockYSize + nBlockYSize > poBand->GetYSize() )
nWinYSize = poBand->GetYSize() - nBlockY * nBlockYSize;
else
nWinYSize = nBlockYSize;
CPLErr eErr = poBand->RasterIO( GF_Write,
nBlockX * nBlockXSize,
nBlockY * nBlockYSize,
nWinXSize, nWinYSize,
buffer, nWinXSize, nWinYSize,
poBand->GetRasterDataType(), 0, 0, NULL );
if( eErr != CE_None )
{
ThrowPCIDSKException( "%s", CPLGetLastErrorMsg() );
}
return 1;
}
示例4: KEACopyBand
static bool KEACopyBand( GDALRasterBand *pBand, kealib::KEAImageIO *pImageIO, int nBand, int nTotalbands, GDALProgressFunc pfnProgress, void *pProgressData)
{
// first copy the raster data over
if( !KEACopyRasterData( pBand, pImageIO, nBand, -1, nTotalbands, pfnProgress, pProgressData) )
return false;
// are there any overviews?
int nOverviews = pBand->GetOverviewCount();
for( int nOverviewCount = 0; nOverviewCount < nOverviews; nOverviewCount++ )
{
GDALRasterBand *pOverview = pBand->GetOverview(nOverviewCount);
int nOverviewXSize = pOverview->GetXSize();
int nOverviewYSize = pOverview->GetYSize();
pImageIO->createOverview( nBand, nOverviewCount + 1, nOverviewXSize, nOverviewYSize);
if( !KEACopyRasterData( pOverview, pImageIO, nBand, nOverviewCount + 1, nTotalbands, pfnProgress, pProgressData) )
return false;
}
// now metadata
KEACopyMetadata(pBand, pImageIO, nBand);
// and attributes
KEACopyRAT(pBand, pImageIO, nBand);
// and description
KEACopyDescription(pBand, pImageIO, nBand);
// and no data
KEACopyNoData(pBand, pImageIO, nBand);
return true;
}
示例5: get_overview_meta
void gdal_featureset::get_overview_meta(GDALRasterBand* band)
{
int band_overviews = band->GetOverviewCount();
if (band_overviews > 0)
{
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: " << band_overviews << " overviews found!";
for (int b = 0; b < band_overviews; b++)
{
GDALRasterBand * overview = band->GetOverview(b);
MAPNIK_LOG_DEBUG(gdal) << boost::format("gdal_featureset: Overview=%d Width=%d Height=%d")
% b % overview->GetXSize() % overview->GetYSize();
}
}
else
{
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: No overviews found!";
}
int bsx,bsy;
double scale;
band->GetBlockSize(&bsx, &bsy);
scale = band->GetScale();
MAPNIK_LOG_DEBUG(gdal) << boost::format("gdal_featureset: Block=%dx%d Scale=%f Type=%s Color=%s") % bsx % bsy % scale
% GDALGetDataTypeName(band->GetRasterDataType())
% GDALGetColorInterpretationName(band->GetColorInterpretation());
}
示例6: MetaDataInfo
void DemReader::MetaDataInfo(GDALDataset* gdalDataset, MapControllerPtr mapController)
{
FileMetaData* header = mapController->GetMapModel()->GetMetaData();
header->driverDesc = gdalDataset->GetDriver()->GetDescription();
header->driverMetaData = gdalDataset->GetDriver()->GetMetadataItem(GDAL_DMD_LONGNAME);
Log::Inst().Write("Driver: " + header->driverDesc + " \\ " + header->driverMetaData);
header->xSize = gdalDataset->GetRasterXSize();
header->ySize = gdalDataset->GetRasterYSize();
header->bands = gdalDataset->GetRasterCount();
Log::Inst().Write("Size (x,y): " +
StringTools::ToString(header->xSize) + ", " +
StringTools::ToString(header->ySize));
Log::Inst().Write("Bands: " + StringTools::ToString(header->bands));
header->projection = std::string(gdalDataset->GetProjectionRef());
Log::Inst().Write("Projection: " + header->projection);
double adfGeoTransform[6];
gdalDataset->GetGeoTransform( adfGeoTransform );
header->originX = adfGeoTransform[0];
header->originY = adfGeoTransform[3];
Log::Inst().Write("Origin: " +
StringTools::ToString(adfGeoTransform[0]) + ", " +
StringTools::ToString(adfGeoTransform[3]));
header->pixelSizeX = adfGeoTransform[1];
header->pixelSizeY = adfGeoTransform[5];
Log::Inst().Write("Pixel Size: " +
StringTools::ToString(adfGeoTransform[1]) + ", " +
StringTools::ToString(adfGeoTransform[5]));
GDALRasterBand* gdalBand = gdalDataset->GetRasterBand(1);
int nBlockXSize, nBlockYSize;
gdalBand->GetBlockSize(&nBlockXSize, &nBlockYSize);
header->dataType = std::string(GDALGetDataTypeName(gdalBand->GetRasterDataType()));
Log::Inst().Write("Block, Type: " + StringTools::ToString(nBlockXSize) + ", " +
StringTools::ToString(nBlockYSize) + ", " +
std::string(header->dataType));
header->colourInterpretation = std::string(GDALGetColorInterpretationName(gdalBand->GetColorInterpretation()));
Log::Inst().Write("Color Interpretation: " + header->colourInterpretation);
header->extents.x = adfGeoTransform[0];
header->extents.y = adfGeoTransform[3] + gdalBand->GetYSize()*adfGeoTransform[5];
Log::Inst().Write("Lower, Left (x,y): " +
StringTools::ToString(header->extents.x) + ", " +
StringTools::ToString(header->extents.y));
header->extents.dx = adfGeoTransform[0]+gdalBand->GetXSize()*adfGeoTransform[1];
header->extents.dy = adfGeoTransform[3];
Log::Inst().Write("Upper, Right (x,y): " +
StringTools::ToString(header->extents.dx) + ", " +
StringTools::ToString(header->extents.dy));
Log::Inst().Write("");
}
示例7: get_overview_meta
void gdal_featureset::get_overview_meta(GDALRasterBand* band)
{
int band_overviews = band->GetOverviewCount();
if (band_overviews > 0)
{
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: " << band_overviews << " overviews found!";
for (int b = 0; b < band_overviews; b++)
{
GDALRasterBand * overview = band->GetOverview(b);
MAPNIK_LOG_DEBUG(gdal) << "Overview= " << b
<< " Width=" << overview->GetXSize()
<< " Height=" << overview->GetYSize();
}
}
else
{
MAPNIK_LOG_DEBUG(gdal) << "gdal_featureset: No overviews found!";
}
int bsx,bsy;
double scale;
band->GetBlockSize(&bsx, &bsy);
scale = band->GetScale();
MAPNIK_LOG_DEBUG(gdal) << "Block=" << bsx << "x" << bsy
<< " Scale=" << scale
<< " Type=" << GDALGetDataTypeName(band->GetRasterDataType())
<< "Color=" << GDALGetColorInterpretationName(band->GetColorInterpretation());
}
示例8: getGDALRasterPtr
SEXP
RGDAL_GetXSize(SEXP sRasterBand) {
GDALRasterBand *pRasterBand = getGDALRasterPtr(sRasterBand);
return(ScalarInteger(pRasterBand->GetXSize()));
}
示例9: 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;
}
示例10: getGDALDimensions
void getGDALDimensions(const std::string &filename, int &height, int &width){
GDALAllRegister();
GDALDataset *fin = (GDALDataset*)GDALOpen(filename.c_str(), GA_ReadOnly);
assert(fin!=NULL);
GDALRasterBand *band = fin->GetRasterBand(1);
height = band->GetYSize();
width = band->GetXSize();
GDALClose(fin);
}
示例11: 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
}
示例12: IRasterIO
CPLErr GDALProxyRasterBand::IRasterIO( GDALRWFlag eRWFlag,
int nXOff, int nYOff, int nXSize, int nYSize,
void * pData, int nBufXSize, int nBufYSize,
GDALDataType eBufType,
GSpacing nPixelSpace,
GSpacing nLineSpace,
GDALRasterIOExtraArg* psExtraArg )
{
CPLErr ret;
GDALRasterBand* poSrcBand = RefUnderlyingRasterBand();
if (poSrcBand)
{
/* -------------------------------------------------------------------- */
/* Do some validation of parameters. */
/* -------------------------------------------------------------------- */
if( nXOff + nXSize > poSrcBand->GetXSize() || nYOff + nYSize > poSrcBand->GetYSize() )
{
ReportError( CE_Failure, CPLE_IllegalArg,
"Access window out of range in RasterIO(). Requested\n"
"(%d,%d) of size %dx%d on raster of %dx%d.",
nXOff, nYOff, nXSize, nYSize, poSrcBand->GetXSize(), poSrcBand->GetYSize() );
ret = CE_Failure;
}
else
{
ret = poSrcBand->IRasterIO(eRWFlag, nXOff, nYOff, nXSize, nYSize,
pData, nBufXSize, nBufYSize, eBufType,
nPixelSpace, nLineSpace, psExtraArg );
}
UnrefUnderlyingRasterBand(poSrcBand);
}
else
{
ret = CE_Failure;
}
return ret;
}
示例13: getGDALHeader
void getGDALHeader(const std::string &filename, int &height, int &width, T &no_data, double *geotrans){
GDALAllRegister();
GDALDataset *fin = (GDALDataset*)GDALOpen(filename.c_str(), GA_ReadOnly);
assert(fin!=NULL);
GDALRasterBand *band = fin->GetRasterBand(1);
height = band->GetYSize();
no_data = band->GetNoDataValue();
width = band->GetXSize();
fin->GetGeoTransform(geotrans);
GDALClose(fin);
}
示例14: band
void HypSpecImage::band(int band, FloatImage *raster)
{
GDALRasterBand *rb = m_data->GetRasterBand(band);
int width = m_data->GetRasterXSize();
int height = m_data->GetRasterYSize();
int lineSize = rb->GetXSize();
float *line = (float *) CPLMalloc(sizeof(float)*lineSize);
for (int i = 0; i < height; i++) {
rb->RasterIO(GF_Read, 0, i, lineSize, 1, line,
lineSize, 1, GDT_Float32, 0, 0);
for (int j = 0; j < width; j++) {
raster->set(j, i, 0, line[j]);
}
}
CPLFree(line);
}
示例15: getGDALHeader
void getGDALHeader(
const std::string &filename,
int32_t &height,
int32_t &width,
T &no_data,
double geotransform[6]
){
GDALAllRegister();
GDALDataset *fin = (GDALDataset*)GDALOpen(filename.c_str(), GA_ReadOnly);
if(fin==NULL)
throw std::runtime_error("Could not get GDAL header: file '" + filename + "'' did not open!");
GDALRasterBand *band = fin->GetRasterBand(1);
height = band->GetYSize();
no_data = band->GetNoDataValue();
width = band->GetXSize();
fin->GetGeoTransform(geotransform);
GDALClose(fin);
}