Since I couldn’t find it on the internet, I decided to post it here.
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.DataSourcesRaster;
string dtedFile = @"C:\Examples\DTED Level 2\E35\N82.DT2";
IWorkspaceFactory workspaceFactoryShape = new RasterWorkspaceFactoryClass();
IRasterWorkspace rasterWorkspace = (IRasterWorkspace)workspaceFactoryShape.OpenFromFile(System.IO.Path.GetDirectoryName(dtedFile), 0);
IRasterDataset ds = rasterWorkspace.OpenRasterDataset(System.IO.Path.GetFileName(dtedFile));
IRaster raster = ds.CreateDefaultRaster();
A few things to point out:
- The OpenFromFile method is only looking for the directory and not actually the file name. It has to open a workspace before it opens the file.
- The OpenRasterDataset method is where you give just the file name of the dted file. Remember it already has the file path I stated in the first point.
This code took me almost a full day to figure out. Its not easily findable on the internet. Hope it helps someone else out there.
Scott
If you liked this post, please be sure to subscribe to my
RSS Feed.