Opened 20 years ago
Last modified 20 years ago
#620 closed defect (fixed)
why GTiff cann't write the geo. information.
Reported by: | Owned by: | warmerdam | |
---|---|---|---|
Priority: | high | Milestone: | |
Component: | GDAL_Raster | Version: | unspecified |
Severity: | normal | Keywords: | |
Cc: |
Description
I use gdal1.2.3 to duplicate geo. information for geotiff format,but it failed (successed with HFA with the same program).And,the data of HFA file is upside down. if( (strGeoRef = pSrcDataset->GetProjectionRef()) != NULL && strlen(strGeoRef) >0 ) { oErr = oSRS.SetProjection(strGeoRef); oErr = pDstDataset->SetProjection( strGeoRef ); if( oErr == CE_Failure ) rv = 5; tGeo = pDstDataset->GetProjectionRef(); }
Change History (4)
comment:3 by , 20 years ago
I have tried the simplest code as following,and the input data is the sample "utm.tif",also,the geographical information cann't be written to the output file(the image data can) ,and the SetProjection return success (actually,the variable in geotiff.c is duplicate correctly),but the information doesn't write into the file! I don't know the reason. #include "gdal_priv.h" #include "gdal.h" #include "cpl_string.h" #include "ogr_spatialref.h" int main() { GDALDataset *poSrcDataset,*poDstDataset; GDALRasterBand *poSrcBand,*poDstBand; int BandNumber = 0,nXSize,nYSize; float *pafScanline; char *pszSrcFilename = "e:\\utm.tif"; char *pszDstFilename = "e:\\utm_copy.tif"; GDALAllRegister(); poSrcDataset = (GDALDataset *) GDALOpen( pszSrcFilename, GA_ReadOnly ); if( poSrcDataset == NULL ) return 0; const char *pszFormat = "GTiff"; GDALDriver *poDriver = (GDALDriver *)GDALGetDriverByName(pszFormat); if( poDriver == NULL ) return 0; poSrcBand = poSrcDataset->GetRasterBand( 1 ); nXSize = poSrcBand->GetXSize(); nYSize = poSrcBand->GetYSize(); poDstDataset = poDriver->Create( pszDstFilename, nXSize, nYSize, 1, GDT_Byte,NULL ); poDstBand = poDstDataset->GetRasterBand( 1 ); pafScanline = (float *) CPLMalloc(sizeof(float)*nXSize); for( int RowLoop = 0; RowLoop<nYSize; RowLoop++ ) { poSrcBand->RasterIO( GF_Read,0,RowLoop,nXSize,1,pafScanline,nXSize,1,GDT_Float32,0,0); poDstBand->RasterIO( GF_Write,0,RowLoop,nXSize,1,pafScanline,nXSize,1,GDT_Float32,0,0); } const char *strGeoRef = NULL; if( (strGeoRef = poSrcDataset->GetProjectionRef()) != NULL && strlen (strGeoRef)>0 ) poDstDataset->SetProjection( strGeoRef ); CPLFree(pafScanline); GDALClose(poSrcDataset); GDALClose(poDstDataset); CPLFree(pszSrcFilename); CPLFree(pszDstFilename); return 1; }
comment:4 by , 20 years ago
Wujun, I have confirmed the problem you report, and determined that the projection isn't getting written because there is no geotransform or GCPs on the target file. The GeoTIFF driver had a quirk where it would not write the projection definition if there wasn't also going to be valid georeferencing tags. I have removed this restriction in CVS, but what you really want to do is also copy over the geotransform. Try adding a line like: double adfGeoTransform[6]; if( poSrcDataset->GetGeoTransform( adfGeoTransform ) == CE_None ) poDstDataset->SetGeoTransform( adfGeoTransform ); Best regards,
Note:
See TracTickets
for help on using tickets.