获得一个mxd中NetworkDataSet
// 获得一个mxd中NetworkDataSet
private static INetworkDataset GetNetworkDataSet(string mxdFileName)
{
//Open the mxd file and get the network dataset
IMapDocument pMapDocument = new MapDocumentClass();
pMapDocument.Open(mxdFileName, "");
INetworkDataset networkDataset = null;
//iterate all the maps
for (int cMap = 0; cMap < pMapDocument.MapCount; cMap++)
{
for (int cLayer = 0; cLayer < pMapDocument.get_Map(cMap).LayerCount; cLayer++)
{
ILayer pLayer = pMapDocument.get_Map(cMap).get_Layer(cLayer);
//NA Layer
if (pLayer is INALayer)
{
INALayer pNALayer = pLayer as INALayer;
networkDataset = pNALayer.Context.NetworkDataset;
break;
}
//Composite Layer
if (pLayer is IGroupLayer)
{
ICompositeLayer pCompositeLayer = pLayer as ICompositeLayer;
for (int cContainLayer = 0; cContainLayer < pCompositeLayer.Count; cContainLayer++)
{
if (pCompositeLayer.get_Layer(cContainLayer) is INALayer)
{
INALayer pNALayer = pCompositeLayer.get_Layer(cContainLayer) as INALayer;
networkDataset = pNALayer.Context.NetworkDataset;
break;
}
}
}
}
}
//Close the MXD Document
pMapDocument.Close();
////judge get the net work data set or not
if (networkDataset == null)
{
Exception ex = new Exception();
ex.Data.Add(0, "无法打开网络数据集!");
throw ex;
}
return networkDataset;
}