How to create a network dataset


Summary This topic shows how to create a simple geodatabase network dataset. The procedure described in this topic constructs the network dataset exactly as it is constructed in Exercise 1 of the ArcGIS Network Analyst Tutorial (referenced in the See Also link at the end of this topic).

In this topic


Creating a network dataset data element

The network dataset being created is based on the SanFrancisco.gdb file geodatabase data located in <your ArcGIS Developer Kit install location>\Samples\data. First, a network dataset data element will be created, the Transportation feature dataset will be opened, and its extent and spatial reference information copied to the data element. The network dataset will be named Streets_ND. Make a backup copy of SanFrancisco.gdb, then delete the network dataset from the main copy. This topic will recreate that dataset.
This topic uses the geodatabase file, SanFrancisco.gdb, which is installed in the C:\arcgis\ArcTutor\Network_Analyst\Tutorial\Exercise01 folder. If you have the ArcGIS Tutorial Data installed, you can modify the OpenFromFile() call in the following code example to create the network dataset in that file geodatabase instead.
Do the following steps to create a network dataset data element:
  1. Create an empty data element for a buildable network dataset.
  2. Open the feature dataset and CType to the IGeoDataset interface.
  3. Copy the feature dataset's extent and spatial reference to the network dataset data element.
  4. Name the network dataset, Streets_ND.
See the following code example:
[Java]
// Create an empty data element for a buildable network dataset.
IDENetworkDataset2 deNetworkDataset = new DENetworkDataset();
deNetworkDataset.setBuildable(true);
// Open the feature dataset and cast to the IGeoDataset interface.
IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory();
IWorkspace workspace = workspaceFactory.openFromFile(fileGDBPath, 0);
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
IFeatureDataset featureDataset = featureWorkspace.openFeatureDataset(
    "Transportation");
IGeoDataset geoDataset = new IGeoDatasetProxy(featureDataset);
// Copy the feature dataset's extent and spatial reference to the network dataset data element.
IDEGeoDataset deGeoDataset = (IDEGeoDataset)deNetworkDataset;
deGeoDataset.setExtentByRef(geoDataset.getExtent());
deGeoDataset.setSpatialReferenceByRef(geoDataset.getSpatialReference());
// Specify the name of the network dataset.
IDataElement dataElement = (IDataElement)deNetworkDataset;
dataElement.setName("Streets_ND");

Adding network sources

The network dataset will be created with two network sources: Streets feature class and RestrictedTurns feature class. The Streets feature class becomes an edge source in the network dataset and the RestrictedTurns feature class becomes a turn source.

Specifying connectivity settings for the edge source

The Streets feature class needs to be an edge feature source in the network dataset with the appropriate connectivity and directions settings. The following is from the New Network Dataset wizard's summary for the source's connectivity settings:
Connectivity:
  Group 1:
    Edge Connectivity:
      Streets (End Point)
Elevation Model: Elevation Fields
  Edge Elevation Fields: (From End, To End):
    Streets: (F_ELEV, T_ELEV)
The following code example shows connectivity settings that will be used when creating an EdgeFeatureSource object:
[Java]
// Specify the network dataset's elevation model.
deNetworkDataset.setElevationModel(esriNetworkElevationModel.esriNEMElevationFields);
// Create an EdgeFeatureSource object and point it to the Streets feature class.
INetworkSource edgeNetworkSource = new EdgeFeatureSource();
edgeNetworkSource.setName("Streets");
edgeNetworkSource.setElementType(esriNetworkElementType.esriNETEdge);
// Set the edge feature source's connectivity settings.
IEdgeFeatureSource edgeFeatureSource = (IEdgeFeatureSource)edgeNetworkSource;
edgeFeatureSource.setUsesSubtypes(false);
edgeFeatureSource.setClassConnectivityGroup(1);
edgeFeatureSource.setClassConnectivityPolicy
    (esriNetworkEdgeConnectivityPolicy.esriNECPEndVertex);
edgeFeatureSource.setFromElevationFieldName("F_ELEV");
edgeFeatureSource.setToElevationFieldName("T_ELEV");

Specifying directions settings for the edge source

