I advise you to uninstall Qgis and after to do a fresh installation from here, all dependencies (gdal,proj4, geos, etc) will be automatically satisfied.
I use Linux Mint 13 "Maya", so for me Ubuntu 12.04 (Precise) works fine.
For you I think it will be Ubuntu 13.10 (Saucy).
Here's just the nuts-and-bolts from some working code:
#include "gdal_priv.h"
#include "gdal_alg.h"
// in main()...
GDALAllRegister(); // register all drivers
// open your raster - format doesn't matter as all the drivers are registered
GDALDataset* SourceRasterDS = (GDALDataset*) GDALOpen(Raster,GA_ReadOnly);
double GeoTransform[6]; // Get the geotransform object
SourceRasterDS->GetGeoTransform(GeoTransform); // from the raster dataset
GDALRasterBand* SrcBnd = SourceRasterDS->GetRasterBand(1); // just one band - 1 based, not 0. This raster has only one band.
// read 32bit floating point raster
float* RasterBlock = (float*)malloc(ReadRows*ReadCols*sizeof(float));
SrcBnd->RasterIO(GDALRWFlag::GF_Read,ColOff,RowOff,ReadCols,ReadRows,RasterBlock,ReadCols,ReadRows,GDALDataType::GDT_Float32,0,0);
// localize the X,Y offset to the raster block
LocalX = GeoTransform[0] + (ColOff * GeoTransform[1]);
LocalY = GeoTransform[3] + (RowOff * GeoTransform[5]);
// get a cell in the block - convert X,Y to Col,Row
ThisCol = (Xcoord - LocalX) / GeoTransform[1];
ThisRow = (Ycoord - LocalY) / GeoTransform[5];
// find the index in the 1-d (one dimension, not One Direction) array
LocInArray = (ReadCols*ThisRow) + ThisCol;
CellValue = RasterBlock[LocInArray];
free RasterBlock;
This code gets the value of one cell in a block in the raster.. the original raster was over 2TB as IMG so I couldn't read the whole thing into memory but I needed to do operations within a specified AOI which is translated to ColOff,RowOff and ReadCols by ReadRows rather than trying to read each cell directly from the source raster.
As I said in my comments it is important to set your paths and also add the additional dependency gdal_i.lib or the code will not link properly:
![enter image description here](https://i.stack.imgur.com/W2ONr.png)
Creating/Writing raster is also fairly straightforward:
GDALDriver* IMGdriver = GetGDALDriverManager()->GetDriverByName(DRVname); // get the ERDAS Imagine driver
GDALDataset* AccumDS;
AccumDS = (GDALDataset*) IMGdriver->Create(AccumName,Cols,Rows,1,GDALDataType::GDT_UInt32,NULL);
AccumDS->SetGeoTransform(GeoTransform);
AccumDS->SetProjection(SR_Text);
AccumData = (unsigned __int32*) malloc(MaxLasRasterSize * 4); // sizeof(__int32) = 4 ALWAYS!!!
AccumDS->RasterIO(GDALRWFlag::GF_Write,ColOff,RowOff,BlockCols,BlockRows,AccumData,BlockCols,BlockRows,GDALDataType::GDT_UInt32,1,NULL,0,0,0);
GDALClose((GDALDatasetH)AccumDS); // very important to close the dataset
This code is missing about 500 lines between creating the memory (AccumData) and writing it - but that's not important in this context. Just remember that you need to address in Col,Row from this current block when modifying values in the memory and you should be fine.
When you download GDAL be sure to download the source, in the tools folder there are some spectacular examples of how to use GDAL that I used as a learning aid, you should find some value in them too.
In Visual Studio (this example from 2010) you need to set some properties in your project:
To ensure that the compiler/linker can find the inputs that it needs.
Best Answer
Yes.
Assuming you're using Python for your plugin, this should cover most things for raster-based processing.
If your plugin needs to handle vector data, add in
If you've done a 'normal' install you should at least have GDAL, and so should your plugin users. This might not be the case for people using older versions of QGIS.
QGIS uses GDAL itself.
An example is the GDAL Tools Plugin. This is a python wrapper around the GDAL functionality (such as Contours, Sieve, Near-Black and so on). It also has the ui files that define the dialog boxes for changing the settings. A lot of the Raster menu is implemented this way.
I think this was originally a stand-alone plugin (in earlier versions) but was brought into core QGIS.
You can see the code in Github . I'm not sure if it uses GDAL directly, or indirectly (as a wrapper the command line)
This file shows an example of how to test for the libraries