ArcEngine打开数据源(FeatureClass)
1、打开GDB
FileGDBWorkspaceFactory fileGDBWorkspaceFactory = new FileGDBWorkspaceFactory();
IWorkspace workspace = fileGDBWorkspaceFactory.OpenFromFile(“GDB路径”, 0);
IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace;
IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(“GDB中要素类名字”);
2、打开mdb
AccessWorkspaceFactory accessWorkspaceFactory = new AccessWorkspaceFactoryClass();
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)accessWorkspaceFactory.OpenFromFile(“MDB路径”, 0);
IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(“MDB中要素类名字”);
3、打开shapefile
IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass();
IWorkspace workspace = workspaceFactory.OpenFromFile(“shp路径”, 0);
IFeatureWorkspace featureWorkspace = workspace as IFeatureWorkspace;
IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(“shp名字”);
4打开raster 影像
string rasterPath = System.IO.Path.GetDirectoryName(rasterFulPath);
string rasterFileName = System.IO.Path.GetFileName(rasterFulPath);
IWorkspaceFactory rasterWorkspaceFactory = new RasterWorkspaceFactoryClass();
IRasterWorkspace rasterWorkspace = (IRasterWorkspace)rasterWorkspaceFactory.OpenFromFile(rasterPath, 0);
IRasterDataset rasterDataset = rasterWorkspace.OpenRasterDataset(rasterFileName);
IRasterLayer rasterLayer = new RasterLayerClass();
rasterLayer.CreateFromDataset(rasterDataset);
//影像去黑边
IRasterRGBRenderer2 rasterRGBRen = new RasterRGBRendererClass();
IRasterStretchColorRampRenderer pRasterStretchRenderer = new RasterStretchColorRampRendererClass();
if (rasterLayer.Renderer is IRasterRGBRenderer2)
{
IRasterRenderer pRasterRendererRGB = (IRasterRenderer)rasterRGBRen;
IRasterStretch2 rasterStretchType = (IRasterStretch2)rasterRGBRen;
rasterStretchType.Background = true;
rasterStretchType.BackgroundValue = 0;
pRasterRendererRGB = (IRasterRenderer)rasterRGBRen;
pRasterRendererRGB.Update();
IRasterProps pRstProps = rasterLayer.Raster as IRasterProps;
pRstProps.NoDataValue = 0;
rasterLayer.Renderer = pRasterRendererRGB;
}
else if (rasterLayer.Renderer is IRasterStretchColorRampRenderer)
{
IRasterRenderer pRasterRendererStretch = (IRasterRenderer)pRasterStretchRenderer;
IRasterStretch2 rasterStretchType = (IRasterStretch2)pRasterStretchRenderer;
rasterStretchType.Background = true;
rasterStretchType.BackgroundValue = 0;
pRasterRendererStretch = (IRasterRenderer)pRasterStretchRenderer;
pRasterRendererStretch.Update();
IRasterProps pRstProps = rasterLayer.Raster as IRasterProps;
pRstProps.NoDataValue = 0;
rasterLayer.Renderer = pRasterRendererStretch;
}
注:对workspace验证是否存在
if (fileGDBWorkspaceFactory.IsWorkspace(GDBPath) == false)
{
msg = “GDB文件不正确,不能打开!”;
return msg;
}
转自:http://blog.csdn.net/hellolib/article/details/7861806
转载自:https://blog.csdn.net/u013751758/article/details/73199982