The edge source also has settings used when generating driving directions and identifying the fields that contain the street names. The following is from the New Network Dataset wizard's summary for the source's directions settings:
Source Directions:
    Streets:
      Street Name Fields:
        Primary:
          Name: NAME
The following directions settings will be used when creating a StreetNameFields object. This object will be added to the previously created EdgeFeatureSource object:
[Java]
// Create a StreetNameFields object and populate its settings.
IStreetNameFields streetNameFields = new StreetNameFields();
streetNameFields.setPriority(1); // Priority 1 indicates the primary street name.
streetNameFields.setStreetNameFieldName("NAME");
// Add the StreetNameFields object to a new NetworkSourceDirections object,
// then add it to the EdgeFeatureSource created earlier.
INetworkSourceDirections nsDirections = new NetworkSourceDirections();
IArray nsdArray = new Array();
nsdArray.add(streetNameFields);
nsDirections.setStreetNameFieldsByRef(nsdArray);
edgeNetworkSource.setNetworkSourceDirectionsByRef(nsDirections);

Specifying the turn source

The network dataset will have a turn feature source referencing the RestrictedTurns feature class.
Specify on the data element that the network dataset supports turns, then create the TurnFeatureSource object. See the following code example:
[Java]
deNetworkDataset.setSupportsTurns(true);
// Create a TurnFeatureSource object and point it to the RestrictedTurns feature class.
INetworkSource turnNetworkSource = new TurnFeatureSource();
turnNetworkSource.setName("RestrictedTurns");
turnNetworkSource.setElementType(esriNetworkElementType.esriNETTurn);
Now that all the sources have been created, they can be added to the array, then the array can be added to the network dataset data element. See the following code example:
[Java]
IArray sourceArray = new Array();
sourceArray.add(edgeNetworkSource);
sourceArray.add(turnNetworkSource);
deNetworkDataset.setSourcesByRef(sourceArray);

Adding the traffic data tables

This network dataset will be created with historical traffic data. The historical traffic data consists of two tables: the speed profile table and the street-speed profile join table. The following is from the New Network Dataset wizard's summary for the historical traffic settings:
  Speed Profile Table:
    Table: DailyProfiles
    First Time Slice Field: TimeFactor_0400
    Last Time Slice Field: TimeFactor_2155
    Minutes Per Time Slice: 5
    First Time Slice Start Time: 4 AM
    Last Time Slice Finish Time: 10 PM
  Street - Speed Profile Join Table:
    Table: Streets_DailyProfiles
    Base Travel Time Field: FreeflowMinutes
    Base Travel Time Units: Minutes
    Sunday ProfileID Field: PROFILE_1
    Monday ProfileID Field: PROFILE_2
    Tuesday ProfileID Field: PROFILE_3
    Wednesday ProfileID Field: PROFILE_4
    Thursday ProfileID Field: PROFILE_5
    Friday ProfileID Field: PROFILE_6
    Saturday ProfileID Field: PROFILE_7
The above historical traffic settings will be used when creating a new TrafficData object. See the following code:
[Java]
// Create a new TrafficData object and populate its historical traffic settings.
IHistoricalTrafficData histTraff = new TrafficData();
// Populate the speed profile table settings.
histTraff.setProfilesTableName("DailyProfiles");
histTraff.setFirstTimeSliceFieldName("TimeFactor_0400");
histTraff.setLastTimeSliceFieldName("TimeFactor_2155");
histTraff.setTimeSliceDurationInMinutes(5);
Date date = new Date( - 1, 11, 30, 4, 0, 0); //December 30th, 1899, 4:00AM
histTraff.setFirstTimeSliceStartTime(date);
// Note: the last time slice finish time is implied from the above settings and need not be specified.
// Populate the street-speed profile join table settings.
histTraff.setJoinTableName("Streets_DailyProfiles");
histTraff.setJoinTableBaseTravelTimeFieldName("FreeflowMinutes");
histTraff.setJoinTableBaseTravelTimeUnits(esriNetworkAttributeUnits.esriNAUMinutes);
IStringArray fieldNames = new Names();
fieldNames.add("PROFILE_1");
fieldNames.add("PROFILE_2");
fieldNames.add("PROFILE_3");
fieldNames.add("PROFILE_4");
fieldNames.add("PROFILE_5");
fieldNames.add("PROFILE_6");
fieldNames.add("PROFILE_7");
histTraff.setJoinTableProfileIDFieldNamesByRef(fieldNames);
// Add the traffic data to the network dataset data element.
deNetworkDataset.setTrafficDataByRef((ITrafficData)histTraff);

