[gdal-dev] How to correct the envisat N1 image with it's GCPs

RSyaoxin RSyaoxin at hotmail.com
Tue Jun 28 07:24:06 EDT 2011


Hi,all.
     I want to correct the envisat N1 image with it's GCPs,this image
haven't geo-referenced information and projection,but it's GCPs have
geo-referenced information.However I can not get correct results,the
corrected image pixels are all zero.Here is my code:

	GDALAllRegister();

	GDALDriverH hDriver;
	GDALDataType eDT;
	GDALDatasetH hDstDS;
	GDALDatasetH hSrcDS;
	

hSrcDS=GDALOpen("D:\\Users\\ASA_IMP_1PNUPA20070408_135835_000000162057_00082_26689_3974.N1",GA_ReadOnly);
	CPLAssert(hSrcDS!=NULL);

	int nGcpCount=GDALGetGCPCount(hSrcDS);
	const GDAL_GCP *pGCPs=GDALGetGCPs(hSrcDS);

	GDALWarpOptions *psWarpOptions = GDALCreateWarpOptions();

psWarpOptions->pTransformerArg=GDALCreateGCPTransformer(nGcpCount,pGCPs,1,0);
	psWarpOptions->pfnTransformer=GDALGCPTransform;
	psWarpOptions->eResampleAlg=GRA_NearestNeighbour;
	psWarpOptions->hSrcDS=hSrcDS;

	psWarpOptions->nBandCount=0;
	psWarpOptions->pfnProgress=GDALTermProgress;
	double adfDstGeoTransform[6];	
	int nPixels=0, nLines=0;
	GDALSuggestedWarpOutput(psWarpOptions->hSrcDS, GDALGCPTransform,		
		psWarpOptions->pTransformerArg, adfDstGeoTransform, &nPixels, &nLines);
	
	hDriver=GDALGetDriverByName("GTiff");
	CPLAssert(hDriver!=NULL);
	eDT=GDALGetRasterDataType(GDALGetRasterBand(hSrcDS,1));

hDstDS=GDALCreate(hDriver,"D:\\Users\\warp.tif",nPixels,nLines,GDALGetRasterCount(hSrcDS),eDT,NULL);
	CPLAssert(hDstDS!=NULL);
	
	psWarpOptions->hDstDS=hDstDS;

	char *pszDstWKT=NULL;
	OGRSpatialReference oSRS;
	oSRS.SetUTM(20,TRUE);
	oSRS.SetWellKnownGeogCS("WGS84");	
	oSRS.exportToWkt(&pszDstWKT);

	GDALSetProjection(hDstDS,pszDstWKT);
	GDALSetGeoTransform(hDstDS,adfDstGeoTransform);
	CPLFree(pszDstWKT);
	
	GDALWarpOperation oOperation;
	oOperation.Initialize(psWarpOptions);
	oOperation.ChunkAndWarpImage(0,0,nPixels,nLines);	
	GDALDestroyGenImgProjTransformer(psWarpOptions->pTransformerArg);
	GDALDestroyWarpOptions(psWarpOptions);

	GDALClose(hDstDS);
	GDALClose(hSrcDS);

That's Why?I turn to Anybody who once did this job for some advice. Thank
you! 
Kind regards.

     

--
View this message in context: http://osgeo-org.1803224.n2.nabble.com/How-to-correct-the-envisat-N1-image-with-it-s-GCPs-tp6524474p6524474.html
Sent from the GDAL - Dev mailing list archive at Nabble.com.


More information about the gdal-dev mailing list