Blog

Create Geometric Network using ArcObject.

Posted by Yogesh Sharma Blogs | ArcObject Nov 08, 2012
Create Geometric Network using ArcObject.
CREATE GEOMETRIC NETWORK USING ARCOBJECT-

 private void CreateGeometricNetwork(IFeatureWorkspace pfeatws)
        {

            IFeatureDataset pfeatDs= pfeatws.OpenFeatureDataset("Electrical");
            IFeatureDatasetName pdsname = pfeatDs as IFeatureDatasetName;

            //first create NetworkLoader Object

            INetworkLoader2 pNetLoad = new NetworkLoaderClass();
            //name of the network

            pNetLoad.NetworkName = "Electric_net";

            //set the type of Network either utility or street
            pNetLoad.NetworkType = esriNetworkType.esriNTUtilityNetwork;

            pNetLoad.FeatureDatasetName =(IDatasetName) pfeatDs.FullName;

            if (pNetLoad.CanUseFeatureClass("cable") == esriNetworkLoaderFeatureClassCheck.esriNLFCCValid)
            {
                pNetLoad.AddFeatureClass("cable", esriFeatureType.esriFTComplexEdge, null, false);
            
            }

            if (pNetLoad.CanUseFeatureClass("Distribution_Transformer") == esriNetworkLoaderFeatureClassCheck.esriNLFCCValid)
            {
                pNetLoad.AddFeatureClass("Distribution_Transformer", esriFeatureType.esriFTComplexJunction, null, false);

            }

            INetworkLoaderProps pnetloadProp=(INetworkLoaderProps)pNetLoad;
            string defField = pnetloadProp.DefaultEnabledField;

            //Ancillary role

            string defAncRole = pnetloadProp.DefaultAncillaryRoleField;
            esriNetworkLoaderFieldCheck fldChk = pNetLoad.CheckAncillaryRoleField("Distribution_Transformer", defAncRole);
            switch (fldChk)
            { 
                case esriNetworkLoaderFieldCheck.esriNLFCValid:
                case esriNetworkLoaderFieldCheck.esriNLFCNotFound:
                    pNetLoad.PutAncillaryRole("Distribution_Transformer", esriNetworkClassAncillaryRole.esriNCARSourceSink, defAncRole);
                    break;
                //default:
                //    MessageBox.Show("");
                //    break;
            
            
            }

            pNetLoad.SnapTolerance = pNetLoad.MinSnapTolerance;
            pNetLoad.LoadNetwork();
            //pNetLoad.AddWeight("weight_test", esriWeightType.esriWTDouble, 0);
        
        }
COMMENT USING
PREMIUM SPONSORS
Hire Mobile & Web Developer on demand. 100% satisfaction. Try for 1 week or Money Back. Local and remote developers available all over USA.
SPONSORED BY
  • MCN is your source for developing solutions involving websites, mobile apps, cloud-computing, databases, BI, back-end services and processes and client-server applications.