Adding network attributes

The network dataset will be created with the following network attributes:
An empty array for the network attributes will be created, then each attribute will be created and added to the array. See the following code example:
[Java]
IArray attributeArray = new Array();
// Initialize variables reused when creating attributes:
IEvaluatedNetworkAttribute evalNetAttr;
INetworkAttribute2 netAttr2;
INetworkFieldEvaluator netFieldEval;
INetworkConstantEvaluator netConstEval;

Oneway network attribute

The following is from the New Network Dataset wizard's summary for the Oneway network attribute:
Oneway:
    Usage Type: Restriction
    Data Type: Boolean
    Units Type: Unknown
    Use by Default: True
    Source Attribute Evaluators:
      Streets (From-To): Field -
          Prelogic:
            restricted = False
            Select Case UCase([ONEWAY])
              Case "N", "TF", "T": restricted = True
            End Select
          Expression: restricted
      Streets (To-From): Field -
          Prelogic:
            restricted = False
            Select Case UCase([ONEWAY])
              Case "N", "FT", "F": restricted = True
            End Select
          Expression: restricted
    Default Attribute Evaluators:
      Default Edges: Constant - Traversable
      Default Junctions: Constant - Traversable
      Default Turns: Constant - Traversable
See the following code example:
[Java]
// Create an EvaluatedNetworkAttribute object and populate its settings.
evalNetAttr = new EvaluatedNetworkAttribute();
netAttr2 = (INetworkAttribute2)evalNetAttr;
netAttr2.setName("Oneway");
netAttr2.setUsageType(esriNetworkAttributeUsageType.esriNAUTRestriction);
netAttr2.setDataType(esriNetworkAttributeDataType.esriNADTBoolean);
netAttr2.setUnits(esriNetworkAttributeUnits.esriNAUUnknown);
netAttr2.setUseByDefault(true);
// Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
netFieldEval = new NetworkFieldEvaluator();
netFieldEval.setExpression("restricted", "restricted = False\n\r" + 
    "Select Case UCase([ONEWAY])\n\r" + 
    " Case \"N\", \"TF\", \"T\": restricted = True\n\r" + "End Select");
evalNetAttr.setEvaluatorByRef(edgeNetworkSource,
    esriNetworkEdgeDirection.esriNEDAlongDigitized, (INetworkEvaluator)netFieldEval);
netFieldEval = new NetworkFieldEvaluator();
netFieldEval.setExpression("restricted", "restricted = False\n\r" + 
    "Select Case UCase([ONEWAY])\n\r" + 
    " Case \"N\", \"FT\", \"F\": restricted = True\n\r" + "End Select");
evalNetAttr.setEvaluatorByRef(edgeNetworkSource,
    esriNetworkEdgeDirection.esriNEDAgainstDigitized, (INetworkEvaluator)
    netFieldEval);
netConstEval = new NetworkConstantEvaluator();
netConstEval.setConstantValue(false); // False = traversable.
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETEdge, 
    (INetworkEvaluator)netConstEval);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETJunction, 
    (INetworkEvaluator)netConstEval);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETTurn, 
    (INetworkEvaluator)netConstEval);
// Add the attribute to the array.
attributeArray.add(evalNetAttr);

Minutes network attribute

The following is from the New Network Dataset wizard's summary for the Minutes network attribute:
Minutes:
    Usage Type: Cost
    Data Type: Double
    Units Type: Minutes
    Use by Default: False
    Source Attribute Evaluators:
      Streets (From-To): Field - [MINUTES]
      Streets (To-From): Field - [MINUTES]
    Default Attribute Evaluators:
      Default Edges: Constant - 0
      Default Junctions: Constant - 0
      Default Turns: Constant - 0
