AoInitialize aoi = new AoInitializeClass(); //也可以设置其他许可类型
esriLicenseProductCode productCode =esriLicenseProductCode.esriLicenseProductCodeEngine;
if (aoi.IsProductCodeAvailable(productCode) ==esriLicenseStatus.esriLicenseAvailable)
{
aoi.Initialize(productCode);
}
ESRI.ArcGIS.esriSystem.IAoInitialize m_AoInitialize = newESRI.ArcGIS.esriSystem.AoInitialize();
m_AoInitialize.Initialize(ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeArcInfo);
IPropertySet pProSet = new PropertySetClass();
IWorkspaceFactory pWorkSpFac = newSdeWorkspaceFactoryClass();
IFeatureWorkspace pFeaWorkSp = null;
IFeatureClass FeaCls = null;
pProSet = sdeconn.SdeConn();
if (pProSet != null)
{
pFeaWorkSp = (IFeatureWorkspace)(pWorkSpFac.Open(pProSet,0));//打开要素空间
FeaCls = pFeaWorkSp.OpenFeatureClass(feaName);//取得要素集
}
转换ILayer
IFeatureLayer featureLyr =new FeatureLayerClass();
featurelyr.FeatureClass=FeaCls ;
public static IMapControlDefault m_pMapCtrl = newMapControlClass();
m_pMapCtrl.AddLayer(featurelyr as ILayer,0);
保存文件
IMxdContents pMxdC; pMxdC = axMapControl1.Map as IMxdContents;
IMapDocument pMapDocument = new MapDocumentClass ();
pMapDocument.New ("@d:aa3.mxd");
IActiveView pActiveView = axMapControl1.Map as IActiveView;
pMapDocument.ReplaceContents (pMxdC);
pMapDocument.Save (true,true);
_______________________________________________________________________
int imgindex = filepath.LastIndexOf('\');
string imgpath = filepath.Substring(0, imgindex);
string imgname = filepath.Substring(imgindex + 1);
IWorkspaceFactory workspaceFactory = newRasterWorkspaceFactoryClass();
IRasterWorkspace rasterWorkspace =(IRasterWorkspace)(workspaceFactory.OpenFromFile(imgpath,0));
IRasterDataset rasterDataset =rasterWorkspace.OpenRasterDataset(imgname);
// Create a raster for viewing
ESRI.ArcGIS.Carto.IRasterLayer rasterLayer = newESRI.ArcGIS.Carto.RasterLayerClass();
rasterLayer.CreateFromDataset(rasterDataset);
IMapControlDefault m_pMapCtrl = new MapControlClass();
m_pMapCtrl.AddLayer(rasterLayer as ILayer,0);
//保存mxd文件
IMxdContents pMxdC = (IMxdContents)m_pMapCtrl.Map;
IMapDocument pMapDocument = new MapDocumentClass();
pMapDocument.New(@"d:temp.mxd");
IActiveView pActiveView = m_pMapCtrl.Map as IActiveView;
pMapDocument.ReplaceContents(pMxdC);
pMapDocument.Save(true, true);