[Gdal-dev] Problems when warping II.
Juan Cicuendez
mruiz at gmv.es
Thu Jul 29 03:43:05 EDT 2004
Thanks for your help Frank,
Sorry for re-posting this as a new message but I had problems with the
followup option.
I had problems to generate a GeoTiff visible from ERDAS (however is visible
from ENVI) after warping a file, as I mentioned I think it is a problem of
the interleave. Frank suggested to create the GeoTiff with the option
INTERLEAVE=PIXEL, then since I could not find the documentation about the
GeoTiff driver I tested:
char *pszOptions = "INTERLEAVE=PIXEL";
hDstDS = GDALCreate( hDriver, outputfilename, nPixels, nLines, bands, eDT,
&pszOptions );
but it does not work. How can I set this option?, is the documentation of
the GeoTiff driver available anywhere?
Thanks a lot,
Juan
I also put up the code:
CPLErr change_projection(char *filename, char *outputfilename, char
*pszDstWKT)
{
GDALDriverH hDriver;
GDALDataType eDT;
GDALDatasetH hDstDS;
GDALDatasetH hSrcDS;
// Open the source file.
hSrcDS = GDALOpen( filename, GA_ReadOnly );
CPLAssert( hSrcDS != NULL );
// Create output with same datatype as first input band.
eDT = GDALGetRasterDataType(GDALGetRasterBand(hSrcDS,1));
// Get output driver (GeoTIFF format)
hDriver = GDALGetDriverByName( "GTiff" );
CPLAssert( hDriver != NULL );
// Get Source coordinate system.
char *pszSrcWKT = NULL;
pszSrcWKT = (char *) GDALGetProjectionRef( hSrcDS );
CPLAssert( pszSrcWKT != NULL && strlen(pszSrcWKT) > 0 );
// Create a transformer that maps from source pixel/line coordinates
// to destination georeferenced coordinates (not destination
// pixel line). We do that by omitting the destination dataset
// handle (setting it to NULL).
void *hTransformArg;
hTransformArg =
GDALCreateGenImgProjTransformer( hSrcDS, pszSrcWKT, NULL, pszDstWKT,
FALSE, 0.0, 1 );
CPLAssert( hTransformArg != NULL );
// Get approximate output georeferenced bounds and resolution for file.
double adfDstGeoTransform[6];
int nPixels=0, nLines=0;
CPLErr eErr;
eErr = GDALSuggestedWarpOutput( hSrcDS, GDALGenImgProjTransform,
hTransformArg,
adfDstGeoTransform,
&nPixels, &nLines );
CPLAssert( eErr == CE_None );
// Create the output file.
int bands = GDALGetRasterCount(hSrcDS);
char *pszOptions = "INTERLEAVE=PIXEL";
hDstDS = GDALCreate( hDriver, outputfilename, nPixels, nLines, bands,
eDT, &pszOptions );
CPLAssert( hDstDS != NULL );
// Write out the projection definition.
GDALSetProjection( hDstDS, pszDstWKT );
GDALSetGeoTransform( hDstDS, adfDstGeoTransform );
// Copy the color table, if required.
GDALColorTableH hCT;
hCT = GDALGetRasterColorTable( GDALGetRasterBand(hSrcDS,1) );
if( hCT != NULL )
GDALSetRasterColorTable( GDALGetRasterBand(hDstDS,1), hCT );
GDALClose( hDstDS );
hDstDS = (GDALDataset *) GDALOpen( outputfilename, GA_Update );
// Setup warp options.
GDALWarpOptions *psWarpOptions = GDALCreateWarpOptions();
psWarpOptions->hSrcDS = hSrcDS;
psWarpOptions->hDstDS = hDstDS;
psWarpOptions->nBandCount = 0;
psWarpOptions->pfnProgress = GDALTermProgress;
// Establish reprojection transformer.
psWarpOptions->pTransformerArg =
GDALCreateGenImgProjTransformer( hSrcDS,
pszSrcWKT,
hDstDS,
pszDstWKT,
FALSE, 0.0, 1 );
psWarpOptions->pfnTransformer = GDALGenImgProjTransform;
// Initialize and execute the warp operation.
GDALWarpOperation oOperation;
oOperation.Initialize( psWarpOptions );
oOperation.ChunkAndWarpImage( 0, 0,
GDALGetRasterXSize( hDstDS ),
GDALGetRasterYSize( hDstDS ) );
GDALDestroyGenImgProjTransformer( psWarpOptions->pTransformerArg );
GDALDestroyWarpOptions( psWarpOptions );
GDALClose( hDstDS );
GDALClose( hSrcDS );
return eErr;
}
More information about the Gdal-dev
mailing list