See the following code example:
[Java]
// Create an EvaluatedNetworkAttribute object and populate its settings.
evalNetAttr = new EvaluatedNetworkAttribute();
netAttr2 = (INetworkAttribute2)evalNetAttr;
netAttr2.setName("Minutes");
netAttr2.setUsageType(esriNetworkAttributeUsageType.esriNAUTCost);
netAttr2.setDataType(esriNetworkAttributeDataType.esriNADTDouble);
netAttr2.setUnits(esriNetworkAttributeUnits.esriNAUMinutes);
netAttr2.setUseByDefault(false);
// Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
netFieldEval = new NetworkFieldEvaluator();
netFieldEval.setExpression("[MINUTES]", "");
evalNetAttr.setEvaluatorByRef(edgeNetworkSource,
    esriNetworkEdgeDirection.esriNEDAlongDigitized, (INetworkEvaluator)netFieldEval);
evalNetAttr.setEvaluatorByRef(edgeNetworkSource,
    esriNetworkEdgeDirection.esriNEDAgainstDigitized, (INetworkEvaluator)
    netFieldEval);
netConstEval = new NetworkConstantEvaluator();
netConstEval.setConstantValue(0);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETEdge, 
    (INetworkEvaluator)netConstEval);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETJunction, 
    (INetworkEvaluator)netConstEval);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETTurn, 
    (INetworkEvaluator)netConstEval);
// Add the attribute to the array.
attributeArray.add(evalNetAttr);

Meters network attribute

The following is from the New Network Dataset wizard's summary for the Meters network attribute:
Meters:
    Usage Type: Cost
    Data Type: Double
    Units Type: Meters
    Use by Default: False
    Source Attribute Evaluators:
      Streets (From-To): Field - [METERS]
      Streets (To-From): Field - [METERS]
    Default Attribute Evaluators:
      Default Edges: Constant - 0
      Default Junctions: Constant - 0
      Default Turns: Constant - 0
See the following code example:
[Java]
// Create an EvaluatedNetworkAttribute object and populate its settings.
evalNetAttr = new EvaluatedNetworkAttribute();
netAttr2 = (INetworkAttribute2)evalNetAttr;
netAttr2.setName("Meters");
netAttr2.setUsageType(esriNetworkAttributeUsageType.esriNAUTCost);
netAttr2.setDataType(esriNetworkAttributeDataType.esriNADTDouble);
netAttr2.setUnits(esriNetworkAttributeUnits.esriNAUMeters);
netAttr2.setUseByDefault(false);
// Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
netFieldEval = new NetworkFieldEvaluator();
netFieldEval.setExpression("[METERS]", "");
evalNetAttr.setEvaluatorByRef(edgeNetworkSource,
    esriNetworkEdgeDirection.esriNEDAlongDigitized, (INetworkEvaluator)netFieldEval);
evalNetAttr.setEvaluatorByRef(edgeNetworkSource,
    esriNetworkEdgeDirection.esriNEDAgainstDigitized, (INetworkEvaluator)
    netFieldEval);
netConstEval = new NetworkConstantEvaluator();
netConstEval.setConstantValue(0);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETEdge, 
    (INetworkEvaluator)netConstEval);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETJunction, 
    (INetworkEvaluator)netConstEval);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETTurn, 
    (INetworkEvaluator)netConstEval);
// Add the attribute to the array.
attributeArray.add(evalNetAttr);

RoadClass network attribute

The following is from the New Network Dataset wizard's summary for the RoadClass network attribute:
RoadClass:
    Usage Type: Descriptor
    Data Type: Integer
    Units Type: Unknown
    Use by Default: False
    Source Attribute Evaluators:
      Streets (From-To): Field -
          Prelogic:
            rc = 1          'Local road
            If [FEATTYP] = 4130 Then
              rc = 4          'Ferry
            Else
              Select Case [FOW]
                Case 1: rc = 2          'Highway
                Case 10: rc = 3          'Ramp
                Case 4: rc = 5          'Roundabout
              End Select
            End If
          Expression: rc
      Streets (To-From): Field -
          Prelogic:
            rc = 1          'Local road
            If [FEATTYP] = 4130 Then
              rc = 4          'Ferry
            Else
              Select Case [FOW]
                Case 1: rc = 2          'Highway
                Case 10: rc = 3          'Ramp
                Case 4: rc = 5          'Roundabout
              End Select
            End If
          Expression: rc
    Default Attribute Evaluators:
      Default Edges: Constant - 0
      Default Junctions: Constant - 0
      Default Turns: Constant - 0
