ArcGIS Engine 10 开发手册(11-8)用代码来创建几何网络

本文目录
  • 正文

使用代码也可以创建几何网络。

示例代码

/// <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 开发手册

如果本文对你有所帮助,欢迎对我们团队进行打赏捐助,让我们在传播3S的路上可以走得更远。
赞赏支持
微信捐助麻辣GIS 支付宝捐助麻辣GIS

麻辣GIS-Sailor
作者:
GIS爱好者,学GIS,更爱玩GIS。

如您有疑问,可在文末留言,或到QQ群提问。

本站QQ群(一):291616564 麻辣GIS

本站QQ群(二):166408035 麻辣GIS(二)

微信公众号:malagis,扫描右边二维码直接关注。

发表评论