BillHoney

Altering the SpatialReference of a file-based raster

Discussion created by BillHoney on Jan 24, 2014
Latest reply on Aug 1, 2014 by miguel.sevilla
Hi,

I am upgrading a 9.2 Arcobjects console application to 10.2 and I am having some problems with changing the spatialReference of rasters.

My application looks at a TIFF file (plain TIFF) , plus an associated .TFW & .PRJ file.
In the 9.3 version of the application, it made changes to the header tags of the .TIF file,  writing the spatial reference directly into the TIFF

In my upgraded 10.2 application, this part no longer works - the TIFF does not get altered & ArcMap still thinks the TIFF has unknown spatial references, and I can't figure out why. 

Can anyone Help?

Bill

Version 10.2 code.
            
            string pathName = Directory.GetCurrentDirectory(); 

            ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Engine);
            
            //// Force ESRI to pick up the new Spatial reference from the .prj file 
            ISpatialReferenceFactory pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass();
            ISpatialReference pSpatialReference = pSpatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile(prjFileName);

            // open the directory as a worekspace 
            Type factoryType = Type.GetTypeFromProgID("esriDataSourcesRaster.RasterWorkspaceFactory");
            IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
            IWorkspace workspace = workspaceFactory.OpenFromFile(pathName, 0);
            IRasterWorkspace rasterWorkspace = (IRasterWorkspace)workspace;

            // open the raster file 
            IRasterDataset r = (IRasterDataset)rasterWorkspace.OpenRasterDataset(tifFileName);
            r.BasicOpenFromFile(tifFileName); // not sure if this line is needed 
            IGeoDataset igs = r as IGeoDataset; 
            IGeoDatasetSchemaEdit2 gds = r as IGeoDatasetSchemaEdit2;

            gds.AlterSpatialReference( pSpatialReference) ;
            igs.SpatialReference.Changed(); // tell it that we have changed the rasters's spatial reference 


Original 9.2 Code (which no longer compiles under 10.2


 // Force ESRI to pick up the new Spatial reference 
 ISpatialReferenceFactory  pSpatialReferenceFactory = new SpatialReferenceEnvironmentClass(); 
 ISpatialReference pSpatialReference = pSpatialReferenceFactory.CreateESRISpatialReferenceFromPRJFile(prjFileName);
   
            // Open the Raster & change its SpartialReference  
            RasterDatasetClass r = new RasterDatasetClass(); 
            r.BasicOpenFromFile(tifFileName); 
            r.AlterSpatialReference(pSpatialReference);

Outcomes