See the following code example:
[Java]
// Create an EvaluatedNetworkAttribute object and populate its settings.
evalNetAttr = new EvaluatedNetworkAttribute();
netAttr2 = (INetworkAttribute2)evalNetAttr;
netAttr2.setName("RoadClass");
netAttr2.setUsageType(esriNetworkAttributeUsageType.esriNAUTDescriptor);
netAttr2.setDataType(esriNetworkAttributeDataType.esriNADTInteger);
netAttr2.setUnits(esriNetworkAttributeUnits.esriNAUUnknown);
netAttr2.setUseByDefault(false);
// Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
netFieldEval = new NetworkFieldEvaluator();
netFieldEval.setExpression("rc", "rc = 1 'Local road\n\r" + 
    "If [FEATTYP] = 4130 Then\n\r" + " rc = 4 'Ferry\n\r" + "Else\n\r" + 
    " Select Case [FOW]\n\r" + " Case 1: rc = 2 'Highway\n\r" + 
    " Case 10: rc = 3 'Ramp\n\r" + " Case 4: rc = 5 'Roundabout\n\r" + 
    " End Select\n\r" + "End If");
evalNetAttr.setEvaluatorByRef(edgeNetworkSource,
    esriNetworkEdgeDirection.esriNEDAlongDigitized, (INetworkEvaluator)netFieldEval);
evalNetAttr.setEvaluatorByRef(edgeNetworkSource,
    esriNetworkEdgeDirection.esriNEDAgainstDigitized, (INetworkEvaluator)
    netFieldEval);
netConstEval = new NetworkConstantEvaluator();
netConstEval.setConstantValue(0);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETEdge, 
    (INetworkEvaluator)netConstEval);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETJunction, 
    (INetworkEvaluator)netConstEval);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETTurn, 
    (INetworkEvaluator)netConstEval);
// Add the attribute to the array.
attributeArray.add(evalNetAttr);

WeekdayFallbackTravelTime network attribute

The following is from the New Network Dataset wizard's summary for the WeekdayFallbackTravelTime network attribute:
WeekdayFallbackTravelTime:
    Usage Type: Cost
    Data Type: Double
    Units Type: Minutes
    Use by Default: False
    Source Attribute Evaluators:
      Streets (From-To): Field - [FT_WeekdayMinutes]
      Streets (To-From): Field - [TF_WeekdayMinutes]
    Default Attribute Evaluators:
      Default Edges: Constant - 0
      Default Junctions: Constant - 0
      Default Turns: Constant - 0
See the following code example:
[Java]
// Create an EvaluatedNetworkAttribute object and populate its settings.
evalNetAttr = new EvaluatedNetworkAttribute();
netAttr2 = (INetworkAttribute2)evalNetAttr;
netAttr2.setName("WeekdayFallbackTravelTime");
netAttr2.setUsageType(esriNetworkAttributeUsageType.esriNAUTCost);
netAttr2.setDataType(esriNetworkAttributeDataType.esriNADTDouble);
netAttr2.setUnits(esriNetworkAttributeUnits.esriNAUMinutes);
netAttr2.setUseByDefault(false);
// Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
netFieldEval = new NetworkFieldEvaluator();
netFieldEval.setExpression("[FT_WeekdayMinutes]", "");
evalNetAttr.setEvaluatorByRef(edgeNetworkSource,
    esriNetworkEdgeDirection.esriNEDAlongDigitized, (INetworkEvaluator)netFieldEval);
netFieldEval = new NetworkFieldEvaluator();
netFieldEval.setExpression("[TF_WeekdayMinutes]", "");
evalNetAttr.setEvaluatorByRef(edgeNetworkSource,
    esriNetworkEdgeDirection.esriNEDAgainstDigitized, (INetworkEvaluator)
    netFieldEval);
netConstEval = new NetworkConstantEvaluator();
netConstEval.setConstantValue(0);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETEdge, 
    (INetworkEvaluator)netConstEval);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETJunction, 
    (INetworkEvaluator)netConstEval);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETTurn, 
    (INetworkEvaluator)netConstEval);
