- Creating a new network dataset data element
- Adding the network sources
- Adding the network attributes
- Specifying directions settings
- Creating and building the network dataset
The network dataset being created is based on the Paris.gdb file geodatabase data located in: C:\Program Files\ArcGIS\DeveloperKit\SamplesNET\data\CreateNetworkDataset. First, a new network dataset data element will be created, the RoadNetwork feature dataset will be opened, and its extent and spatial reference information copied to the data element. The network dataset will be named ParisNet.
This document uses the geodatabase file, Paris.gdb, which is installed in the C:\arcgis\ArcTutor\Network_Analyst\Exercise2 folder. If you have the ArcGIS Tutorial Data installed, you can modify the OpenFromFile() call in the following code to create the network dataset in that file geodatabase instead.
[VB.NET]
' Create a new empty data element for a buildable network dataset.
Dim deND As IDENetworkDataset = New DENetworkDataset
deND.Buildable = True
' Open the feature dataset and CType to the IGeoDataset interface.
Dim gdbWSF As IWorkspaceFactory = New FileGDBWorkspaceFactory
Dim gdbFWS As IFeatureWorkspace = CType(gdbWSF.OpenFromFile("C:\Program Files\ArcGIS\DeveloperKit\SamplesNET\data\CreateNetworkDataset\Paris.gdb", 0), IFeatureWorkspace)
Dim fdsGDS As IGeoDataset = CType(gdbFWS.OpenFeatureDataset("RoadNetwork"), IGeoDataset)
' Copy the feature dataset's extent and spatial reference to the network dataset data element.
Dim deGDS As IDEGeoDataset = CType(deND, IDEGeoDataset)
deGDS.Extent = fdsGDS.Extent
deGDS.SpatialReference = fdsGDS.SpatialReference
' Specify the name of the network dataset.
Dim dataElement As IDataElement = CType(deND, IDataElement)
dataElement.Name = "ParisNet"
[C#]
// Create a new empty data element for a buildable network dataset.
IDENetworkDataset deNetworkDataset = new DENetworkDatasetClass();
deNetworkDataset.Buildable = true;
// Open the feature dataset and cast to the IGeoDataset interface.
IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory();
IWorkspace workspace = workspaceFactory.OpenFromFile(@
"C:\Program Files\ArcGIS\DeveloperKit\SamplesNET\data\CreateNetworkDataset\Paris.gdb", 0);
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
IFeatureDataset featureDataset = featureWorkspace.OpenFeatureDataset("RoadNetwork");
IGeoDataset geoDataset = (IGeoDataset)featureDataset;
// Copy the feature dataset's extent and spatial reference to the network dataset data element.
IDEGeoDataset deGeoDataset = (IDEGeoDataset)deNetworkDataset;
deGeoDataset.Extent = geoDataset.Extent;
deGeoDataset.SpatialReference = geoDataset.SpatialReference;
// Specify the name of the network dataset.
IDataElement dataElement = (IDataElement)deNetworkDataset;
dataElement.Name = "ParisNet";
The network dataset will be created with two network sources: Streets feature class and ParisTurns feature class. The Streets feature class will become an edge source in the network dataset, and the ParisTurns feature class will become a turn 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 : Highways (End Point)
Streets : Local Streets (Any Vertex)
Streets : Major Roads (End Point)
Group 1:
Edge Connectivity:
Streets : Highways (End Point)
Streets : Local Streets (Any Vertex)
Streets : Major Roads (End Point)
The subtype values for the Streets feature class are as follows:
Highways = 1
Major Roads = 2
Local Streets = 3
Major Roads = 2
Local Streets = 3
The following connectivity settings will be used when creating a new EdgeFeatureSource object:
[VB.NET]
' Create a new EdgeFeatureSource object and point it to the Streets feature class.
Dim edgeNetSource As INetworkSource = New EdgeFeatureSource
edgeNetSource.Name = "Streets"
edgeNetSource.ElementType = esriNETEdge
' Set the edge feature source's connectivity settings.
Dim edgeFS As IEdgeFeatureSource = CType(edgeNetSource, IEdgeFeatureSource)
With edgeFS
.UsesSubtypes = True
.SubtypeConnectivityGroup(1) = 1
.SubtypeConnectivityPolicy(1) = esriNECPEndVertex
.SubtypeConnectivityGroup(2) = 1
.SubtypeConnectivityPolicy(2) = esriNECPEndVertex
.SubtypeConnectivityGroup(3) = 1
.SubtypeConnectivityPolicy(3) = esriNECPAnyVertex
End With
[C#]
// Create a new EdgeFeatureSource object and point it to the Streets feature class.
INetworkSource edgeNetworkSource = new EdgeFeatureSourceClass();
edgeNetworkSource.Name = "Streets";
edgeNetworkSource.ElementType = esriNetworkElementType.esriNETEdge;
// Set the edge feature source's connectivity settings.
IEdgeFeatureSource edgeFeatureSource = (IEdgeFeatureSource)edgeNetworkSource;
edgeFeatureSource.UsesSubtypes = true;
edgeFeatureSource.set_SubtypeConnectivityGroup(1, 1);
edgeFeatureSource.set_SubtypeConnectivityPolicy(1,
esriNetworkEdgeConnectivityPolicy.esriNECPEndVertex);
edgeFeatureSource.set_SubtypeConnectivityGroup(2, 1);
edgeFeatureSource.set_SubtypeConnectivityPolicy(2,
esriNetworkEdgeConnectivityPolicy.esriNECPEndVertex);
edgeFeatureSource.set_SubtypeConnectivityGroup(3, 1);
edgeFeatureSource.set_SubtypeConnectivityPolicy(3,
esriNetworkEdgeConnectivityPolicy.esriNECPAnyVertex);
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: FULL_NAME
Streets:
Street Name Fields:
Primary:
Name: FULL_NAME
The following directions settings will be used when creating a new StreetNameFields object. This object will be added to the EdgeFeatureSource object created previously:
[VB.NET]
' Create a StreetNameFields object and populate its settings.
Dim snf As IStreetNameFields = New StreetNameFields
With snf
.Priority = 1 'Priority 1 indicates the primary street name.
.StreetNameFieldName = "FULL_NAME"
End With
' Add the StreetNameFields object to a new NetworkSourceDirections object,
' then add it to the EdgeFeatureSource created earlier.
Dim nsd As INetworkSourceDirections = New NetworkSourceDirections
Dim snfArray As IArray = New ESRI.ArcGIS.esriSystem.Array
snfArray.Add(snf)
nsd.StreetNameFields = snfArray
edgeNetSource.NetworkSourceDirections = nsd
[C#]
// Create a StreetNameFields object and populate its settings.
IStreetNameFields streetNameFields = new StreetNameFieldsClass();
streetNameFields.Priority = 1; // Indicates the primary street name.
streetNameFields.StreetNameFieldName = "FULL_NAME";
// Add the StreetNameFields object to a new NetworkSourceDirections object,
// then add it to the EdgeFeatureSource created earlier.
INetworkSourceDirections nsDirections = new NetworkSourceDirectionsClass();
IArray nsdArray = new ArrayClass();
nsdArray.Add(streetNameFields);
nsDirections.StreetNameFields = nsdArray;
edgeNetworkSource.NetworkSourceDirections = nsDirections;
The network dataset will have a turn feature source referencing the ParisTurns feature class. Specify on the data element that the network dataset supports turns, then create the TurnFeatureSource object. See the following code:
[VB.NET]
deND.SupportsTurns = True
' Create a new TurnFeatureSource object and point it to the ParisTurns feature class.
Dim turnNetSource As INetworkSource = New TurnFeatureSource
turnNetSource.Name = "ParisTurns"
turnNetSource.ElementType = esriNETTurn
[C#]
deNetworkDataset.SupportsTurns = true;
// Create a new TurnFeatureSource object and point it to the ParisTurns feature class.
INetworkSource turnNetworkSource = new TurnFeatureSourceClass();
turnNetworkSource.Name = "ParisTurns";
turnNetworkSource.ElementType = 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:
[VB.NET]
Dim sourceArray As IArray = New ESRI.ArcGIS.esriSystem.Array
With sourceArray
.Add(edgeNetSource)
.Add(turnNetSource)
End With
deND.Sources = sourceArray
[C#]
IArray sourceArray = new ArrayClass();
sourceArray.Add(edgeNetworkSource);
sourceArray.Add(turnNetworkSource);
deNetworkDataset.Sources = sourceArray;
The network dataset will be created with five network attributes:
- Oneway network attribute
- Minutes network attribute
- Meters network attribute
- RoadClass network attribute
- TurnRestriction network attribute
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:
[VB.NET]
Dim attrArray As IArray = New ESRI.ArcGIS.esriSystem.Array
[C#]
IArray attributeArray = new ArrayClass();
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
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:
[VB.NET]
' Create a new EvaluatedNetworkAttribute object and populate its settings.
Dim evalNetAttr As IEvaluatedNetworkAttribute = New EvaluatedNetworkAttribute
Dim netAttr2 As INetworkAttribute2 = CType(evalNetAttr, INetworkAttribute2)
With netAttr2
.Name = "Oneway"
.UsageType = esriNAUTRestriction
.DataType = esriNADTBoolean
.Units = esriNAUUnknown
.UseByDefault = True
End With
' Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
Dim netFieldEval As INetworkFieldEvaluator = New NetworkFieldEvaluator
netFieldEval.SetExpression("restricted", _
"restricted = False" & vbNewLine & _
"Select Case UCase([Oneway])" & vbNewLine & _
" Case ""N"", ""TF"", ""T"": restricted = True" & vbNewLine & _
"End Select")
evalNetAttr.Evaluator(edgeNetSource, esriNEDAlongDigitized) = netFieldEval
netFieldEval = New NetworkFieldEvaluator
netFieldEval.SetExpression("restricted", _
"restricted = False" & vbNewLine & _
"Select Case UCase([Oneway])" & vbNewLine & _
" Case ""N"", ""FT"", ""F"": restricted = True" & vbNewLine & _
"End Select")
evalNetAttr.Evaluator(edgeNetSource, esriNEDAgainstDigitized) = netFieldEval
Dim netConstEval As INetworkConstantEvaluator = New NetworkConstantEvaluator
netConstEval.ConstantValue = False 'False means Traversable (that is, not restricted).
evalNetAttr.DefaultEvaluator(esriNETEdge) = netConstEval
evalNetAttr.DefaultEvaluator(esriNETJunction) = netConstEval
evalNetAttr.DefaultEvaluator(esriNETTurn) = netConstEval
' Add the attribute to the array.
attrArray.Add(evalNetAttr)
[C#]
// Create a new EvaluatedNetworkAttribute object and populate its settings.
IEvaluatedNetworkAttribute oneWayAttribute = new EvaluatedNetworkAttributeClass();
INetworkAttribute2 oneWayNetworkAttribute2 = (INetworkAttribute2)oneWayAttribute;
oneWayNetworkAttribute2.Name = "Oneway";
oneWayNetworkAttribute2.UsageType =
esriNetworkAttributeUsageType.esriNAUTRestriction;
oneWayNetworkAttribute2.DataType = esriNetworkAttributeDataType.esriNADTBoolean;
oneWayNetworkAttribute2.Units = esriNetworkAttributeUnits.esriNAUUnknown;
oneWayNetworkAttribute2.UseByDefault = true;
// Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
INetworkFieldEvaluator oneWayToFromNetworkFieldEvaluator = new
NetworkFieldEvaluatorClass();
INetworkEvaluator oneWayToFromNetworkEvaluator = (INetworkEvaluator)
oneWayToFromNetworkFieldEvaluator;
oneWayToFromNetworkFieldEvaluator.SetExpression("restricted",
"restricted = False\n\rSelect Case UCase([Oneway])\n\r Case \"N\", \"TF\", \"T\": restricted = True\n\rEnd Select");
oneWayAttribute.set_Evaluator(edgeNetworkSource,
esriNetworkEdgeDirection.esriNEDAlongDigitized, oneWayToFromNetworkEvaluator);
INetworkFieldEvaluator oneWayFromToNetworkFieldEvaluator = new
NetworkFieldEvaluatorClass();
INetworkEvaluator oneWayFromToNetworkEvaluator = (INetworkEvaluator)
oneWayFromToNetworkFieldEvaluator;
oneWayFromToNetworkFieldEvaluator.SetExpression("restricted",
"restricted = False\n\rSelect Case UCase([Oneway])\n\r Case \"N\", \"FT\", \"F\": restricted = True\n\rEnd Select");
oneWayAttribute.set_Evaluator(edgeNetworkSource,
esriNetworkEdgeDirection.esriNEDAgainstDigitized, oneWayFromToNetworkEvaluator);
INetworkConstantEvaluator oneWayNetworkConstantEvaluator = new
NetworkConstantEvaluatorClass();
INetworkEvaluator oneWayConstantNetworkEvaluator = (INetworkEvaluator)
oneWayNetworkConstantEvaluator;
oneWayNetworkConstantEvaluator.ConstantValue = false; // False = traversable
oneWayAttribute.set_DefaultEvaluator(esriNetworkElementType.esriNETEdge,
oneWayConstantNetworkEvaluator);
oneWayAttribute.set_DefaultEvaluator(esriNetworkElementType.esriNETJunction,
oneWayConstantNetworkEvaluator);
oneWayAttribute.set_DefaultEvaluator(esriNetworkElementType.esriNETTurn,
oneWayConstantNetworkEvaluator);
// Add the attribute to the array.
attributeArray.Add(oneWayAttribute);
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: True
Source Attribute Evaluators:
Streets (From-To): Field - [FT_Minutes]
Streets (To-From): Field - [TF_Minutes]
Default Attribute Evaluators:
Default Edges: Constant - 0
Default Junctions: Constant - 0
Default Turns: Constant - 0
Usage Type: Cost
Data Type: Double
Units Type: Minutes
Use by Default: True
Source Attribute Evaluators:
Streets (From-To): Field - [FT_Minutes]
Streets (To-From): Field - [TF_Minutes]
Default Attribute Evaluators:
Default Edges: Constant - 0
Default Junctions: Constant - 0
Default Turns: Constant - 0
See the following code:
[VB.NET]
' Create a new EvaluatedNetworkAttribute object and populate its settings.
evalNetAttr = New EvaluatedNetworkAttribute
netAttr2 = CType(evalNetAttr, INetworkAttribute2)
With netAttr2
.Name = "Minutes"
.UsageType = esriNAUTCost
.DataType = esriNADTDouble
.Units = esriNAUMinutes
.UseByDefault = True
End With
' Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
netFieldEval = New NetworkFieldEvaluator
netFieldEval.SetExpression("[FT_Minutes]", "")
evalNetAttr.Evaluator(edgeNetSource, esriNEDAlongDigitized) = netFieldEval
netFieldEval = New NetworkFieldEvaluator
netFieldEval.SetExpression("[TF_Minutes]", "")
evalNetAttr.Evaluator(edgeNetSource, esriNEDAgainstDigitized) = netFieldEval
netConstEval = New NetworkConstantEvaluator
netConstEval.ConstantValue = 0
evalNetAttr.DefaultEvaluator(esriNETEdge) = netConstEval
evalNetAttr.DefaultEvaluator(esriNETJunction) = netConstEval
evalNetAttr.DefaultEvaluator(esriNETTurn) = netConstEval
' Add the attribute to the array.
attrArray.Add(evalNetAttr)
[C#]
// Create a new EvaluatedNetworkAttribute object and populate its settings.
IEvaluatedNetworkAttribute minutesAttribute = new EvaluatedNetworkAttributeClass();
INetworkAttribute2 minutesNetworkAttribute2 = (INetworkAttribute2)minutesAttribute;
minutesNetworkAttribute2.Name = "Minutes";
minutesNetworkAttribute2.UsageType = esriNetworkAttributeUsageType.esriNAUTCost;
minutesNetworkAttribute2.DataType = esriNetworkAttributeDataType.esriNADTDouble;
minutesNetworkAttribute2.Units = esriNetworkAttributeUnits.esriNAUMinutes;
minutesNetworkAttribute2.UseByDefault = true;
// Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
INetworkFieldEvaluator ftMinutesNetworkFieldEvaluator = new
NetworkFieldEvaluatorClass();
INetworkEvaluator ftMinutesNetworkEvaluator = (INetworkEvaluator)
ftMinutesNetworkFieldEvaluator;
ftMinutesNetworkFieldEvaluator.SetExpression("[FT_Minutes]", "");
minutesAttribute.set_Evaluator(edgeNetworkSource,
esriNetworkEdgeDirection.esriNEDAlongDigitized, ftMinutesNetworkEvaluator);
INetworkFieldEvaluator tfMinutesNetworkFieldEvaluator = new
NetworkFieldEvaluatorClass();
INetworkEvaluator tfMinutesNetworkEvaluator = (INetworkEvaluator)
tfMinutesNetworkFieldEvaluator;
tfMinutesNetworkFieldEvaluator.SetExpression("[TF_Minutes]", "");
minutesAttribute.set_Evaluator(edgeNetworkSource,
esriNetworkEdgeDirection.esriNEDAgainstDigitized, tfMinutesNetworkEvaluator);
INetworkConstantEvaluator minutesNetworkConstantEvaluator = new
NetworkConstantEvaluatorClass();
INetworkEvaluator minutesConstantNetworkEvaluator = (INetworkEvaluator)
minutesNetworkConstantEvaluator;
minutesNetworkConstantEvaluator.ConstantValue = 0;
minutesAttribute.set_DefaultEvaluator(esriNetworkElementType.esriNETEdge,
minutesConstantNetworkEvaluator);
minutesAttribute.set_DefaultEvaluator(esriNetworkElementType.esriNETJunction,
minutesConstantNetworkEvaluator);
minutesAttribute.set_DefaultEvaluator(esriNetworkElementType.esriNETTurn,
minutesConstantNetworkEvaluator);
// Add the attribute to the array.
attributeArray.Add(minutesAttribute);
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
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:
[VB.NET]
' Create a new EvaluatedNetworkAttribute object and populate its settings.
evalNetAttr = New EvaluatedNetworkAttribute
netAttr2 = CType(evalNetAttr, INetworkAttribute2)
With netAttr2
.Name = "Meters"
.UsageType = esriNAUTCost
.DataType = esriNADTDouble
.Units = esriNAUMeters
.UseByDefault = False
End With
' Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
netFieldEval = New NetworkFieldEvaluator
netFieldEval.SetExpression("[Meters]", "")
evalNetAttr.Evaluator(edgeNetSource, esriNEDAlongDigitized) = netFieldEval
evalNetAttr.Evaluator(edgeNetSource, esriNEDAgainstDigitized) = netFieldEval
netConstEval = New NetworkConstantEvaluator
netConstEval.ConstantValue = 0
evalNetAttr.DefaultEvaluator(esriNETEdge) = netConstEval
evalNetAttr.DefaultEvaluator(esriNETJunction) = netConstEval
evalNetAttr.DefaultEvaluator(esriNETTurn) = netConstEval
' Add the attribute to the array.
attrArray.Add(evalNetAttr)
[C#]
// Create a new EvaluatedNetworkAttribute object and populate its settings.
IEvaluatedNetworkAttribute metersAttribute = new EvaluatedNetworkAttributeClass();
INetworkAttribute2 metersNetworkAttribute2 = (INetworkAttribute2)metersAttribute;
metersNetworkAttribute2.Name = "Meters";
metersNetworkAttribute2.UsageType = esriNetworkAttributeUsageType.esriNAUTCost;
metersNetworkAttribute2.DataType = esriNetworkAttributeDataType.esriNADTDouble;
metersNetworkAttribute2.Units = esriNetworkAttributeUnits.esriNAUMeters;
metersNetworkAttribute2.UseByDefault = false;
// Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
INetworkFieldEvaluator metersNetworkFieldEvaluator = new NetworkFieldEvaluatorClass()
;
INetworkEvaluator metersNetworkEvaluator = (INetworkEvaluator)
metersNetworkFieldEvaluator;
metersNetworkFieldEvaluator.SetExpression("[Meters]", "");
metersAttribute.set_Evaluator(edgeNetworkSource,
esriNetworkEdgeDirection.esriNEDAlongDigitized, metersNetworkEvaluator);
metersAttribute.set_Evaluator(edgeNetworkSource,
esriNetworkEdgeDirection.esriNEDAgainstDigitized, metersNetworkEvaluator);
INetworkConstantEvaluator metersNetworkConstantEvaluator = new
NetworkConstantEvaluatorClass();
INetworkEvaluator metersConstantNetworkEvaluator = (INetworkEvaluator)
metersNetworkConstantEvaluator;
metersNetworkConstantEvaluator.ConstantValue = 0;
metersAttribute.set_DefaultEvaluator(esriNetworkElementType.esriNETEdge,
metersConstantNetworkEvaluator);
metersAttribute.set_DefaultEvaluator(esriNetworkElementType.esriNETJunction,
metersConstantNetworkEvaluator);
metersAttribute.set_DefaultEvaluator(esriNetworkElementType.esriNETTurn,
metersConstantNetworkEvaluator);
// Add the attribute to the array.
attributeArray.Add(metersAttribute);
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
Select Case UCase([CFCC])
Case "A10", "A11", "A12", "A13", "A14", "A15", "A16", "A17", "A18", "A19"
rc = 2 'Highway
Case "A60", "A63"
rc = 3 'Ramp
Case "A65", "A66", "A68", "A69"
rc = 4 'Ferry
Case "A62"
rc = 5 'Roundabout
End Select
Expression: rc
Streets (To-From): Field -
Prelogic:
rc = 1 'Local road
Select Case UCase([CFCC])
Case "A10", "A11", "A12", "A13", "A14", "A15", "A16", "A17", "A18", "A19"
rc = 2 'Highway
Case "A60", "A63"
rc = 3 'Ramp
Case "A65", "A66", "A68", "A69"
rc = 4 'Ferry
Case "A62"
rc = 5 'Roundabout
End Select
Expression: rc
Default Attribute Evaluators:
Default Edges: Constant - 0
Default Junctions: Constant - 0
Default Turns: Constant - 0
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
Select Case UCase([CFCC])
Case "A10", "A11", "A12", "A13", "A14", "A15", "A16", "A17", "A18", "A19"
rc = 2 'Highway
Case "A60", "A63"
rc = 3 'Ramp
Case "A65", "A66", "A68", "A69"
rc = 4 'Ferry
Case "A62"
rc = 5 'Roundabout
End Select
Expression: rc
Streets (To-From): Field -
Prelogic:
rc = 1 'Local road
Select Case UCase([CFCC])
Case "A10", "A11", "A12", "A13", "A14", "A15", "A16", "A17", "A18", "A19"
rc = 2 'Highway
Case "A60", "A63"
rc = 3 'Ramp
Case "A65", "A66", "A68", "A69"
rc = 4 'Ferry
Case "A62"
rc = 5 'Roundabout
End Select
Expression: rc
Default Attribute Evaluators:
Default Edges: Constant - 0
Default Junctions: Constant - 0
Default Turns: Constant - 0
See the following code:
[VB.NET]
' Create a new EvaluatedNetworkAttribute object and populate its settings.
evalNetAttr = New EvaluatedNetworkAttribute
netAttr2 = CType(evalNetAttr, INetworkAttribute2)
With netAttr2
.Name = "RoadClass"
.UsageType = esriNAUTDescriptor
.DataType = esriNADTInteger
.Units = esriNAUUnknown
.UseByDefault = False
End With
' Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
netFieldEval = New NetworkFieldEvaluator
netFieldEval.SetExpression("rc", _
"rc = 1 'Local road" & vbNewLine & _
"Select Case UCase([CFCC])" & vbNewLine & _
" Case ""A10"", ""A11"", ""A12"", ""A13"", ""A14"", ""A15"", ""A16"", ""A17"", ""A18"", ""A19""" & vbNewLine & _
" rc = 2 'Highway" & vbNewLine & _
" Case ""A60"", ""A63""" & vbNewLine & _
" rc = 3 'Ramp" & vbNewLine & _
" Case ""A65"", ""A66"", ""A68"", ""A69""" & vbNewLine & _
" rc = 4 'Ferry" & vbNewLine & _
" Case ""A62""" & vbNewLine & _
" rc = 5 'Roundabout" & vbNewLine & _
"End Select")
evalNetAttr.Evaluator(edgeNetSource, esriNEDAlongDigitized) = netFieldEval
evalNetAttr.Evaluator(edgeNetSource, esriNEDAgainstDigitized) = netFieldEval
netConstEval = New NetworkConstantEvaluator
netConstEval.ConstantValue = 0
evalNetAttr.DefaultEvaluator(esriNETEdge) = netConstEval
evalNetAttr.DefaultEvaluator(esriNETJunction) = netConstEval
evalNetAttr.DefaultEvaluator(esriNETTurn) = netConstEval
' Add the attribute to the array.
attrArray.Add(evalNetAttr)
[C#]
// Create a new EvaluatedNetworkAttribute object and populate its settings.
IEvaluatedNetworkAttribute roadClassAttribute = new EvaluatedNetworkAttributeClass();
INetworkAttribute2 roadClassNetworkAttribute2 = (INetworkAttribute2)
roadClassAttribute;
roadClassNetworkAttribute2.Name = "RoadClass";
roadClassNetworkAttribute2.UsageType =
esriNetworkAttributeUsageType.esriNAUTDescriptor;
roadClassNetworkAttribute2.DataType = esriNetworkAttributeDataType.esriNADTInteger;
roadClassNetworkAttribute2.Units = esriNetworkAttributeUnits.esriNAUUnknown;
roadClassNetworkAttribute2.UseByDefault = false;
// Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
INetworkFieldEvaluator roadClassNetworkFieldEvaluator = new
NetworkFieldEvaluatorClass();
INetworkEvaluator roadClassNetworkEvaluator = (INetworkEvaluator)
roadClassNetworkFieldEvaluator;
roadClassNetworkFieldEvaluator.SetExpression("rc",
"rc = 1 'Local road\n\rSelect Case UCase([CFCC])\n\r" +
" Case \"A10\", \"A11\", \"A12\", \"A13\", \"A14\", \"A15\", \"A16\", \"A17\", \"A18\", \"A19\"\n\r" + " rc = 2 'Highway\n\r" + " Case \"A60\", \"A63\"\n\r" + " rc = 3 'Ramp\n\r" + " Case \"A65\", \"A66\", \"A68\", \"A69\"\n\r" + " rc = 4 'Ferry\n\r" + " Case \"A62\"\n\r" + " rc = 5 'Roundabout\n\r" + "End Select");
roadClassAttribute.set_Evaluator(edgeNetworkSource,
esriNetworkEdgeDirection.esriNEDAlongDigitized, roadClassNetworkEvaluator);
roadClassAttribute.set_Evaluator(edgeNetworkSource,
esriNetworkEdgeDirection.esriNEDAgainstDigitized, roadClassNetworkEvaluator);
INetworkConstantEvaluator roadClassNetworkConstantEvaluator = new
NetworkConstantEvaluatorClass();
INetworkEvaluator roadClassConstantNetworkEvaluator = (INetworkEvaluator)
roadClassNetworkConstantEvaluator;
roadClassNetworkConstantEvaluator.ConstantValue = 0;
roadClassAttribute.set_DefaultEvaluator(esriNetworkElementType.esriNETEdge,
roadClassConstantNetworkEvaluator);
roadClassAttribute.set_DefaultEvaluator(esriNetworkElementType.esriNETJunction,
roadClassConstantNetworkEvaluator);
roadClassAttribute.set_DefaultEvaluator(esriNetworkElementType.esriNETTurn,
roadClassConstantNetworkEvaluator);
// Add the attribute to the array.
attributeArray.Add(roadClassAttribute);
The following is from the New Network Dataset wizard's summary for the TurnRestriction network attribute:
TurnRestriction:
Usage Type: Restriction
Data Type: Boolean
Units Type: Unknown
Use by Default: True
Source Attribute Evaluators:
ParisTurns: Constant - Restricted
Default Attribute Evaluators:
Default Edges: Constant - Traversable
Default Junctions: Constant - Traversable
Default Turns: Constant - Traversable
Usage Type: Restriction
Data Type: Boolean
Units Type: Unknown
Use by Default: True
Source Attribute Evaluators:
ParisTurns: Constant - Restricted
Default Attribute Evaluators:
Default Edges: Constant - Traversable
Default Junctions: Constant - Traversable
Default Turns: Constant - Traversable
See the following code:
[VB.NET]
' Create a new EvaluatedNetworkAttribute object and populate its settings.
evalNetAttr = New EvaluatedNetworkAttribute
netAttr2 = CType(evalNetAttr, INetworkAttribute2)
With netAttr2
.Name = "TurnRestriction"
.UsageType = esriNAUTRestriction
.DataType = esriNADTBoolean
.Units = esriNAUUnknown
.UseByDefault = True
End With
' Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
netConstEval = New NetworkConstantEvaluator
netConstEval.ConstantValue = True 'True means Restricted.
evalNetAttr.Evaluator(turnNetSource, esriNEDNone) = netConstEval
netConstEval = New NetworkConstantEvaluator
netConstEval.ConstantValue = False 'False means Traversable (that is, not restricted).
evalNetAttr.DefaultEvaluator(esriNETEdge) = netConstEval
evalNetAttr.DefaultEvaluator(esriNETJunction) = netConstEval
evalNetAttr.DefaultEvaluator(esriNETTurn) = netConstEval
' Add the attribute to the array.
attrArray.Add(evalNetAttr)
[C#]
// Create a new EvaluatedNetworkAttribute object and populate its settings.
IEvaluatedNetworkAttribute turnAttribute = new EvaluatedNetworkAttributeClass();
INetworkAttribute2 turnNetworkAttribute2 = (INetworkAttribute2)turnAttribute;
turnNetworkAttribute2.Name = "TurnRestriction";
turnNetworkAttribute2.UsageType = esriNetworkAttributeUsageType.esriNAUTDescriptor;
turnNetworkAttribute2.DataType = esriNetworkAttributeDataType.esriNADTInteger;
turnNetworkAttribute2.Units = esriNetworkAttributeUnits.esriNAUUnknown;
turnNetworkAttribute2.UseByDefault = false;
INetworkConstantEvaluator turnTrueNetworkConstantEvaluator = new
NetworkConstantEvaluatorClass();
INetworkEvaluator turnTrueNetworkEvaluator = (INetworkEvaluator)
turnTrueNetworkConstantEvaluator;
turnTrueNetworkConstantEvaluator.ConstantValue = true;
turnAttribute.set_Evaluator(turnNetworkSource, esriNetworkEdgeDirection.esriNEDNone,
turnTrueNetworkEvaluator);
INetworkConstantEvaluator turnFalseNetworkConstantEvaluator = new
NetworkConstantEvaluatorClass();
INetworkEvaluator turnFalseNetworkEvaluator = (INetworkEvaluator)
turnFalseNetworkConstantEvaluator;
turnFalseNetworkConstantEvaluator.ConstantValue = false;
turnAttribute.set_DefaultEvaluator(esriNetworkElementType.esriNETEdge,
turnFalseNetworkEvaluator);
turnAttribute.set_DefaultEvaluator(esriNetworkElementType.esriNETJunction,
turnFalseNetworkEvaluator);
turnAttribute.set_DefaultEvaluator(esriNetworkElementType.esriNETTurn,
turnFalseNetworkEvaluator);
// Add the attribute to the array.
attributeArray.Add(turnAttribute);
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:
[VB.NET]
deND.Attributes = attrArray
[C#]
deNetworkDataset.Attributes = attributeArray;
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.
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
Road Class Attribute: RoadClass
Display Length Units: Miles
Length Attribute: Meters
Time Attribute: Minutes
Road Class Attribute: RoadClass
These directions settings will be used when creating a new NetworkDirections object, then the object will be added to the network dataset data element object. See the following code:
[VB.NET]
' Create a NetworkDirections object and populate its settings.
Dim netDirections As INetworkDirections = New NetworkDirections
With netDirections
.DefaultOutputLengthUnits = esriNAUMiles
.LengthAttributeName = "Meters"
.TimeAttributeName = "Minutes"
.RoadClassAttributeName = "RoadClass"
End With
' Add the NetworkDirections object to the network dataset data element.
deND.Directions = netDirections
[C#]
// Create a NetworkDirections object and populate its settings.
INetworkDirections networkDirections = new NetworkDirectionsClass();
networkDirections.DefaultOutputLengthUnits = esriNetworkAttributeUnits.esriNAUMeters;
networkDirections.LengthAttributeName = "Meters";
networkDirections.TimeAttributeName = "Minutes";
networkDirections.RoadClassAttributeName = "RoadClass";
// Add the NetworkDirections object to the network dataset data element.
deNetworkDataset.Directions = networkDirections;
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:
[VB.NET]
' Get the feature dataset extension and create the network dataset based on the data element.
Dim fdxc As IFeatureDatasetExtensionContainer = CType(fdsGDS, IFeatureDatasetExtensionContainer)
Dim fdx As IFeatureDatasetExtension = fdxc.FindExtension(esriDTNetworkDataset)
Dim dsc2 As IDatasetContainer2 = CType(fdx, IDatasetContainer2)
Dim netDataset As INetworkDataset = CType(dsc2.CreateDataset(deND), INetworkDataset)
' Once the network dataset is created, build it.
Dim netBuild As INetworkBuild = CType(netDataset, INetworkBuild)
netBuild.BuildNetwork(fdsGDS.Extent)
[C#]
// Get the feature dataset extension and create the network dataset based on the data element.
IFeatureDatasetExtensionContainer fdxContainer = (IFeatureDatasetExtensionContainer)
featureDataset;
IFeatureDatasetExtension fdExtension = fdxContainer.FindExtension
(esriDatasetType.esriDTNetworkDataset);
IDatasetContainer2 datasetContainer2 = (IDatasetContainer2)fdExtension;
IDEDataset deDataset = (IDEDataset)deNetworkDataset;
INetworkDataset networkDataset = (INetworkDataset)datasetContainer2.CreateDataset
(deDataset);
// Once the network dataset is created, build it.
INetworkBuild networkBuild = (INetworkBuild)networkDataset;
networkBuild.BuildNetwork(geoDataset.Extent);