AnsweredAssumed Answered

Error Using Con Statement with Raster in a File Geodatabase

Question asked by geonetadmin on Nov 13, 2010
Original User: Eosdis!!

I'm having a problem using the 'Con' tool with a raster I created using IRasterWorkspaceEx and that is stored in a File Geodatabase. When I try and run a Con statement using this raster I get an "Unexpected error". However, when I use the Con statement on a raster I've generated using IRasterWorkspace2 (i.e. a stand-alone .img format) the tool works fine despite the rasters being identical in content and size/spatial reference.

I believe that it has got something to do with the way the raster is created when working with IRasterWorkspaceEx and maybe I'm not defining something correctly. For a bit I was getting a "Spatial Grid Size" error that went away when I installed SP6 (ArcMap 9.2). Below is the code I've used to create the raster. For all intents and purposes the output raster is fine except that I get this undefined error when trying to use it with the Con statement. I could revert to using the code that output to file system .img raster but wanted the output stored in a geodatabase.

Any advice on what I might be doing wrong in setting up the raster that it is triggering the error with the Con tool would be very appreciated!



//Section of Code from my project that creates a raster in a file geodatabase

                IRasterWorkspaceEx RWS = DataManager.GetRasterWorkspaceEx(outputlocation);               
                string RastName = DataManager.ReturnViableName2((IWorkspace)RWS, "Vector_Grid", esriDatasetType.esriDTAny);

                IRasterStorageDef rasterStorageDef = new RasterStorageDefClass();
                rasterStorageDef.CompressionType =   esriRasterCompressionType.esriRasterCompressionLZ77;
                rasterStorageDef.PyramidResampleType = rstResamplingTypes.RSP_BilinearInterpolation;

                IRasterDef rasterDef = new RasterDefClass();
                rasterDef.Description = "VectorGrid";
                rasterDef.SpatialReference = sr;

                IGeometryDef geomDef = new GeometryDefClass();
                IGeometryDefEdit geomDefEdit = (IGeometryDefEdit)geomDef;
                geomDefEdit.GeometryType_2 = esriGeometryType.esriGeometryPolygon;
                geomDefEdit.AvgNumPoints_2 = 4;
                geomDefEdit.GridCount_2 = 1;
                geomDefEdit.SpatialReference_2 = sr;

IRasterDataset2 rasterDataset = (IRasterDataset2)RWS.CreateRasterDataset(RastName, 1, rstPixelType.PT_DOUBLE, rasterStorageDef,"DEFAULTS", rasterDef, geomDef);

                IRaster newRaster = rasterDataset.CreateFullRaster();

                IRasterProps rasterProps = (IRasterProps)newRaster;
                IEnvelope extent = new EnvelopeClass();
                double rastEnv_XMin = rasterOrigin.X;
                double rastEnv_YMin = rasterOrigin.Y;
                double rastEnv_XMax = rasterOrigin.X + columns * resolution;
                double rastEnv_YMax = rasterOrigin.Y + rows * resolution;

                extent.PutCoords(rastEnv_XMin, rastEnv_YMin, rastEnv_XMax, rastEnv_YMax);

                rasterProps.Extent = extent;
                rasterProps.SpatialReference = sr;
                rasterProps.PixelType = rstPixelType.PT_DOUBLE;
                rasterProps.Height = rows;
                rasterProps.Width = columns;

                IPnt Pnt = new PntClass();
                Pnt.SetCoords(0, 0);

                IPnt RastSize = new PntClass();
                RastSize.SetCoords(columns, rows);

                IPixelBlock3 pixelBlock = (IPixelBlock3)newRaster.CreatePixelBlock(RastSize);

                System.Array pixelData = (System.Array)pixelBlock.get_PixelData(0);