Hi Robert, if you use opencv there is an easy way to pass buffer from RasterIO to a cv::Mat
double *padRasterData = (double*)CPLMalloc(iGridsizeX*iGridsizeY*sizeof(double)); h_dataset->RasterIO(GF_Read, 0, 0, iGridsizeX, iGridsizeY, padRasterData, iGridsizeX, iGridsizeY, GDT_Float64, 1,NULL,0,0,0); cv::Mat img = cv::Mat(iGridsizeY, iGridsizeX, CV_64F, &padRasterData[0]); ... CPLFree( padRasterData ); cheers, peb On Tue, Jun 17, 2014 at 8:56 PM, Robert Grah <[email protected]> wrote: > Hallo, > > i think this question is somehow a bit stupid but I have to ask it anyway > because i can not find a good working solution. > I try to read the whole elevation data from a band of a GeoTiff image into > a c++ 2d vector so that I can read the values like vector[x][y]. > I also like to convert the data to an image and perform other operations. > > I tried it like this, but this gives me the data in a strange order: > > poBand->RasterIO( GF_Read, 0, 0, nXSize, nYSize, > pafScanline2, nXSize, nYSize, GDT_Float32, > 0, 0 ); > int totalCount = 0; > for (int i = 0; i GetXSize(); i++){ > > vector yVal; > for (int j = 0; j GetYSize(); j++){ > yVal.push_back(pafScanline2[totalCount]); > totalCount++; > } > altData.push_back(yVal); > } > > > I also tried to read every single value step by step, but this was really > slow. > Is there an easy way to get the values ordered like the pixels of an image? > From left to right and top to bottom? I think i am overlooking something... > > Cheers, > Robert > > _______________________________________________ > gdal-dev mailing list > [email protected] > http://lists.osgeo.org/mailman/listinfo/gdal-dev >
_______________________________________________ gdal-dev mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/gdal-dev