// Add the attribute to the array.
attributeArray.add(evalNetAttr);

WeekendFallbackTravelTime network attribute

The following is from the New Network Dataset wizard's summary for the WeekendFallbackTravelTime network attribute:
WeekendFallbackTravelTime:
    Usage Type: Cost
    Data Type: Double
    Units Type: Minutes
    Use by Default: False
    Source Attribute Evaluators:
      Streets (From-To): Field - [FT_WeekendMinutes]
      Streets (To-From): Field - [TF_WeekendMinutes]
    Default Attribute Evaluators:
      Default Edges: Constant - 0
      Default Junctions: Constant - 0
      Default Turns: Constant - 0
See the following code example:
[Java]
// Create an EvaluatedNetworkAttribute object and populate its settings.
evalNetAttr = new EvaluatedNetworkAttribute();
netAttr2 = (INetworkAttribute2)evalNetAttr;
netAttr2.setName("WeekendFallbackTravelTime");
netAttr2.setUsageType(esriNetworkAttributeUsageType.esriNAUTCost);
netAttr2.setDataType(esriNetworkAttributeDataType.esriNADTDouble);
netAttr2.setUnits(esriNetworkAttributeUnits.esriNAUMinutes);
netAttr2.setUseByDefault(false);
// Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
netFieldEval = new NetworkFieldEvaluator();
netFieldEval.setExpression("[FT_WeekendMinutes]", "");
evalNetAttr.setEvaluatorByRef(edgeNetworkSource,
    esriNetworkEdgeDirection.esriNEDAlongDigitized, (INetworkEvaluator)netFieldEval);
netFieldEval = new NetworkFieldEvaluator();
netFieldEval.setExpression("[TF_WeekendMinutes]", "");
evalNetAttr.setEvaluatorByRef(edgeNetworkSource,
    esriNetworkEdgeDirection.esriNEDAgainstDigitized, (INetworkEvaluator)
    netFieldEval);
netConstEval = new NetworkConstantEvaluator();
netConstEval.setConstantValue(0);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETEdge, 
    (INetworkEvaluator)netConstEval);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETJunction, 
    (INetworkEvaluator)netConstEval);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETTurn, 
    (INetworkEvaluator)netConstEval);
// Add the attribute to the array.
attributeArray.add(evalNetAttr);

TravelTime network attribute

The following is from the New Network Dataset wizard's summary for the TravelTime network attribute:
TravelTime:
    Usage Type: Cost
    Data Type: Double
    Units Type: Minutes
    Use by Default: True
    Source Attribute Evaluators:
      Streets (From-To): Edge Traffic
        Weekday Fallback Attribute: WeekdayFallbackTravelTime
        Weekend Fallback Attribute: WeekendFallbackTravelTime
        Time Neutral Attribute: Minutes
      Streets (To-From): Edge Traffic
        Weekday Fallback Attribute: WeekdayFallbackTravelTime
        Weekend Fallback Attribute: WeekendFallbackTravelTime
        Time Neutral Attribute: Minutes
    Default Attribute Evaluators:
      Default Edges: Constant - 0
      Default Junctions: Constant - 0
      Default Turns: Constant - 0
See the following code example:
[Java]
// Create an EvaluatedNetworkAttribute object and populate its settings.
evalNetAttr = new EvaluatedNetworkAttribute();
netAttr2 = (INetworkAttribute2)evalNetAttr;
netAttr2.setName("TravelTime");
netAttr2.setUsageType(esriNetworkAttributeUsageType.esriNAUTCost);
netAttr2.setDataType(esriNetworkAttributeDataType.esriNADTDouble);
netAttr2.setUnits(esriNetworkAttributeUnits.esriNAUMinutes);
netAttr2.setUseByDefault(true);
// Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
IHistoricalTravelTimeEvaluator histTravelTimeEval = new NetworkEdgeTrafficEvaluator()
    ;
histTravelTimeEval.setWeekdayFallbackAttributeName("WeekdayFallbackTravelTime");
histTravelTimeEval.setWeekendFallbackAttributeName("WeekendFallbackTravelTime");
histTravelTimeEval.setTimeNeutralAttributeName("Minutes");
evalNetAttr.setEvaluatorByRef(edgeNetworkSource,
    esriNetworkEdgeDirection.esriNEDAlongDigitized, (INetworkEvaluator)
    histTravelTimeEval);
