Geoscience Reference
In-Depth Information
#include <string>
#include "gdal_priv.h"
#include "cpl_conv.h"
#include "pcl_string.h"
using namespace std;
int main( int argc, char *argv[])
{
GDALDataset *poDataset;
GDALAllRegister();
const char *pszFormat="GTiff";//image format
GDALDriver *poDriver;
poDriver = GetGDALDriverManager()->GetDriverByName(pszFormat);
try {
if ( poDriver == NULL ){
string errorString="Could not find a driver";
throw (errorString);
}
char **papszMetadata;
papszMetadata = poDriver->GetMetadata();
if (!CSLFetchBoolean( papszMetadata, GDAL_DCAP_CREATE, FALSE
)){
string errorString="Create method not supported, use CreateCopy
";
throw (errorString);
}
}
catch (string errorString){
cout <<"Error: "<< errorString << endl;
exit(1);
}
//we create a tiled, compressed image, interleaved by band
char **papszOptions=NULL;
papszOptions = CSLSetNameValue( papszOptions,"TILED","YES");
papszOptions = CSLSetNameValue( papszOptions,"COMPRESS",
"
LZW");
papszOptions = CSLSetNameValue( papszOptions,"INTERLEAVE",
"
BAND");
string imageFilename="myNewImage.tif";//image name
int ncol=512;//number of columns in image
int nrow=512;//number of rows in image
int nband=1;//write single band only
poDataset=poDriver->Create(imageFilename.c_str(), ncol, nrow, nband
, GDT_UInt16, papszOptions);
//perform dataset (write) operations here...
//clean up:
CSLDestroy(papszOptions);
CSLDestroy(papszMetadata);
//close the dataset
GDALClose( (GDALDataset*) poDataset );
return 0;
 
Search WWH ::




Custom Search