How to create geometric networks within a geodatabase

Source: Internet
Author: User
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);}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.