evalNetAttr.setEvaluatorByRef(edgeNetworkSource,
    esriNetworkEdgeDirection.esriNEDAgainstDigitized, (INetworkEvaluator)
    histTravelTimeEval);
netConstEval = new NetworkConstantEvaluator();
netConstEval.setConstantValue(0);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETEdge, 
    (INetworkEvaluator)netConstEval);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETJunction, 
    (INetworkEvaluator)netConstEval);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETTurn, 
    (INetworkEvaluator)netConstEval);
// Add the attribute to the array.
attributeArray.add(evalNetAttr);

RestrictedTurns network attribute

The following is from the New Network Dataset wizard's summary for the RestrictedTurns network attribute:
RestrictedTurns:
    Usage Type: Restriction
    Data Type: Boolean
    Units Type: Unknown
    Use by Default: True
    Source Attribute Evaluators: 
      RestrictedTurns: Constant - Restricted
    Default Attribute Evaluators:
      Default Edges: Constant - Traversable
      Default Junctions: Constant - Traversable
      Default Turns: Constant - Traversable 
See the following code example:
[Java]
// Create an EvaluatedNetworkAttribute object and populate its settings.
evalNetAttr = new EvaluatedNetworkAttribute();
netAttr2 = (INetworkAttribute2)evalNetAttr;
netAttr2.setName("RestrictedTurns");
netAttr2.setUsageType(esriNetworkAttributeUsageType.esriNAUTRestriction);
netAttr2.setDataType(esriNetworkAttributeDataType.esriNADTBoolean);
netAttr2.setUnits(esriNetworkAttributeUnits.esriNAUUnknown);
netAttr2.setUseByDefault(true);
netConstEval = new NetworkConstantEvaluator();
netConstEval.setConstantValue(true);
evalNetAttr.setEvaluatorByRef(turnNetworkSource,
    esriNetworkEdgeDirection.esriNEDNone, (INetworkEvaluator)netConstEval);
netConstEval = new NetworkConstantEvaluator();
netConstEval.setConstantValue(false);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETEdge, 
    (INetworkEvaluator)netConstEval);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETJunction, 
    (INetworkEvaluator)netConstEval);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETTurn, 
    (INetworkEvaluator)netConstEval);
// Add the attribute to the array.
attributeArray.add(evalNetAttr);

HierarchyMultiNet network attribute

The following is from the New Network Dataset wizard's summary for the HierarchyMultiNet network attribute:
HierarchyMultiNet:
    Usage Type: Hierarchy
    Data Type: Integer
    Units Type: Unknown
    Use by Default: False
    Hierarchy Ranges:
      Primary Roads: up to 2
      Secondary Roads: 3 - 4
      Local Roads: 5 and higher
    Source Attribute Evaluators:
      Streets (From-To): Field -
          Prelogic:
            h = [NET2CLASS] + 1
            if h > 5 Then h = 5
          Expression: h
      Streets (To-From): Field -
          Prelogic:
            h = [NET2CLASS] + 1
            if h > 5 Then h = 5
          Expression: h
    Default Attribute Evaluators:
      Default Edges: Constant - 0
      Default Junctions: Constant - 0
      Default Turns: Constant - 0
See the following code example:
[Java]
// Create an EvaluatedNetworkAttribute object and populate its settings.
evalNetAttr = new EvaluatedNetworkAttribute();
netAttr2 = (INetworkAttribute2)evalNetAttr;
netAttr2.setName("HierarchyMultiNet");
netAttr2.setUsageType(esriNetworkAttributeUsageType.esriNAUTHierarchy);
netAttr2.setDataType(esriNetworkAttributeDataType.esriNADTInteger);
netAttr2.setUnits(esriNetworkAttributeUnits.esriNAUUnknown);
netAttr2.setUseByDefault(false);
// Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
netFieldEval = new NetworkFieldEvaluator();
netFieldEval.setExpression("h", "h = [NET2CLASS] + 1\n\r" + "if h > 5 then h = 5");
evalNetAttr.setEvaluatorByRef(edgeNetworkSource,
    esriNetworkEdgeDirection.esriNEDAlongDigitized, (INetworkEvaluator)netFieldEval);
