Le vendredi 27 février 2015 12:28:01, Dusted a écrit : > I'm getting corrupt output when writing a GeoTiff using GDAL API (v1.10 - > C++). The raster geotransform is correct, the block is written in the > correct position but the pixels are written at random positions and values > within the block. > > Example: http://i.imgur.com/mntnAfK.png <http://i.imgur.com/mntnAfK.png> > > Method: Open a GDAL Raster --> copy projection info & size --> create > output GeoTiff --> write a block from array at offset. > > Code: > > //Open the input DEM > const char* demFName = "/Users/mount.dem"; > const char* outFName = "/Users/geodata/out_test.tif"; > auto poDataset = ioUtils::openDem(demFName); > double adfGeoTransform[6]; > poDataset->GetGeoTransform( adfGeoTransform ); > > //Setup driver > const char *pszFormat = "GTiff"; > GDALDriver *poDriver; > poDriver = GetGDALDriverManager()->GetDriverByName(pszFormat); > char *pszSRS_WKT = NULL; > GDALRasterBand *poBand; > //Get size from input Raster > int xSize = poDataset->GetRasterXSize(); > int ySize = poDataset->GetRasterYSize(); > > //Set output Dataset > GDALDataset *poDstDS; > char **papszOptions = NULL; > > //Create output geotiff > poDstDS = poDriver->Create( outFName, xSize, ySize, 1, GDT_Byte, > papszOptions ); > > //Get the geotrans from the input geotrans > poDataset->GetGeoTransform( adfGeoTransform ); > poDstDS->SetGeoTransform( adfGeoTransform ); > poDstDS->SetProjection( poDataset->GetProjectionRef() ); > > //Create some data to write > unsigned char rData[512*512]; > //Assign some values other than 0 > for (int col=0; col < 512; col++){ > for (int row=0; row < 512; row++){ > rData[col*row] = 50;
==> rData[row*512+col] = 50 And for efficiency with the CPU caches, you should switch the order of the for loops. > } > } > > //Write some data > poBand = poDstDS->GetRasterBand(1); > poBand->RasterIO( GF_Write, 200, 200, 512, 512, > rData, 512, 512, GDT_Byte, 0, 0 ); > > //Close > GDALClose( (GDALDatasetH) poDstDS ); > std::cout << "Done" << std::endl; > > > Any pointers / help much appreciated! > > Chris > > > > -- > View this message in context: > http://osgeo-org.1560.x6.nabble.com/GDAL-GeoTiff-Corrupt-on-Write-C-tp5190 > 440.html Sent from the GDAL - Dev mailing list archive at Nabble.com. > _______________________________________________ > gdal-dev mailing list > [email protected] > http://lists.osgeo.org/mailman/listinfo/gdal-dev -- Spatialys - Geospatial professional services http://www.spatialys.com _______________________________________________ gdal-dev mailing list [email protected] http://lists.osgeo.org/mailman/listinfo/gdal-dev
