1
2 ///
3 /// 创建几何网络
4 ///
5 ///
6 ///
7 ///
8 ///
9 ///
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 }
2 ///
3 /// 创建几何网络
4 ///
5 ///
6 ///
7 ///
8 ///
9 ///
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 }