本文整理汇总了C++中GDALGetRasterXSize函数的典型用法代码示例。如果您正苦于以下问题:C++ GDALGetRasterXSize函数的具体用法?C++ GDALGetRasterXSize怎么用?C++ GDALGetRasterXSize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了GDALGetRasterXSize函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GDALOpen
QgsAlignRaster::RasterInfo::RasterInfo( const QString& layerpath )
{
mDataset = GDALOpen( layerpath.toLocal8Bit().constData(), GA_ReadOnly );
if ( !mDataset )
return;
mXSize = GDALGetRasterXSize( mDataset );
mYSize = GDALGetRasterYSize( mDataset );
GDALGetGeoTransform( mDataset, mGeoTransform );
// TODO: may be null or empty string
mCrsWkt = QString::fromAscii( GDALGetProjectionRef( mDataset ) );
mBandCnt = GDALGetBandNumber( mDataset );
}
示例2: GDALGetRasterCount
void MDAL::GdalDataset::parseParameters()
{
mNBands = static_cast<unsigned int>( GDALGetRasterCount( mHDataset ) );
if ( mNBands == 0 ) throw MDAL_Status::Err_InvalidData;
GDALGetGeoTransform( mHDataset, mGT ); // in case of error it returns Identid
mXSize = static_cast<unsigned int>( GDALGetRasterXSize( mHDataset ) ); //raster width in pixels
if ( mXSize == 0 ) throw MDAL_Status::Err_InvalidData;
mYSize = static_cast<unsigned int>( GDALGetRasterYSize( mHDataset ) ); //raster height in pixels
if ( mYSize == 0 ) throw MDAL_Status::Err_InvalidData;
mNPoints = mXSize * mYSize;
mNVolumes = ( mXSize - 1 ) * ( mYSize - 1 );
}
示例3: WorkerFunc
static void WorkerFunc( void * )
{
GDALDatasetH hDS;
int iIter, iOpenIter;
for( iOpenIter = 0; iOpenIter < nOpenIterations; iOpenIter++ )
{
if( bLockOnOpen )
CPLAcquireMutex( pGlobalMutex, 100.0 );
hDS = GDALOpen( pszFilename, GA_ReadOnly );
if( bLockOnOpen )
CPLReleaseMutex( pGlobalMutex );
for( iIter = 0; iIter < nIterations && hDS != NULL; iIter++ )
{
int nMyChecksum;
nMyChecksum = GDALChecksumImage( GDALGetRasterBand( hDS, 1 ),
0, 0,
GDALGetRasterXSize( hDS ),
GDALGetRasterYSize( hDS ) );
if( nMyChecksum != nChecksum )
{
printf( "Checksum ERROR in worker thread!\n" );
break;
}
}
if( hDS )
{
if( bLockOnOpen )
CPLAcquireMutex( pGlobalMutex, 100.0 );
GDALClose( hDS );
if( bLockOnOpen )
CPLReleaseMutex( pGlobalMutex );
}
}
CPLAcquireMutex( pGlobalMutex, 100.0 );
nPendingThreads--;
CPLReleaseMutex( pGlobalMutex );
}
示例4: GDALOpen
//duplicated from QgsNineCellFilter. Todo: make common base class
GDALDatasetH QgsRelief::openInputFile( int &nCellsX, int &nCellsY )
{
GDALDatasetH inputDataset = GDALOpen( mInputFile.toUtf8().constData(), GA_ReadOnly );
if ( inputDataset )
{
nCellsX = GDALGetRasterXSize( inputDataset );
nCellsY = GDALGetRasterYSize( inputDataset );
//we need at least one band
if ( GDALGetRasterCount( inputDataset ) < 1 )
{
GDALClose( inputDataset );
return nullptr;
}
}
return inputDataset;
}
示例5: GDALOpen
GDALDatasetH QgsNineCellFilter::openInputFile( int& nCellsX, int& nCellsY )
{
GDALDatasetH inputDataset = GDALOpen( mInputFile.toLocal8Bit().data(), GA_ReadOnly );
if ( inputDataset != NULL )
{
nCellsX = GDALGetRasterXSize( inputDataset );
nCellsY = GDALGetRasterYSize( inputDataset );
//we need at least one band
if ( GDALGetRasterCount( inputDataset ) < 1 )
{
GDALClose( inputDataset );
return NULL;
}
}
return inputDataset;
}
示例6: GDALOpen
//duplicated from QgsNineCellFilter. Todo: make common base class
GDALDatasetH QgsRelief::openInputFile( int& nCellsX, int& nCellsY )
{
GDALDatasetH inputDataset = GDALOpen( TO8F( mInputFile ), GA_ReadOnly );
if ( inputDataset != NULL )
{
nCellsX = GDALGetRasterXSize( inputDataset );
nCellsY = GDALGetRasterYSize( inputDataset );
//we need at least one band
if ( GDALGetRasterCount( inputDataset ) < 1 )
{
GDALClose( inputDataset );
return NULL;
}
}
return inputDataset;
}
示例7: QgsRectangle
void TestQgsGdalUtils::testCreateSingleBandMemoryDataset()
{
gdal::dataset_unique_ptr ds1 = QgsGdalUtils::createSingleBandMemoryDataset( GDT_Float32, QgsRectangle( 1, 1, 21, 11 ), 40, 20, QgsCoordinateReferenceSystem( "EPSG:4326" ) );
QVERIFY( ds1 );
QCOMPARE( GDALGetRasterCount( ds1.get() ), 1 );
QCOMPARE( GDALGetRasterXSize( ds1.get() ), 40 );
QCOMPARE( GDALGetRasterYSize( ds1.get() ), 20 );
QCOMPARE( GDALGetProjectionRef( ds1.get() ), EPSG_4326_WKT );
double geoTransform[6];
double geoTransformExpected[] = { 1, 0.5, 0, 11, 0, -0.5 };
QCOMPARE( GDALGetGeoTransform( ds1.get(), geoTransform ), CE_None );
QVERIFY( memcmp( geoTransform, geoTransformExpected, sizeof( double ) * 6 ) == 0 );
QCOMPARE( GDALGetRasterDataType( GDALGetRasterBand( ds1.get(), 1 ) ), GDT_Float32 );
}
示例8: make_me_a_sandwitch
/* Makes a copy of a dataset, and opens it for writing.. */
GDALDatasetH make_me_a_sandwitch(GDALDatasetH *in_dataset, char *filename)
{
char **papszOptions = NULL;
const char *pszFormat = "GTiff";
GDALDriverH hDriver;
GDALDatasetH out_gdalfile;
hDriver = GDALGetDriverByName( pszFormat );
papszOptions = CSLSetNameValue( papszOptions, "TILED", "YES" );
papszOptions = CSLSetNameValue( papszOptions, "COMPRESS", "DEFLATE" );
/*Create copy..*/
/*return GDALCreateCopy( hDriver, filename, *in_dataset, FALSE, papszOptions, NULL, NULL );*/
return GDALCreate(hDriver, filename,
GDALGetRasterXSize( *in_dataset ),
GDALGetRasterYSize( *in_dataset ),
1,
GDT_Byte, papszOptions );
}
示例9: GDALGetRasterXSize
GDALDatasetH QgsNineCellFilter::openOutputFile( GDALDatasetH inputDataset, GDALDriverH outputDriver )
{
if ( inputDataset == NULL )
{
return NULL;
}
int xSize = GDALGetRasterXSize( inputDataset );
int ySize = GDALGetRasterYSize( inputDataset );;
//open output file
char **papszOptions = NULL;
GDALDatasetH outputDataset = GDALCreate( outputDriver, mOutputFile.toLocal8Bit().data(), xSize, ySize, 1, GDT_Float32, papszOptions );
if ( outputDataset == NULL )
{
return outputDataset;
}
//get geotransform from inputDataset
double geotransform[6];
if ( GDALGetGeoTransform( inputDataset, geotransform ) != CE_None )
{
GDALClose( outputDataset );
return NULL;
}
GDALSetGeoTransform( outputDataset, geotransform );
//make sure mCellSizeX and mCellSizeY are always > 0
mCellSizeX = geotransform[1];
if ( mCellSizeX < 0 )
{
mCellSizeX = -mCellSizeX;
}
mCellSizeY = geotransform[5];
if ( mCellSizeY < 0 )
{
mCellSizeY = -mCellSizeY;
}
const char* projection = GDALGetProjectionRef( inputDataset );
GDALSetProjection( outputDataset, projection );
return outputDataset;
}
示例10: JakoFileDataView
static dErr JakoFileDataView(GDALDatasetH filedata,const char *name,PetscViewer viewer)
{
dErr err;
CPLErr cplerr;
double geo[6],data[8*12];
int nx=8,ny=12,snx,sny;
GDALRasterBandH band;
dFunctionBegin;
cplerr = GDALGetGeoTransform(filedata,geo);
err = dRealTableView(2,3,geo,PETSC_VIEWER_STDOUT_WORLD,"%s:geo",name);dCHK(err);
snx = GDALGetRasterXSize(filedata);
sny = GDALGetRasterYSize(filedata);
err = PetscViewerASCIIPrintf(viewer,"%s: nx=%d ny=%d\n",name,snx,sny);dCHK(err);
band = GDALGetRasterBand(filedata,1);
cplerr = GDALRasterIO(band,GF_Read,snx/2,sny/2,nx,ny,data,nx,ny,GDT_Float64,0,0);dCPLCHK(cplerr);
err = dRealTableView(ny,nx,data,PETSC_VIEWER_STDOUT_WORLD,name);dCHK(err);
dFunctionReturn(0);
}
示例11: JakoGDALMemAddBand
static dErr JakoGDALMemAddBand(GDALDatasetH dset,GDALDataType dtype,void *memory)
{
char buf[256] = {0},**bandoptions = NULL;
int bytes,nx,ny;
CPLErr cplerr;
dErr err;
dFunctionBegin;
bytes = GDALGetDataTypeSize(dtype);
nx = GDALGetRasterXSize(dset);
ny = GDALGetRasterYSize(dset);
err = dMalloc(nx*ny*bytes,(void**)memory);dCHK(err);
// This is where the API moves from merely cumbersome to outright demeaning, like some twisted hazing ritual.
CPLPrintPointer(buf,*(void**)memory,sizeof(buf));
bandoptions = CSLSetNameValue(bandoptions,"DATAPOINTER",buf);
cplerr = GDALAddBand(dset,dtype,bandoptions);dCPLCHK(cplerr);
CSLDestroy(bandoptions);
dFunctionReturn(0);
}
示例12: generic_read
void generic_read(struct FI *f, char *filename)
{
if (filename_corresponds_to_tiffo(filename)) {
#ifdef FANCY_TIFF
f->tiffo = true;
tiff_octaves_init0(f->t, filename, f->megabytes,f->max_octaves);
if (f->option_write) f->t->option_write = true;
f->w = f->t->i->w;
f->h = f->t->i->h;
f->pd = f->t->i->spp;
f->no = f->t->noctaves;
#else
assert(false);
#endif
} else if (!f->option_write && FORCE_GDAL()) {
#ifdef FANCY_GDAL
f->gdal = true;
GDALAllRegister();
char buf[2*FILENAME_MAX];
snprintf(buf, 2*FILENAME_MAX, has_prefix(filename, "http://") ||
has_prefix(filename, "https://") ?
"/vsicurl/%s" : "%s", filename);
f->gdal_img = GDALOpen(buf, GA_ReadOnly);
fprintf(stderr, "gdal_dataset = %p\n", f->gdal_img);
f->pd = GDALGetRasterCount(f->gdal_img);
f->w = GDALGetRasterXSize(f->gdal_img);
f->h = GDALGetRasterYSize(f->gdal_img);
f->no = 1;
for (int i = 0; i < f->pd; i++)
f->gdal_band[i] = GDALGetRasterBand(f->gdal_img, i+1);
#else
assert(false);
#endif
} else {
f->x = iio_read_image_float_vec(filename, &f->w, &f->h, &f->pd);
f->no = build_pyramid(f, f->max_octaves);
snprintf(f->x_filename, FILENAME_MAX, "%s", filename);
f->x_changed = false;
}
}
示例13: GDALGetRasterXSize
// Determines the pixel/line position given an x/y.
// No reprojection is done at this time.
bool Colorization::getPixelAndLinePosition(double x,
double y,
boost::array<double, 6> const& inverse,
boost::int32_t& pixel,
boost::int32_t& line,
void* ds)
{
#ifdef PDAL_HAVE_GDAL
pixel = (boost::int32_t) std::floor(
inverse[0]
+ inverse[1] * x
+ inverse[2] * y);
line = (boost::int32_t) std::floor(
inverse[3]
+ inverse[4] * x
+ inverse[5] * y);
int xs = GDALGetRasterXSize(ds);
int ys = GDALGetRasterYSize(ds);
if (!xs || !ys)
{
throw pdal_error("Unable to get X or Y size from raster!");
}
if (pixel < 0 ||
line < 0 ||
pixel >= xs ||
line >= ys
)
{
// The x, y is not coincident with this raster
return false;
}
#endif
return true;
}
示例14: msUVRASTERLayerGetExtent
int msUVRASTERLayerGetExtent(layerObj *layer, rectObj *extent)
{
char szPath[MS_MAXPATHLEN];
mapObj *map = layer->map;
double adfGeoTransform[6];
int nXSize, nYSize;
GDALDatasetH hDS;
shapefileObj *tileshpfile;
int tilelayerindex = -1;
CPLErr eErr = CE_Failure;
char *decrypted_path;
if( (!layer->data || strlen(layer->data) == 0)
&& layer->tileindex == NULL) {
/* should we be issuing a specific error about not supporting
extents for tileindexed raster layers? */
return MS_FAILURE;
}
if( map == NULL )
return MS_FAILURE;
/* If the layer use a tileindex, return the extent of the tileindex shapefile/referenced layer */
if (layer->tileindex) {
tilelayerindex = msGetLayerIndex(map, layer->tileindex);
if(tilelayerindex != -1) /* does the tileindex reference another layer */
return msLayerGetExtent(GET_LAYER(map, tilelayerindex), extent);
else {
tileshpfile = (shapefileObj *) malloc(sizeof(shapefileObj));
MS_CHECK_ALLOC(tileshpfile, sizeof(shapefileObj), MS_FAILURE);
if(msShapefileOpen(tileshpfile, "rb", msBuildPath3(szPath, map->mappath, map->shapepath, layer->tileindex), MS_TRUE) == -1)
if(msShapefileOpen(tileshpfile, "rb", msBuildPath(szPath, map->mappath, layer->tileindex), MS_TRUE) == -1)
return MS_FAILURE;
*extent = tileshpfile->bounds;
msShapefileClose(tileshpfile);
free(tileshpfile);
return MS_SUCCESS;
}
}
msTryBuildPath3(szPath, map->mappath, map->shapepath, layer->data);
decrypted_path = msDecryptStringTokens( map, szPath );
msAcquireLock( TLOCK_GDAL );
if( decrypted_path ) {
hDS = GDALOpen(decrypted_path, GA_ReadOnly );
msFree( decrypted_path );
} else
hDS = NULL;
if( hDS != NULL ) {
nXSize = GDALGetRasterXSize( hDS );
nYSize = GDALGetRasterYSize( hDS );
eErr = GDALGetGeoTransform( hDS, adfGeoTransform );
GDALClose( hDS );
}
msReleaseLock( TLOCK_GDAL );
if( hDS == NULL || eErr != CE_None ) {
return MS_FAILURE;
}
/* If this appears to be an ungeoreferenced raster than flip it for
mapservers purposes. */
if( adfGeoTransform[5] == 1.0 && adfGeoTransform[3] == 0.0 ) {
adfGeoTransform[5] = -1.0;
adfGeoTransform[3] = nYSize;
}
extent->minx = adfGeoTransform[0];
extent->maxy = adfGeoTransform[3];
extent->maxx = adfGeoTransform[0] + nXSize * adfGeoTransform[1];
extent->miny = adfGeoTransform[3] + nYSize * adfGeoTransform[5];
return MS_SUCCESS;
}
示例15: main
int main( int argc, char ** argv )
{
GDALDatasetH hSrcDS;
int iY, iX, nOutLevel=0, nXSize, nYSize, iArg, nFillDist=0;
void *pStream;
GInt16 *panData;
const char *pszFilename = NULL;
GDALRasterBandH hSrcBand;
double adfGeoTransform[6];
int bEnableTrim = FALSE;
GInt16 noDataValue = 0;
int bHasNoData;
/* -------------------------------------------------------------------- */
/* Identify arguments. */
/* -------------------------------------------------------------------- */
for( iArg = 1; iArg < argc; iArg++ )
{
if( EQUAL(argv[iArg],"-trim") )
bEnableTrim = TRUE;
else if( EQUAL(argv[iArg],"-fill") )
nFillDist = atoi(argv[++iArg]);
else if( EQUAL(argv[iArg],"-level") )
nOutLevel = atoi(argv[++iArg]);
else
{
if( pszFilename != NULL )
Usage();
pszFilename = argv[iArg];
}
}
if( pszFilename == NULL )
Usage();
/* -------------------------------------------------------------------- */
/* Open input file. */
/* -------------------------------------------------------------------- */
GDALAllRegister();
hSrcDS = GDALOpen( pszFilename, GA_ReadOnly );
if( hSrcDS == NULL )
exit(1);
hSrcBand = GDALGetRasterBand( hSrcDS, 1 );
noDataValue = (GInt16)GDALGetRasterNoDataValue(hSrcBand, &bHasNoData);
nXSize = GDALGetRasterXSize( hSrcDS );
nYSize = GDALGetRasterYSize( hSrcDS );
GDALGetGeoTransform( hSrcDS, adfGeoTransform );
/* -------------------------------------------------------------------- */
/* Create output stream. */
/* -------------------------------------------------------------------- */
pStream = DTEDCreatePtStream( ".", nOutLevel );
if( pStream == NULL )
exit( 1 );
/* -------------------------------------------------------------------- */
/* Process all the profiles. */
/* -------------------------------------------------------------------- */
panData = (GInt16 *) malloc(sizeof(GInt16) * nXSize);
for( iY = 0; iY < nYSize; iY++ )
{
GDALRasterIO( hSrcBand, GF_Read, 0, iY, nXSize, 1,
panData, nXSize, 1, GDT_Int16, 0, 0 );
if (bHasNoData)
{
for( iX = 0; iX < nXSize; iX++ )
{
if (panData[iX] == noDataValue)
panData[iX] = DTED_NODATA_VALUE;
}
}
for( iX = 0; iX < nXSize; iX++ )
{
DTEDWritePt( pStream,
adfGeoTransform[0]
+ adfGeoTransform[1] * (iX + 0.5)
+ adfGeoTransform[2] * (iY + 0.5),
adfGeoTransform[3]
+ adfGeoTransform[4] * (iX + 0.5)
+ adfGeoTransform[5] * (iY + 0.5),
panData[iX] );
}
}
free( panData );
/* -------------------------------------------------------------------- */
/* Cleanup. */
//.........这里部分代码省略.........