ArcGIS Engine 10 开发手册(11-8)用代码来创建几何网络
发布时间: 2018-02-23
所属分类: ArcGIS Engine 10 开发手册
使用代码也可以创建几何网络。
示例代码
/// <summary>
/// 打开个人数据库
/// </summary>
/// <param name="_pGDBName"></param>
/// <returns></returns>
public IWorkspace GetWorkspace (String _pGDBName)
{
IWorkspaceFactory pWsFac = new AccessWorkspaceFactoryClass ();
IWorkspace pWs = pWsFac.OpenFromFile (_pGDBName, 0);
return pWs;
}
public void CreateGeometricNetwork (IWorkspace _pWorkspace, IFeatureDatasetName _pFeatureDatasetName, String _pGeometricName)
{
INetworkLoader2 pNetworkLoader = new NetworkLoaderClass ();
// 网络的名称
pNetworkLoader.NetworkName = _pGeometricName;
// 网络的类型
pNetworkLoader.NetworkType = esriNetworkType.esriNTUtilityNetwork;
// Set the containing feature dataset.
pNetworkLoader.FeatureDatasetName = (IDatasetName) _pFeatureDatasetName;
// 检查要建立几何网络的数据,每一个要素只能参与一个网络
if (pNetworkLoader.CanUseFeatureClass ("PrimaryLine") == esriNetworkLoaderFeatureClassCheck.esriNLFCCValid)
{
pNetworkLoader.AddFeatureClass ("PrimaryLine", esriFeatureType.esriFTComplexEdge, null, false);
}
if (pNetworkLoader.CanUseFeatureClass ("Feeder") == esriNetworkLoaderFeatureClassCheck.esriNLFCCValid)
{
pNetworkLoader.AddFeatureClass ("Feeder", esriFeatureType.esriFTSimpleJunction, null, false);
}
// 我的数据中没有enable字段,所以,用了false,如果用true的话,就要进行相关的设置
INetworkLoaderProps pNetworkLoaderProps = (INetworkLoaderProps) pNetworkLoader;
pNetworkLoader.PreserveEnabledValues = false;
// Set the ancillary role field for the Feeder class.
String defaultAncillaryRoleFieldName = pNetworkLoaderProps.DefaultAncillaryRoleField;
esriNetworkLoaderFieldCheck ancillaryRoleFieldCheck = pNetworkLoader.CheckAncillaryRoleField ("Feeder", defaultAncillaryRoleFieldName);
switch (ancillaryRoleFieldCheck)
{
case esriNetworkLoaderFieldCheck.esriNLFCValid:
case esriNetworkLoaderFieldCheck.esriNLFCNotFound:
pNetworkLoader.PutAncillaryRole ("Feeder", esriNetworkClassAncillaryRole.esriNCARSourceSink, defaultAncillaryRoleFieldName);
break;
default:
Console.WriteLine ("The field {0} could not be used as an ancillary role field.", defaultAncillaryRoleFieldName);
break;
}
pNetworkLoader.SnapTolerance = 0.02;
// 给几何网络添加权重
pNetworkLoader.AddWeight ("Weight", esriWeightType.esriWTDouble, 0);
// 将权重和PrimaryLine数据中的SHAPE_Length字段关联
pNetworkLoader.AddWeightAssociation ("Weight", "PrimaryLine", "SHAPE_Length");
// 构建网络
pNetworkLoader.LoadNetwork ();
}
IWorkspace pWs = GetWorkspace (@"E:\arcgis\Engine\Geometric.mdb");
IFeatureWorkspace pFtWs = pWs as IFeatureWorkspace;
IFeatureDataset pFtDataset = pFtWs.OpenFeatureDataset ("work");
IDataset pDataset = pFtDataset as IDataset;
IFeatureDatasetName pFtDatasetName = pDataset.FullName as IFeatureDatasetName;
CreateGeometricNetwork (pWs, pFtDatasetName, "TestGeometric");
运行结果
有了几何网络,接下来就是在这个几何网络上做分析,几何网络能执行的操作都在ITraceFlowSolverGEN 接口中,该接口的方法如下图:
ArcGIS Engine 10 开发手册全集
ArcGIS Engine 10 开发手册全集: ArcGIS Engine 10 开发手册
相关阅读
声明
1.本文所分享的所有需要用户下载使用的内容(包括但不限于软件、数据、图片)来自于网络或者麻辣GIS粉丝自行分享,版权归该下载资源的合法拥有者所有,如有侵权请第一时间联系本站删除。
2.下载内容仅限个人学习使用,请切勿用作商用等其他用途,否则后果自负。
手机阅读
公众号关注
知识星球
手机阅读
最新GIS干货
私享圈子