I'm using C++ (QtCreator) QGIS 2.0 und openCV2 on an 64 bit Workstation running Debian Wheezy. The Application I try to assemble is a standalone QGIS one and will be a mix of gis and image processing software.
Problem description:
I've a QgsMapLayerCanvas with an associated QgsRasterlayer based on an GeoTiff with UTM32 CRS and a resolution of 2 cm. My objective ist to point on an location, determin the pixel data and cut out the data buffer in a 2 x 2 meter window . In the next step this buffer should go to an opencv image processing routine. I' havent found a ready to use solution in the qgis library.
My guess is, that the QgsRasterDataProvider can do this job but. But I cannot find any useful snippets in the web for this task.
Is there somebody who has experience with this matter?
Here the snippet of my first try:
void MainWindow::doMapImgCanvasClicked(const QgsPoint &point,
Qt::MouseButton button) {
if (!(qgsMapImgLayer && qgsMapImgProvider) ) return;
// Size of the window for the image process
int winWidth = 10; int winHeight = 10;
// Calculate the pixel position
QPoint pixPos(-1,-1);
doMapImgCalcRasterPos(point, qgsMapImgLayer, pixPos);
// Give me a response for coords and pixel pos
QString str;
str.sprintf("COORD %f %f PIX %d %d",
point.x(), point.y(),
pixPos.x(), pixPos.y());
outLog(str);
// Create a region of interest
QgsRectangle roi(point.x()-1, point.y()-1, point.x()+1, point.y()+1);
// Make a copy of Data 2x2 m for the first band
QgsRasterBlock *block = qgsMapImgProvider->block(
1, roi, winWidth, winHeight);
// Block data is OK?
if (block->isValid()) {
outLog("VALID");
}
// Blockdata empty?
if (block->isEmpty()) {
outLog("EMPTY");
} else {
return;
}
// Is this the buffer?
char* bits = block->bits();
str.sprintf("DB.TYPE %d", block->dataType()); outLog(str);
// OK This is the size of the Pointer
str.sprintf("DB.NUM %d", sizeof(bits) ); outLog(str);
// Test Output
for (int i=0; i<winWidth*winHeight; i++) {
char c = bits[i];
str.sprintf("PIX[%d]=%d", i, bits[i] ); outLog(str);
}
}