Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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();
rasterLayer.CreateFromDataset(rds);
_map.AddLayer(rasterLayer);

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

1 Answer 1

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;
workspaceEdit.StartEditing(false);
workspaceEdit.StartEditOperation();
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);
feature.Store();

//Stop editing and save edits.
workspaceEdit.StopEditOperation();
workspaceEdit.StopEditing(true);
share|improve this answer

Your Answer

 
discard

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.