How to create geometric networks within a geodatabase


Summary
A geometric network allows you to model the behavior features in a utility network, such as electrical and wastewater networks. Geometric networks are created from feature classes that reside in the same feature dataset. The geometric network stores the connectivity of the features and maintains it during editing. Each geometric network has an associated logical network, which is where the connectivity of the features is stored. The logical network is the mechanism through which on-the-fly connectivity is maintained and fast network analysis is accomplished.
The NetworkLoader class allows you to specify input parameters for the geometric network. Once all parameters are specified, the LoadNetwork method is called to create the geometric network according to the specified parameters.
Prior to creating the geometric network, ensure that you have an exclusive schema lock on the feature dataset. Use the ISchemaLock interface to determine if other locks exist and to get an exclusive lock on the feature dataset.
This article demonstrates a common workflow for creating geometric networks.

In this topic


Creating geometric networks within a geodatabase

To build a geometric network using the NetworkLoader object, you need to create the object. Since INetworkLoader2 inherits from INetworkLoader, the methods from both interfaces can be accessed by creating a INetworkLoader2 variable. See the following:
[Java]
INetworkLoader2 networkLoader2 = new NetworkLoader();
At this point, you can start specifying the parameters of how you want your geometric network built. Follow the general order of specifying the parameters as outlined next.
Network name
You need to give your geometric network a name. The name of the geometric network (fully qualified name for ArcSDE geodatabases) must be unique within the geodatabase. You can use the IWorkspace2.NameExists property to ensure that you select a unique name.
If you only have one geometric network in your feature dataset, you can give it a name that is based on the feature dataset. See the following:
[Java]
networkLoader2.setNetworkName("MyNetwork");
Type of network
A geometric network can be one of two types: utility or street. The majority of the functionality in geometric networks has been implemented for utility networks. Network datasets are tailored for use with street networks. See the following:
 
[Java]
networkLoader2.setNetworkType(esriNetworkType.esriNTUtilityNetwork);
Feature dataset name
Geometric networks can only be created within a feature dataset. The NetworkLoader needs a reference to the FeatureDatasetName object where you want to build the geometric network. The featuredatasetName variable in the following code is a reference to the IFeatureDatasetName interface:
[Java]
networkLoader2.setFeatureDatasetName(featuredatasetName);
Enabled or disabled field
Every feature class in your network must have a field that determines whether a feature is enabled or disabled. Enabled and disabled features affect how the flow and trace results are determined. It is strongly recommended to use the default name for the enabled and disabled field. If you do not make a call to PutEnabledDisabledFieldName for a feature class, then the NetworkLoader assumes that you want to use the default name for the enabled and disabled field. See the following:
 
 
The default name for the enabled and disabled field can be obtained from the DefaultEnabledField property on the INetworkLoaderProps interface. If you specify an existing field to use as the enabled and disabled field, verify that this field is of the correct type and domain; to verify, call the CheckEnabledDisabledField method. You also have the option of resetting all values in the existing field to true or preserving the existing values. If the specified field does not exist, the NetworkLoader automatically adds it to the feature class when it builds the network, populating all values in this field with the value of true to indicate that the features are enabled.
 
The following code demonstrates using the default enabled or disabled field name and checking the field before calling PutEnabledDisabledFieldName (see the note that follows the code). The code also sets the PreserveEnabledValues property to true:
 
[Java]
INetworkLoaderProps networkloaderProps = (INetworkLoaderProps)networkLoader2;
String defaultEnabledFieldName = networkloaderProps.getDefaultEnabledField();
int esriLoaderFieldCheck = networkLoader2.checkEnabledDisabledField("primaries",
    defaultEnabledFieldName);
switch (esriLoaderFieldCheck){
    case esriNetworkLoaderFieldCheck.esriNLFCValid:
    case esriNetworkLoaderFieldCheck.esriNLFCNotFound:
        networkLoader2.putEnabledDisabledFieldName("primaries",
            defaultEnabledFieldName);
        break;
    default:
        System.out.println("The field " + defaultEnabledFieldName + 
            " could not be used as an enabled/disabled field.");
        break;
}

networkLoader2.setPreserveEnabledValues(true);
In reality, this code (with the exception of the call to PreserveEnabledValues) is not necessary, since in the absence of calls to PutEnabledDisabledFieldName for a feature class, the NetworkLoader assumes that you want to use the default enabled or disabled field for that feature class. The previous code is provided for illustrative purposes only.
Ancillary roles
Geometric networks are used to model systems with directed flow where the direction of movement through the network is well defined. Flow direction in the geometric network is calculated using a series of sources and sinks. To participate as a source or sink, a feature class must be specified as having an ancillary role. Feature classes that you specify as having an ancillary role indicate that its features can act as either sources or sinks to determine flow within your network. Only point feature classes can be specified as having an ancillary role; however, multiple point feature classes in the network can have ancillary roles. See the following:
Use PutAncillaryRole to specify a feature class as participating as a source or sink. The field name you specify contains the ancillary role attribute for this feature class. It is strongly recommended to use the default name for the ancillary role field. The default name for the ancillary role field can be obtained from the DefaultAncillaryRoleField property on the INetworkLoaderProps interface. If you specify an existing field to use as the ancillary role field, verify that this field is of the correct type and domain and can become an ancillary role field; to verify, call the CheckAncillaryRoleField method. If the specified field does not exist, the NetworkLoader automatically adds it to the feature class when it builds the network, populating all values in this field with 0.
The following code demonstrates using the ancillary role field name and checking the ancillary role field before calling PutAncillaryRole:
[Java]
INetworkLoaderProps networkloaderProps = (INetworkLoaderProps)networkLoader2;
String defaultAncillaryRoleFieldName =
    networkloaderProps.getDefaultAncillaryRoleField();