evalNetAttr.setEvaluatorByRef(edgeNetworkSource,
    esriNetworkEdgeDirection.esriNEDAgainstDigitized, (INetworkEvaluator)
    netFieldEval);
netConstEval = new NetworkConstantEvaluator();
netConstEval.setConstantValue(0);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETEdge, 
    (INetworkEvaluator)netConstEval);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETJunction, 
    (INetworkEvaluator)netConstEval);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETTurn, 
    (INetworkEvaluator)netConstEval);
// Add the attribute to the array.
attributeArray.add(evalNetAttr);
// Since this is the hierarchy attribute, also set it as the hierarchy cluster attribute.
deNetworkDataset.setHierarchyClusterAttribute((INetworkAttribute)evalNetAttr);
// Specify the ranges for the hierarchy levels.
deNetworkDataset.setHierarchyLevelCount(3);
deNetworkDataset.setMaxValueForHierarchy(1, 2); // level 1: up to 2
deNetworkDataset.setMaxValueForHierarchy(2, 4); // level 2: 3 - 4
deNetworkDataset.setMaxValueForHierarchy(3, 5); 
    // level 3: 5 and higher (the values of h only go up to 5)
Now that all the attributes have been added to the array, the array to the network dataset data element can be added. See the following code example:
[Java]
deNetworkDataset.setAttributesByRef(attributeArray);

Specifying directions settings

The network dataset has settings for generating driving directions. The source-specific settings were specified when the EdgeFeatureSource was created. Next, the general settings will be specified.

General directions settings

The following is from the New Network Dataset wizard's summary for the General Directions settings:
  General Directions:
    Display Length Units: Miles
    Length Attribute: Meters
    Time Attribute: Minutes
    Signpost Feature Class: Signposts
    Signpost Streets Table: Signposts_Streets
    Road Detail:
      Road Class Attribute: RoadClass
These directions settings will be used when creating a NetworkDirections object, then the object will be added to the network dataset data element object. See the following code example:
[Java]
// Create a NetworkDirections object and populate its settings.
INetworkDirections networkDirections = new NetworkDirections();
networkDirections.setDefaultOutputLengthUnits(esriNetworkAttributeUnits.esriNAUMiles)
    ;
networkDirections.setLengthAttributeName("Meters");
networkDirections.setTimeAttributeName("Minutes");
networkDirections.setRoadClassAttributeName("RoadClass");
ISignposts netDirSignposts = (ISignposts)networkDirections;
netDirSignposts.setSignpostFeatureClassName("Signposts");
netDirSignposts.setSignpostStreetsTableName("Signposts_Streets");
// Add the NetworkDirections object to the network dataset data element.
deNetworkDataset.setDirectionsByRef(networkDirections);

Creating and building the network dataset

All the network dataset settings are now included on the data element, and the network dataset can be created. A network dataset is created through the Network Dataset Feature Dataset extension. Once the network dataset is created, build it using the INetworkBuild interface. See the following code example:
[Java]
// Get the feature dataset extension and create the network dataset based on the data element.
IFeatureDatasetExtensionContainer fdxContainer = new
    IFeatureDatasetExtensionContainerProxy(featureDataset);
IFeatureDatasetExtension fdExtension = fdxContainer.findExtension
    (esriDatasetType.esriDTNetworkDataset);
IDatasetContainer2 datasetContainer2 = new IDatasetContainer2Proxy(fdExtension);
IDEDataset deDataset = (IDEDataset)deNetworkDataset;
INetworkDataset networkDataset = new INetworkDatasetProxy
    (datasetContainer2.createDataset(deDataset));
// Once the network dataset is created, build it.
INetworkBuild networkBuild = new INetworkBuildProxy(networkDataset);
networkBuild.buildNetwork(geoDataset.getExtent());






Development licensing Deployment licensing
ArcView ArcView: Network Analyst
ArcEditor ArcEditor: Network Analyst
ArcInfo ArcInfo: Network Analyst
Engine Developer Kit Engine Runtime: Network