I'm trying to transfer a subset (box (0,0)-(300,300)) of a panchromatic geotiff to a new file.Although the georeference and the set are transferring correctly, the raster values seem off.
Loading the raster files in qGIS give me at the original .tif values 7614-15959 and at the resulting .tif 0-14530.
Just to clarify: I have no other problems (with projection, georeference or the crop result's borders).
(datasets are GDALDataset and bands are GDALRasterBand)
/*GET PANCHROMATIC BAND*/ band_pan = dataset_pan->GetRasterBand(1);/*GET IMAGE/BAND DATATYPE*/ bufDataType=band_pan->GetRasterDataType();/*CREATE NEW IMAGE WITH SAME DATATYPE*/ char **cropOptions = NULL; dataset_crop = poDriver->Create(fname_crop,512,512,1,bufDataType,cropOptions);/*TRANSFER GEOREFERENCE INFO*/ double adfGeoTransform[6]; dataset_pan->GetGeoTransform( adfGeoTransform ) dataset_crop->SetGeoTransform(adfGeoTransform); dataset_crop->SetProjection( dataset_pan->GetProjectionRef() )/*READ IMAGE SUBSET*/ band_pan->RasterIO(GF_Read,0,0,300,300,buffer,bufsizeX,bufsizeY,bufDataType,0,0);/*GET NEW IMAGE'S BAND*/ band_out = dataset_crop->GetRasterBand(1);/*WRITE SUBSET ON NEW IMAGE*/ band_out->RasterIO(GF_Write,0,0,300,300,buffer,bufsizeX,bufsizeY,bufDataType,0,0);
Am I missing something?
Thanks!
أكثر...
Loading the raster files in qGIS give me at the original .tif values 7614-15959 and at the resulting .tif 0-14530.
Just to clarify: I have no other problems (with projection, georeference or the crop result's borders).
(datasets are GDALDataset and bands are GDALRasterBand)
/*GET PANCHROMATIC BAND*/ band_pan = dataset_pan->GetRasterBand(1);/*GET IMAGE/BAND DATATYPE*/ bufDataType=band_pan->GetRasterDataType();/*CREATE NEW IMAGE WITH SAME DATATYPE*/ char **cropOptions = NULL; dataset_crop = poDriver->Create(fname_crop,512,512,1,bufDataType,cropOptions);/*TRANSFER GEOREFERENCE INFO*/ double adfGeoTransform[6]; dataset_pan->GetGeoTransform( adfGeoTransform ) dataset_crop->SetGeoTransform(adfGeoTransform); dataset_crop->SetProjection( dataset_pan->GetProjectionRef() )/*READ IMAGE SUBSET*/ band_pan->RasterIO(GF_Read,0,0,300,300,buffer,bufsizeX,bufsizeY,bufDataType,0,0);/*GET NEW IMAGE'S BAND*/ band_out = dataset_crop->GetRasterBand(1);/*WRITE SUBSET ON NEW IMAGE*/ band_out->RasterIO(GF_Write,0,0,300,300,buffer,bufsizeX,bufsizeY,bufDataType,0,0);
Am I missing something?
Thanks!
أكثر...