创建几何网络(Geometric Network)

 1 
 2           ///   <summary>
 3           ///  创建几何网络
 4           ///   </summary>
 5           ///   <param name="junctions"></param>
 6           ///   <param name="simpleEdges"></param>
 7           ///   <param name="complexEdges"></param>
 8           ///   <param name="featureDatasetName"></param>
 9           ///   <param name="networkname"></param>
10           public   static   void  CreateGeometricNetwork(List < string >  junctions, List < string >  simpleEdges, List < string >  complexEdges, IFeatureDatasetName featureDatasetName,  string  networkname) {
11               //  Create a network loader.
12              INetworkLoader2 networkLoader2  =   new  NetworkLoaderClass();
13               //  Set the network name.
14              networkLoader2.NetworkName  =  networkname;
15               //  Set the network type.
16              networkLoader2.NetworkType  =  esriNetworkType.esriNTUtilityNetwork;
17               //  Set the containing feature dataset.
18              networkLoader2.FeatureDatasetName  =  (IDatasetName)featureDatasetName;
19 
20               //  Add classes to the network.
21               foreach  (var item  in  junctions) {
22                   if  (networkLoader2.CanUseFeatureClass(item)  ==
23                      esriNetworkLoaderFeatureClassCheck.esriNLFCCValid) {
24                      networkLoader2.AddFeatureClass(item,
25                          esriFeatureType.esriFTSimpleJunction,  null false );
26                  }
27              }
28               //  添加简单边
29               foreach  (var item  in  simpleEdges) {
30                   if  (networkLoader2.CanUseFeatureClass(item)  ==
31                      esriNetworkLoaderFeatureClassCheck.esriNLFCCValid) {
32                      networkLoader2.AddFeatureClass(item,
33                          esriFeatureType.esriFTSimpleEdge,  null false );
34                  }
35              }
36               //  添加复杂边
37               foreach  (var item  in  complexEdges) {
38                   if  (networkLoader2.CanUseFeatureClass(item)  ==
39                      esriNetworkLoaderFeatureClassCheck.esriNLFCCValid) {
40                      networkLoader2.AddFeatureClass(item,
41                          esriFeatureType.esriFTComplexEdge,  null false );
42                  }
43              }
44 
45               //  Set the enabled field for the distribmains class.
46              List < string >  fcnames  =   new  List < string > (junctions);
47              fcnames.AddRange(simpleEdges);
48              fcnames.AddRange(complexEdges);
49 
50              INetworkLoaderProps networkLoaderProps  =  (INetworkLoaderProps)networkLoader2;
51              String defaultEnabledFieldName  =  networkLoaderProps.DefaultEnabledField;
52              esriNetworkLoaderFieldCheck enabledFieldCheck  =  esriNetworkLoaderFieldCheck.esriNLFCUnknownError;
53               foreach  (var item  in  fcnames) {
54                  enabledFieldCheck  =  networkLoader2.CheckEnabledDisabledField(item, defaultEnabledFieldName);
55                   switch  (enabledFieldCheck) {
56                       case  esriNetworkLoaderFieldCheck.esriNLFCValid:
57                       case  esriNetworkLoaderFieldCheck.esriNLFCNotFound:
58                          networkLoader2.PutEnabledDisabledFieldName(item,
59                              defaultEnabledFieldName);
60                           break ;
61                  }
62              }
63              networkLoader2.PreserveEnabledValues  =   true ;
64 
65               //  Set the ancillary role field for the tanks class.
66               // String defaultAncillaryRoleFieldName = networkLoaderProps.DefaultAncillaryRoleField;
67               // esriNetworkLoaderFieldCheck ancillaryRoleFieldCheck = esriNetworkLoaderFieldCheck.esriNLFCUnknownError;
68               // foreach (var item in fcnames) {
69               //     networkLoader2.CheckAncillaryRoleField(item, defaultAncillaryRoleFieldName);
70               //     switch (ancillaryRoleFieldCheck) {
71               //         case esriNetworkLoaderFieldCheck.esriNLFCValid:
72               //         case esriNetworkLoaderFieldCheck.esriNLFCNotFound:
73               //             networkLoader2.PutAncillaryRole(item,
74               //                 esriNetworkClassAncillaryRole.esriNCARSourceSink,
75               //                 defaultAncillaryRoleFieldName);
76               //             break;
77               //     }
78               // }
79 
80               //  If the geodatabase is an SDE GDB, set the configuration keyword.
81               if  (SdeWorkspace.Type  ==  esriWorkspaceType.esriRemoteDatabaseWorkspace) {
82                  networkLoader2.ConfigurationKeyword  =   " Network_Defaults " ;
83              }
84               //  Set the snap tolerance for the network.
85              networkLoader2.SnapTolerance  =  networkLoader2.MinSnapTolerance;
86 
87               /// / Add a weight with a double type to the network.
88               // networkLoader2.AddWeight("MainWeight", esriWeightType.esriWTDouble, 0);
89               /// / For weights of type esriWTBitGate, the BitGateSize parameter should be set:
90               // networkLoader2.AddWeight("WTBitGateEx", esriWeightType.esriWTBitGate, 5);
91               /// / Associate the MainWeight weight with the DIAMETER field of Distribmains.
92               // networkLoader2.AddWeightAssociation("MainWeight", "Distribmains", "DIAMETER");
93 
94               //  Load the network.
95              networkLoader2.LoadNetwork();
96          }

 

转载于:https://www.cnblogs.com/xgyb12458/archive/2010/06/02/1749985.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值