Select to view content in your preferred language

Reprojection while loading Rasters

923
1
09-10-2010 06:16 AM
ChrisBarrington_Brown
Emerging Contributor
I'm loading rasters into a file geodatabase in Engine code.  Some of them need reprojecting so I'm trying the following code:

// I have an IRaster pointed to by pRaster and a required ISpatialReference pointed to by pSpatialRef

VARIANT vMissing;
vMissing.vt = VT_ERROR;
vMissing.scode = DISP_E_PARAMNOTFOUND;

// Create a RasterTransformionOp to do the re-projection
CComPtr<ITransformationOp> pTransform;
hr = pTransform.CoCreateInstance(CLSID_RasterTransformationOp);

// get the IGeoDataset of the original Raster
CComPtr<IGeoDataset> pInGeoDataset;
hr = pRaster.QueryInterface(&pInGeoDataset);

// Project it into the new Spatial Reference
CComPtr<IGeoDataset> pOutGeoDataset;
hr = pTransform->ProjectFast(pInGeoDataset, pSpatialRef, esriGeoAnalysisResampleCubic, &vMissing, &pOutGeoDataset);
       
// Get the resulting RasterDataset
CComPtr<IRasterDataset> pReprojRasterDataset;
hr = pOutGeoDataset.QueryInterface(&pReprojRasterDataset);

// Get the reprojected raster from the new dataset
CComPtr<IRaster> pReprojRaster;
hr = pReprojRasterDataset->CreateDefaultRaster(&pReprojRaster);

// Load it into the existing File Geodatabase
hr = pRasterLoader->Load(pRasterDataset, pReprojRaster);


However, the resultant raster isn't reprojected.  Any clues as to what I am mis-understanding?

Chris
0 Kudos
1 Reply
RobertBerger
Occasional Contributor
Hi Chris,

Did you see the code snippet online: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/conceptualhelp/index.html#/How_to_project_a_raster...
It talks about reprojecting a raster. The saveas call in the end just needs to go to your geodatabase rather than file system. I think that should do it.

Robert
0 Kudos