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.

How can I load .SID files in ArcEngine? I think its possible, but I can't find any links.

With Kirk's help I got it here's the code:

  public void add_SID_file(string dir) 
        {
            RasterWorkspaceFactory raster = new RasterWorkspaceFactoryClass();
            IRasterWorkspace rasterWorkspace = raster.OpenFromFile(dir, 0) as IRasterWorkspace;

            if (rasterWorkspace != null)
            {
                IWorkspace w = rasterWorkspace as IWorkspace;
                IEnumDatasetName dsNames = w.get_DatasetNames(esriDatasetType.esriDTRasterDataset);
                IDatasetName datasetName = dsNames.Next();
                List<string> names = new List<string>(); 
                while (datasetName != null)
                {
                    names.Add(datasetName.Name);
                    datasetName = dsNames.Next();
                }
                if (names.Count > 0)
                {
                    IRasterDataset pRasterDataset = rasterWorkspace.OpenRasterDataset(names[0]);
                    IRasterLayer pRasterLayer = new RasterLayerClass();
                    pRasterLayer.CreateFromDataset(pRasterDataset);
                    mapControl.Map.AddLayer(pRasterLayer); 
                }
            }
share|improve this question
    
I've never seen any problems with this approach, but Esri advises to use Activator.CreateInstance instead of "new" for RasterWorkspaceFactory. See documentation here. –  Kirk Kuykendall May 25 '11 at 20:58
add comment

2 Answers

up vote 2 down vote accepted

Probably more than one way to do it, but I've used IRasterWorkspaceFactory.OpenFromFile and passed the folder (NOT the file) as an argument. Then use IRasterWorkspace.OpenRasterDataset. If you forget the naming convention, you can also loop through each raster dataset using the enumerator returned from IWorkspace.Datasets, and list the IDataset.Name. I forget if .sid is part of the name or not.

share|improve this answer
add comment

A less-verbose way of opening a Raster is to use GPUtilities.openRasterDatasetFromString. It's slower than writing the raw ArcObjects like you've done, but it handles a lot more of the edge cases internally.

share|improve this answer
    
+1 yes, probably a lot less verbose! –  Kirk Kuykendall May 26 '11 at 2:56
add comment

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.