• How to create geometric networks within a geodatabase


    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);
    }

  • 相关阅读:
    jQuery+d3绘制流程图OK
    jQuery+d3绘制流程图OK
    史上最全的后端技术大全,你都了解哪些技术呢?
    史上最全的后端技术大全,你都了解哪些技术呢?
    R语言面板数据分析步骤及流程
    R语言面板数据分析步骤及流程
    SQL Server之深入理解STUFF
    1048:有一门课不及格的学生
    1048:有一门课不及格的学生
    1047:判断能否被3,5,7整除
  • 原文地址:https://www.cnblogs.com/zuiyirenjian/p/1894387.html
Copyright © 2020-2023  润新知