protected void CreatMXD()
{
//获得服务器上下文
IGISServerConnection gisServerConnection = new GISServerConnection();
gisServerConnection.Connect("fms");
IServerObjectManager4 serverObjectManager = (IServerObjectManager4)gisServerConnection.ServerObjectManager;
IServerContext serverContext = serverObjectManager.CreateServerContext("", "");
ESRI.ArcGIS.Geodatabase.IWorkspaceFactory wf = serverContext.CreateObject("esriDataSourcesGDB.AccessWorkspaceFactory") as IWorkspaceFactory;
string fileName = @"F:\data\MyGeodatabase.mdb";
IFeatureWorkspace fws = wf.OpenFromFile(fileName,0) as IFeatureWorkspace;
//打开要素数据集
IFeatureDataset pFeatureDataset = fws.OpenFeatureDataset("MyDataset");
IEnumDataset enumDataset = pFeatureDataset.Subsets;
IDataset dataset = enumDataset.Next();
//创建地图对象
IMap pMap = serverContext.CreateObject("esriCarto.Map") as IMap;
int featureClassCount =0;
//遍历每个数据集,检查其是否要素类
try
{
while (dataset != null)
{
if (dataset.Type == esriDatasetType.esriDTFeatureClass)
{
IFeatureClass pFeatureClass = dataset as IFeatureClass;
IFeatureLayer pFeatureLayer = serverContext.CreateObject("esriCarto.FeatureLayer") as IFeatureLayer;
pFeatureLayer.FeatureClass = pFeatureClass;
ILayer layer = pFeatureLayer as ILayer;
layer.Name = pFeatureClass.AliasName;
pMap.AddLayer(layer);
featureClassCount++;
}
dataset = enumDataset.Next();
}
}
catch (Exception ex)
{
}
//mxd文档的保存地址
string sDocument = @"F:\data\myMXD.mxd";
//创建地图文档对象
IMapDocument pMapDocument = serverContext.CreateObject("esriCarto.MapDocument") as IMapDocument;
pMapDocument.New(sDocument);
pMapDocument.ReplaceContents(pMap as IMxdContents);
pMapDocument.Save(true, false);
//释放服务器上下文
serverContext.ReleaseContext();
}