int esriLoaderFieldCheck = networkLoader2.checkAncillaryRoleField("primaries",
    defaultAncillaryRoleFieldName);
switch (esriLoaderFieldCheck){
    case esriNetworkLoaderFieldCheck.esriNLFCValid:
    case esriNetworkLoaderFieldCheck.esriNLFCNotFound:
        networkLoader2.putAncillaryRole("primaries",
            esriNetworkClassAncillaryRole.esriNCARSourceSink,
            defaultAncillaryRoleFieldName);
        break;
    default:
        System.out.println("The field " + defaultAncillaryRoleFieldName + 
            " could not be used as an ancillary role field.");
        break;
}
Configuration keyword
If you created your geometric network in an ArcSDE geodatabase, you can specify a configuration keyword for building your geometric network. A configuration keyword is used to specify storage and location parameters for optimal space and disk location efficiency. The configuration keyword is provided by your database administrator. See the following:
[Java]
if (workspace.getType() == esriWorkspaceType.esriRemoteDatabaseWorkspace){
    networkLoader2.setConfigurationKeyword("Network_Defaults");
}
Snapping
When a geometric network is built, feature connectivity is determined by the spatial relationship of the features. If features are geometrically coincident, they will be connected during network building.
You may know, for example, where your line features are located but not where your point features are located. In this case, specify that your point features should be snapped. Your line features stay in the same position but the coordinates of your points change to match the line features. If you select more than one feature class to be snapped, then the mean coordinate is computed. Feature classes are designed to participate in snapping when they are added to the NetworkLoader using the AddFeatureClass method.
 
Snap tolerance
The snap tolerance controls the search distance used for establishing connectivity during the network building process. The snap tolerance is specified in map units.
The following code shows you how to specify your snap tolerance to be the minimum or default tolerance. Usually, you use the minimum snapping tolerance to ensure feature connectivity within your geometric network:
[Java]
networkLoader2.setSnapTolerance(networkLoader2.getMinSnapTolerance());
Adding feature classes
A geometric network is built from feature classes. These feature classes must be contained within the feature dataset specified by the INetworkLoader.FeatureDatasetName property. There are some restrictions on the types of feature classes that can participate in a geometric network. Feature classes must be either lines or points; they cannot already be participating in a geometric network; and in the case of SDE, they must not be registered as versioned. Before adding a feature class, you can check for these violations and any others, by calling the CanUseFeatureClass method. See the following:
[Java]
if (networkLoader2.canUseFeatureClass("primaries") ==
    esriNetworkLoaderFeatureClassCheck.esriNLFCCValid){
    networkLoader2.addFeatureClass("primaries", esriFeatureType.esriFTSimple, null,
        false);
}
Adding weights
You can also specify weights to be added to your network. A weight is the cost of moving along a feature in a network. In a water utility network, this could be the diameter of a pipe, which can have an effect on the amount of flow through the pipe. To get all the weights on a network, use the INetSchema interface. The following code example shows how to add a new integer weight:
[Java]
networkLoader2.addWeight("MyWeight", esriWeightType.esriWTInteger, 0);
//For weights of type esriWTBitGate, the BitGateSize parameter should be set:
networkLoader2.addWeight("MyWeight", esriWeightType.esriWTBitGate, 5);
After adding a weight to the network, you need to indicate the feature classes and fields the weight will be associated with. By default, weights are not associated with feature classes. Use the AddWeightAssociation method to indicate the feature classes and fields the weight will use.
Adding weight associations
The weights you specified for your network need to have values. These values are taken from the fields of the feature classes that are participating in the network. Adding weight associations tells the network which fields belong to which weights. A weight can be associated with multiple feature classes but may only be associated with a single field in each feature class. See the following:
[Java]
networkLoader2.addWeightAssociation("MyWeight", "primaries", "fieldname");
These associations are dependent on the type of field and the type of weight you created. For example, a weight of type esriWTDouble can only be associated with a field of type esriFieldTypeDouble. For weights of type esriWTBitGate, the field type can be either esriFieldTypeInteger or esriFieldTypeSmallInteger.
Build your network
Finally, after specifying all of the parameters for your network, you need to tell the NetworkLoader object to build it. You can do this by calling the LoadNetwork method. See the following:
[Java]
networkLoader2.loadNetwork();
After building your network
The feature classes participating in your geometric network can contain features with invalid geometry. The types of invalid geometries are detailed in the esriNetworkErrorType enumeration. If these types of features exist, they will be identified during the network creation process and recorded into the geometric network error table. The error table is created only when features with invalid geometries are found.
You can use the following set of properties to discover if any invalid geometries were found during network creation and to return the total number of invalid geometries or the total for each feature class.
The following returns the name of the error table, which will generally be the name of the geometric network with "_ERR" appended to the end:
[Java]
String errortableName = networkLoader2.getErrorTableName();
The following returns the number of invalid features for the specified feature class:
[Java]
int numinvalidFeatures = networkLoader2.getNumInvalidFeatures("primaries");
The following returns the number of invalid features for all feature classes in the geometric network:
[Java]
int totalnuminvalidFeatures = networkLoader2.getTotalNumInvalidFeatures();






Development licensingDeployment licensing
ArcGIS for Desktop StandardArcGIS for Desktop Standard
ArcGIS for Desktop AdvancedArcGIS for Desktop Advanced
Engine Developer KitEngine