C#+AE 创建几何网络

 几何网络必须存在数据集中,Engine创建的时候要有geodatabase updata 许可,我的数据库是个人数据库。

先看一下ArcMap是怎么创建的
在catalog中打开创建几个网络的向导


几何网络的名称


选中参与网络的要素


是否启用enable字段


数据集的角色



创建权重字段

权重字段和相应的字段关联




结果如下:

  1. ///
  2. /// 打开个人数据库
  3. ///
  4. ///
  5. ///
  6. public IWorkspace GetWorkspace(String _pGDBName)
  7. {
  8. IWorkspaceFactory pWsFac = new AccessWorkspaceFactoryClass();

  9. IWorkspace pWs = pWsFac.OpenFromFile(_pGDBName,0);

  10. return pWs;
  11. }

  12. public void CreateGeometricNetwork(IWorkspace _pWorkspace, IFeatureDatasetName
  13. _pFeatureDatasetName,String _pGeometricName)
  14. {

  15. INetworkLoader2 pNetworkLoader = new NetworkLoaderClass();

  16. // 网络的名称
  17. pNetworkLoader.NetworkName = _pGeometricName;

  18. // 网络的类型
  19. pNetworkLoader.NetworkType = esriNetworkType.esriNTUtilityNetwork;

  20. // Set the containing feature dataset.
  21. pNetworkLoader.FeatureDatasetName = (IDatasetName)_pFeatureDatasetName;


  22. // 检查要建立几何网络的数据,每一个要素只能参与一个网络
  23. if (pNetworkLoader.CanUseFeatureClass("PrimaryLine") ==
  24. esriNetworkLoaderFeatureClassCheck.esriNLFCCValid)
  25. {
  26. pNetworkLoader.AddFeatureClass("PrimaryLine",
  27. esriFeatureType.esriFTComplexEdge, null, false);
  28. }

  29. if (pNetworkLoader.CanUseFeatureClass("Feeder") ==
  30. esriNetworkLoaderFeatureClassCheck.esriNLFCCValid)
  31. {
  32. pNetworkLoader.AddFeatureClass("Feeder", esriFeatureType.esriFTSimpleJunction,
  33. null, false);
  34. }

  35. // 我的数据中没有enable字段,所以,用了false,如果用true的话,就要进行相关的设置

  36. INetworkLoaderProps pNetworkLoaderProps = (INetworkLoaderProps)pNetworkLoader;

  37. pNetworkLoader.PreserveEnabledValues = false;


  38. // Set the ancillary role field for the Feeder class.
  39. String defaultAncillaryRoleFieldName =
  40. pNetworkLoaderProps.DefaultAncillaryRoleField;
  41. esriNetworkLoaderFieldCheck ancillaryRoleFieldCheck =
  42. pNetworkLoader.CheckAncillaryRoleField("Feeder",
  43. defaultAncillaryRoleFieldName);
  44. switch (ancillaryRoleFieldCheck)
  45. {
  46. case esriNetworkLoaderFieldCheck.esriNLFCValid:
  47. case esriNetworkLoaderFieldCheck.esriNLFCNotFound:
  48. pNetworkLoader.PutAncillaryRole("Feeder",
  49. esriNetworkClassAncillaryRole.esriNCARSourceSink,
  50. defaultAncillaryRoleFieldName);
  51. break;
  52. default:
  53. Console.WriteLine(
  54. "The field {0} could not be used as an ancillary role field.",
  55. defaultAncillaryRoleFieldName);
  56. break;
  57. }



  58. pNetworkLoader.SnapTolerance = 0.02;

  59. // 给几何网络添加权重
  60. pNetworkLoader.AddWeight("Weight", esriWeightType.esriWTDouble, 0);



  61. // 将权重和PrimaryLine数据中的SHAPE_Length字段关联
  62. pNetworkLoader.AddWeightAssociation("Weight", "PrimaryLine", "SHAPE_Length");

  63. // 构建网络
  64. pNetworkLoader.LoadNetwork();


  65. }


  66. IWorkspace pWs = GetWorkspace(@"E:\arcgis\Engine\Geometric.mdb");

  67. IFeatureWorkspace pFtWs = pWs as IFeatureWorkspace;

  68. IFeatureDataset pFtDataset = pFtWs.OpenFeatureDataset("work");

  69. IDataset pDataset = pFtDataset as IDataset;

  70. IFeatureDatasetName pFtDatasetName = pDataset.FullName as IFeatureDatasetName;

  71. CreateGeometricNetwork(pWs, pFtDatasetName, "TestGeometric");
复制代码


效果如下:

你可能感兴趣的:(ArcGISEngine)