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
// 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);
r.AlterSpatialReference(pSpatialReference);
Hi Bill, were you able to resolve your issue? We have similar 9.3 code that is throwing an AccessViolationException in 10.2.2. So I was wondering if you were able to find a fix for 10.x Thank you!