Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

We have several TIFF images (already tagged with position information) we want to load as a single layer into the map. It's the first time I dig into this raster/topology thing, but at least I managed to create a layer with one image as an IRasterDataset:

Type factoryType = Type.GetTypeFromProgID("esriDataSourcesRaster.RasterWorkspaceFactory");
IWorkspaceFactory wsFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
IRasterWorkspace2 rasterWS = (IRasterWorkspace2)wsFactory.OpenFromFile(@"c:\sourcefiles\");
IRasterDataset rds = rasterWS.OpenRasterDataset(@"example.tif");    
IRasterLayer rasterLayer = new RasterLayerClass();

This works well but I need to add all TIFF files to this raster layer. So I assume that IRasterCatalog could suit my needs. But my attempt to use it fails already on creation of the catalog object (taken from sample):

Geoprocessor geoProcessor = new Geoprocessor();    
CreateRasterCatalog createRasterCatalog = new ESRI.ArcGIS.DataManagementTools.CreateRasterCatalog();

//Set parameters
createRasterCatalog.out_path = outPath;
createRasterCatalog.out_name = catalogName;
createRasterCatalog.raster_spatial_reference = map.SpatialReference;
createRasterCatalog.spatial_reference = = map.SpatialReference;    

//Execute the tool to create a raster catalog
geoProcessor.Execute(createRasterCatalog, null);

On Exceute() I get a COMException, which isn't very helpfull. I tried to set the SpatialReference to IGPCoordinateSystem objects. I made sure that the output path exists. Still the COMException raises. Has anyone a clue for me?

Is this the right approach at all?

share|improve this question
up vote 1 down vote accepted

I found a solution to this:

Type factoryType = ype.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
IWorkspaceFactory mdWorkspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);
IWorkspaceName wsName = mdWorkspaceFactory.Create(@"C:\temp\rastercat_test", "rastercat_test.gdb", null, 0);

IName name = (IName)wsName;
IWorkspace mdWorkspace = (IWorkspace)name.Open();   
IRasterWorkspaceEx workspaceEx = (IRasterWorkspaceEx)(mdWorkspace);

IFields fields = CreateRasterCatalogFields(map.SpatialReference);
IRasterCatalog catalog = workspaceEx.CreateRasterCatalog("TestRC", fields, "Shape", "Raster", "");

Then you can create RasterDatasets for every TIFF file and add them to the RasterCatalog:

IDataset dataset = (IDataset)featureClass;
IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)dataset.Workspace;
IFeature feature = featureClass.CreateFeature();

//Find raster field index.
int iRasterField = feature.Fields.FindField("Raster");

//Create raster value with input raster dataset.
IRasterValue rasterValue = new RasterValueClass();
rasterValue.RasterDataset = rasterDataset;

//Set raster value to the raster field.
feature.set_Value(iRasterField, rasterValue);

//Stop editing and save edits.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.