Wednesday, February 09, 2005
ArcObjects AlterSpatialReference does not work
ESRI ArcObjects
If you have attempted to use AlterSpatialReference and it does not seem to work then most probably the file is in use.
If you attempted calling it from ArcCatalog, then check to see if the image is not loaded in ArcMap or ArcScene or is being used by some other application.
In code, if you attempt to set the spatial reference then you need to set the GeoDatasetSchemeEdit to null (or nothing in VB).
Here is an example using VC++
IDocumentPtr ipDoc;
ipApp->get_Document(&ipDoc);
IMxDocumentPtr ipMxDoc(ipDoc);
IMapPtr ipMap;
ipMxDoc->get_FocusMap(&ipMap);
ISpatialReferencePtr ipSpatialReference;
ipMap->get_SpatialReference( &ipSpatialReference );
IWorkspaceFactoryPtr ipWorkspaceFactory;
ipWorkspaceFactory.CreateInstance(CLSID_RasterWorkspaceFactory);
IRasterWorkspacePtr ipRWorkspace;
IWorkspacePtr ipWorkspace;
hRes = ipWorkspaceFactory->OpenFromFile(CComBSTR(strResPath), 0, &ipWorkspace);
ipRWorkspace = ipWorkspace;
IRasterDatasetPtr ipRasterDataset;
IRasterPtr ipRaster;
hRes = ipRWorkspace->OpenRasterDataset (CComBSTR(strResFileName), &ipRasterDataset);
VARIANT_BOOL varCanAlter;
if ( (ipSpatialReference != NULL) && (ipRasterDataset != NULL) )
{
((IGeoDatasetSchemaEditPtr)ipRasterDataset)->get_CanAlterSpatialReference(&varCanAlter);
if (varCanAlter == VARIANT_TRUE )
{
((IGeoDatasetSchemaEditPtr)ipRasterDataset)->AlterSpatialReference(ipSpatialReference );
}
}
ipRasterDataset = NULL; //this is important - otherwise Spatial Ref wont be set
//reopen raster dataset
hRes = ipRWorkspace->OpenRasterDataset (CComBSTR(strResFileName), &ipRasterDataset);
//...continue processing the raster
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment