public void CreateGeometricNetwork(IWorkspace workspace, IFeatureDatasetName featureDatasetName) { // Create a network loader. INetworkLoader2 networkLoader2 = new NetworkLoaderClass(); // Set the network name. networkLoader2.NetworkName = "Water_Net"; // Set the network type. networkLoader2.NetworkType = esriNetworkType.esriNTUtilityNetwork; // Set the containing feature dataset. networkLoader2.FeatureDatasetName = (IDatasetName)featureDatasetName; // Add the two classes to the network. if (networkLoader2.CanUseFeatureClass("Distribmains") == esriNetworkLoaderFeatureClassCheck.esriNLFCCValid) { networkLoader2.AddFeatureClass("Distribmains", esriFeatureType.esriFTComplexEdge, null, false); } if (networkLoader2.CanUseFeatureClass("Tanks") == esriNetworkLoaderFeatureClassCheck.esriNLFCCValid) { networkLoader2.AddFeatureClass("Tanks", esriFeatureType.esriFTSimpleJunction, null, false); } // Set the enabled field for the distribmains class. INetworkLoaderProps networkLoaderProps = (INetworkLoaderProps)networkLoader2; String defaultEnabledFieldName = networkLoaderProps.DefaultEnabledField; esriNetworkLoaderFieldCheck enabledFieldCheck = networkLoader2.CheckEnabledDisabledField("Tanks", defaultEnabledFieldName); switch (enabledFieldCheck) { case esriNetworkLoaderFieldCheck.esriNLFCValid: case esriNetworkLoaderFieldCheck.esriNLFCNotFound: networkLoader2.PutEnabledDisabledFieldName("Tanks", defaultEnabledFieldName); break; default: Console.WriteLine( "The field {0} could not be used as an enabled/disabled field.", defaultEnabledFieldName); break; } networkLoader2.PreserveEnabledValues = true; // Set the ancillary role field for the tanks class. String defaultAncillaryRoleFieldName = networkLoaderProps.DefaultAncillaryRoleField; esriNetworkLoaderFieldCheck ancillaryRoleFieldCheck = networkLoader2.CheckAncillaryRoleField("Tanks", defaultAncillaryRoleFieldName); switch (ancillaryRoleFieldCheck) { case esriNetworkLoaderFieldCheck.esriNLFCValid: case esriNetworkLoaderFieldCheck.esriNLFCNotFound: networkLoader2.PutAncillaryRole("Tanks", esriNetworkClassAncillaryRole.esriNCARSourceSink, defaultAncillaryRoleFieldName); break; default: Console.WriteLine( "The field {0} could not be used as an ancillary role field.", defaultAncillaryRoleFieldName); break; } // If the geodatabase is an SDE GDB, set the configuration keyword. if (workspace.Type == esriWorkspaceType.esriRemoteDatabaseWorkspace) { networkLoader2.ConfigurationKeyword = "Network_Defaults"; } // Set the snap tolerance for the network. networkLoader2.SnapTolerance = networkLoader2.MinSnapTolerance; // Add a weight with a double type to the network. networkLoader2.AddWeight("MainWeight", esriWeightType.esriWTDouble, 0); // For weights of type esriWTBitGate, the BitGateSize parameter should be set: networkLoader2.AddWeight("WTBitGateEx", esriWeightType.esriWTBitGate, 5); // Associate the MainWeight weight with the DIAMETER field of Distribmains. networkLoader2.AddWeightAssociation("MainWeight", "Distribmains", "DIAMETER"); // Load the network. networkLoader2.LoadNetwork(); // Get the name of the network's error table. String errorTableName = networkLoader2.ErrorTableName; // Display the number of invalid features in the Distribmains class. int numInvalidFeatures = networkLoader2.get_NumInvalidFeatures("Distribmains"); Console.WriteLine("Distribmains contains {0} invalid features.", numInvalidFeatures); // Display the number of invalid features in the network. int totalNumInvalidFeatures = networkLoader2.TotalNumInvalidFeatures; Console.WriteLine("The network contains {0} invalid features.", totalNumInvalidFeatures); }