In this topic
- Creating a network dataset data element
- Adding network sources
- Specifying connectivity settings for the edge and junction source
- Specifying directions settings for the edge source
- Specifying global turns
- Adding network attributes
- Oneway network attribute
- DriveTime network attribute
- Meters network attribute
- RoadClass network attribute
- PedestrianTime network attribute
- Specifying directions settings
- Creating and building the network dataset
Creating a network dataset data element
The network dataset being created is based on the Paris.gdb file geodatabase data located in the ArcGIS Network Analyst extension tutorial. 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 ParisMultimodal_ND.
This topic uses the geodatabase file, Paris.gdb, which is installed in the C:\arcgis\ArcTutor\Network_Analyst\Tutorial\Exercise02 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:
- Create an empty data element for a buildable network dataset.
- Open the feature dataset and CType to the IGeoDataset interface.
- Copy the feature dataset's extent and spatial reference to the network dataset data element.
- Name the network dataset, ParisMultimodal_ND. See the following code example:
//Create an empty data element for a buildable network dataset.
IDENetworkDataset deND = new DENetworkDataset();
deND.setBuildable(true);
//Open the shapefile and cast to the IGeoDataset interface.
IWorkspaceFactory gdbWSF = new ShapefileWorkspaceFactory();
IFeatureWorkspace gdbFWS = new IFeatureWorkspaceProxy(gdbWSF.openFromFile(
"C:\\Program Files\\ArcGIS\\DeveloperKit10.0\\SamplesNET\\data\\CreateNetworkDataset\\ParisMultimodal.gdb", 0));
IGeoDataset fdsGDS = new IGeoDatasetProxy(gdbFWS.openFeatureDataset(
"Multimodal_Network"));
//Copy the feature dataset's extent and spatial reference to the network dataset data element.
IDEGeoDataset deGDS = (IDEGeoDataset)deND;
deGDS.setExtentByRef(fdsGDS.getExtent());
deGDS.setSpatialReferenceByRef(fdsGDS.getSpatialReference());
//Specify the name of the network dataset.
IDataElement dataElement = (IDataElement)deND;
dataElement.setName("ParisMultiNet");
Adding network sources
The network dataset will be created with six network sources, four line feature classes, and two point feature classes. The line feature classes become edge sources in the network dataset and the point feature classes become junction sources:
Sources:
Edge Sources:
Metro_Lines
Streets
Transfer_Stations
Transfer_Street_Station
Junction Sources:
Metro_Entrances
Metro_Stations
Edge Sources:
Metro_Lines
Streets
Transfer_Stations
Transfer_Street_Station
Junction Sources:
Metro_Entrances
Metro_Stations
Specifying connectivity settings for the edge and junction source
The feature classes need to be an edge and a junction 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:
Metro_Lines (End Point)
Transfer_Stations (End Point)
Transfer_Street_Station (End Point)
Junction Connectivity - Transfer Groups {2}:
Metro_Entrances (Override) - Transfer Groups {2}
Metro_Stations (Honor)
Group 2:
Edge Connectivity:
Streets (End Point)
Junction Connectivity - Transfer Groups {1}:
Metro_Entrances (Override) - Transfer Groups {1}
Group 1:
Edge Connectivity:
Metro_Lines (End Point)
Transfer_Stations (End Point)
Transfer_Street_Station (End Point)
Junction Connectivity - Transfer Groups {2}:
Metro_Entrances (Override) - Transfer Groups {2}
Metro_Stations (Honor)
Group 2:
Edge Connectivity:
Streets (End Point)
Junction Connectivity - Transfer Groups {1}:
Metro_Entrances (Override) - Transfer Groups {1}
Use these connectivity settings when creating EdgeFeatureSource and JunctionFeatureSource objects. See the following code example:
[Java]
//Create anEdgeFeatureSource object and point it to the Streets feature class.
INetworkSource streetsNetSource = new EdgeFeatureSource();
streetsNetSource.setName("Streets");
streetsNetSource.setElementType(esriNetworkElementType.esriNETEdge);
//Set the edge feature source's connectivity settings.
IEdgeFeatureSource edgeFS = (IEdgeFeatureSource)streetsNetSource;
edgeFS.setUsesSubtypes(false);
edgeFS.setClassConnectivityGroup(2);
edgeFS.setClassConnectivityPolicy
(esriNetworkEdgeConnectivityPolicy.esriNECPEndVertex);
//Create an EdgeFeatureSource object and point it to the Metro_Lines feature class.
INetworkSource metroNetSource = new EdgeFeatureSource();
metroNetSource.setName("Metro_Lines");
metroNetSource.setElementType(esriNetworkElementType.esriNETEdge);
//Set the edge feature source's connectivity settings.
edgeFS = (IEdgeFeatureSource)metroNetSource;
edgeFS.setUsesSubtypes(false);
edgeFS.setClassConnectivityGroup(1);
edgeFS.setClassConnectivityPolicy
(esriNetworkEdgeConnectivityPolicy.esriNECPEndVertex);
//Create an EdgeFeatureSource object and point it to the Transfer_Stations feature class.
INetworkSource tsNetSource = new EdgeFeatureSource();
tsNetSource.setName("Transfer_Stations");
tsNetSource.setElementType(esriNetworkElementType.esriNETEdge);
//Set the edge feature source's connectivity settings.
edgeFS = (IEdgeFeatureSource)tsNetSource;
edgeFS.setUsesSubtypes(false);
edgeFS.setClassConnectivityGroup(1);
edgeFS.setClassConnectivityPolicy
(esriNetworkEdgeConnectivityPolicy.esriNECPEndVertex);
//Create an EdgeFeatureSource object and point it to the Transfer_Street_Station feature class.
INetworkSource tssNetSource = new EdgeFeatureSource();
tssNetSource.setName("Transfer_Street_Station");
tssNetSource.setElementType(esriNetworkElementType.esriNETEdge);
//Set the edge feature source's connectivity settings.
edgeFS = (IEdgeFeatureSource)tssNetSource;
edgeFS.setUsesSubtypes(false);
edgeFS.setClassConnectivityGroup(1);
edgeFS.setClassConnectivityPolicy
(esriNetworkEdgeConnectivityPolicy.esriNECPEndVertex);
//Create a JunctionFeatureSource object and point it to the Metro_Stations feature class.
INetworkSource stationsNetSource = new JunctionFeatureSource();
stationsNetSource.setName("Metro_Stations");
stationsNetSource.setElementType(esriNetworkElementType.esriNETJunction);
//Set the junction feature source's connectivity settings.
IJunctionFeatureSource junctionFS = (IJunctionFeatureSource)stationsNetSource;
junctionFS.setUsesSubtypes(false);
junctionFS.removeAllClassConnectivityGroups();
junctionFS.addClassConnectivityGroup(1);
junctionFS.setClassConnectivityPolicy
(esriNetworkJunctionConnectivityPolicy.esriNJCPHonor);
//Create a JunctionFeatureSource object and point it to the Metro_Entrances feature class.
INetworkSource entrancesNetSource = new JunctionFeatureSource();
entrancesNetSource.setName("Metro_Entrances");
entrancesNetSource.setElementType(esriNetworkElementType.esriNETJunction);
//Set the junction feature source's connectivity settings.
junctionFS = (IJunctionFeatureSource)entrancesNetSource;
junctionFS.setUsesSubtypes(false);
junctionFS.removeAllClassConnectivityGroups();
junctionFS.addClassConnectivityGroup(1);
junctionFS.addClassConnectivityGroup(2);
junctionFS.setClassConnectivityPolicy
(esriNetworkJunctionConnectivityPolicy.esriNJCPOverride);
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:
Metro_Lines:
Street Name Fields:
Primary:
Name: NAME
Streets:
Street Name Fields:
Primary:
Name: FULL_NAME
Transfer_Stations:
Street Name Fields:
Primary:
Name: NAME
Metro_Lines:
Street Name Fields:
Primary:
Name: NAME
Streets:
Street Name Fields:
Primary:
Name: FULL_NAME
Transfer_Stations:
Street Name Fields:
Primary:
Name: NAME
The previous settings are the ones to specify and the following code example shows how to implement these settings using ArcObjects:
[Java]
//Create a StreetNameFields object and populate its settings for the Streets source.
IStreetNameFields snf = new StreetNameFields();
snf.setPriority(1); //Priority 1 indicates the primary street name.
snf.setStreetNameFieldName("FULL_NAME");
//Add the StreetNameFields object to a new NetworkSourceDirections object,
//then add it to the EdgeFeatureSource object created earlier.
INetworkSourceDirections nsd = new NetworkSourceDirections();
IArray snfArray = new Array();
snfArray.add(snf);
nsd.setStreetNameFieldsByRef(snfArray);
streetsNetSource.setNetworkSourceDirectionsByRef(nsd);
//Create a StreetNameFields object and populate its settings
//for the Metro_Lines and Transfer_Stations sources.
snf = new StreetNameFields();
snf.setPriority(1); //Priority 1 indicates the primary street name.
snf.setStreetNameFieldName("NAME");
//Add the StreetNameFields object to a new NetworkSourceDirections object,
//then add it to the EdgeFeatureSource object created earlier.
nsd = new NetworkSourceDirections();
snfArray = new Array();
snfArray.add(snf);
nsd.setStreetNameFieldsByRef(snfArray);
metroNetSource.setNetworkSourceDirectionsByRef(nsd);
tsNetSource.setNetworkSourceDirectionsByRef(nsd);
Now that all the source objects 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(streetsNetSource);
sourceArray.add(metroNetSource);
sourceArray.add(tsNetSource);
sourceArray.add(tssNetSource);
sourceArray.add(stationsNetSource);
sourceArray.add(entrancesNetSource);
deND.setSourcesByRef(sourceArray);
Specifying global turns
The network dataset supports global turns, which will be set on the data element. See the following code example:
[Java]
deND.setSupportsTurns(true);
Adding network attributes
The network dataset will be created with five network attributes:
- Oneway network attribute
- DriveTime network attribute
- Meters network attribute
- RoadClass network attribute
- PedestrianTime 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 example:
[Java]
IArray attrArray = new Array();
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
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.
IEvaluatedNetworkAttribute evalNetAttr = new EvaluatedNetworkAttribute();
INetworkAttribute2 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.
INetworkFieldEvaluator 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.setEvaluator(edgeNetSource,
esriNetworkEdgeDirection.esriNEDAlongDigitized, 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.setEvaluator(edgeNetSource,
esriNetworkEdgeDirection.esriNEDAgainstDigitized, netFieldEval);
INetworkConstantEvaluator netConstEval = new NetworkConstantEvaluator();
netConstEval.setConstantValue(false);
//False means Traversable (that is, not restricted).
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETEdge,
(INetworkEvaluator)netConstEval);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETJunction,
(INetworkEvaluator)netConstEval);
evalNetAttr.setDefaultEvaluatorByRef(esriNetworkElementType.esriNETTurn,
(INetworkEvaluator)netConstEval);
//Add the attribute to the array.
attrArray.add(evalNetAttr);
DriveTime network attribute
The following is from the New Network Dataset wizard's summary for the DriveTime network attribute:
DriveTime:
Usage Type: Cost
Data Type: Double
Units Type: Minutes
Use by Default: True
Source Attribute Evaluators:
Metro_Lines (From-To): Constant - -1
Metro_Lines (To-From): Constant - -1
Streets (From-To): Field - [FT_Minutes]
Streets (To-From): Field - [TF_Minutes]
Transfer_Stations (From-To): Constant - -1
Transfer_Stations (To-From): Constant - -1
Transfer_Street_Station (From-To): Constant - -1
Transfer_Street_Station (To-From): Constant - -1
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:
Metro_Lines (From-To): Constant - -1
Metro_Lines (To-From): Constant - -1
Streets (From-To): Field - [FT_Minutes]
Streets (To-From): Field - [TF_Minutes]
Transfer_Stations (From-To): Constant - -1
Transfer_Stations (To-From): Constant - -1
Transfer_Street_Station (From-To): Constant - -1
Transfer_Street_Station (To-From): Constant - -1
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.
IEvaluatedNetworkAttribute evalNetAttr = new EvaluatedNetworkAttribute();
INetworkAttribute2 netAttr2 = (INetworkAttribute2)evalNetAttr;
netAttr2.setName("DriveTime");
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.
INetworkFieldEvaluator netFieldEval = new NetworkFieldEvaluator();
netFieldEval.setExpression("[FT_Minutes]", "");
evalNetAttr.setEvaluator(streetsNetSource,
esriNetworkEdgeDirection.esriNEDAlongDigitized, netFieldEval);
netFieldEval = new NetworkFieldEvaluator();
netFieldEval.setExpression("[TF_Minutes]", "");
evalNetAttr.setEvaluator(streetsNetSource,
esriNetworkEdgeDirection.esriNEDAgainstDigitized, netFieldEval);
INetworkConstantEvaluator netConstEval = new NetworkConstantEvaluator();
netConstEval.setConstantValue( - 1);
//False means Traversable (that is, not restricted).
evalNetAttr.setEvaluator(metroNetSource,
esriNetworkEdgeDirection.esriNEDAlongDigitized, netConstEval);
evalNetAttr.setEvaluator(metroNetSource,
esriNetworkEdgeDirection.esriNEDAgainstDigitized, netConstEval);
evalNetAttr.setEvaluator(tsNetSource, esriNetworkEdgeDirection.esriNEDAlongDigitized,
netConstEval);
evalNetAttr.setEvaluator(tsNetSource,
esriNetworkEdgeDirection.esriNEDAgainstDigitized, netConstEval);
evalNetAttr.setEvaluator(tssNetSource,
esriNetworkEdgeDirection.esriNEDAlongDigitized, netConstEval);
evalNetAttr.setEvaluator(tssNetSource,
esriNetworkEdgeDirection.esriNEDAgainstDigitized, netConstEval);
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.
attrArray.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:
Metro_Lines (From-To): Field - [Meters]
Metro_Lines (To-From): Field - [Meters]
Streets (From-To): Field - [Meters]
Streets (To-From): Field - [Meters]
Transfer_Stations (From-To): Field - [Shape_Length]
Transfer_Stations (To-From): Field - [Shape_Length]
Transfer_Street_Station (From-To): Field - [Shape_Length]
Transfer_Street_Station (To-From): Field - [Shape_Length]
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:
Metro_Lines (From-To): Field - [Meters]
Metro_Lines (To-From): Field - [Meters]
Streets (From-To): Field - [Meters]
Streets (To-From): Field - [Meters]
Transfer_Stations (From-To): Field - [Shape_Length]
Transfer_Stations (To-From): Field - [Shape_Length]
Transfer_Street_Station (From-To): Field - [Shape_Length]
Transfer_Street_Station (To-From): Field - [Shape_Length]
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 EvaluatedNetworkAttributeClass();
netAttr2 = evalNetAttr as INetworkAttribute2;
netAttr2.Name = "Meters";
netAttr2.UsageType = esriNAUTCost;
netAttr2.DataType = esriNADTDouble;
netAttr2.Units = esriNAUMeters;
netAttr2.UseByDefault = false;
// Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
netFieldEval = new NetworkFieldEvaluatorClass();
netFieldEval.SetExpression("[Meters]", "");
evalNetAttr.Evaluator(metroNetSource, esriNEDAlongDigitized) = netFieldEval;
evalNetAttr.Evaluator(metroNetSource, esriNEDAgainstDigitized) = netFieldEval;
evalNetAttr.Evaluator(streetsNetSource, esriNEDAlongDigitized) = netFieldEval;
evalNetAttr.Evaluator(streetsNetSource, esriNEDAgainstDigitized) = netFieldEval;
netFieldEval = new NetworkFieldEvaluatorClass();
netFieldEval.SetExpression("[Shape_Length]", "");
evalNetAttr.Evaluator(tsNetSource, esriNEDAlongDigitized) = netFieldEval;
evalNetAttr.Evaluator(tsNetSource, esriNEDAgainstDigitized) = netFieldEval;
evalNetAttr.Evaluator(tssNetSource, esriNEDAlongDigitized) = netFieldEval;
evalNetAttr.Evaluator(tssNetSource, esriNEDAgainstDigitized) = netFieldEval;
netConstEval = new NetworkConstantEvaluatorClass();
netConstEval.ConstantValue = 0;
evalNetAttr.DefaultEvaluator(esriNETEdge) = netConstEval;
evalNetAttr.DefaultEvaluator(esriNETJunction) = netConstEval;
evalNetAttr.DefaultEvaluator(esriNETTurn) = netConstEval;
// Add the attribute to the array.
attrArray.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
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 example:
[Java]
// Create an EvaluatedNetworkAttribute object and populate its settings.
evalNetAttr = new EvaluatedNetworkAttributeClass();
netAttr2 = evalNetAttr as INetworkAttribute2;
netAttr2.Name = "RoadClass";
netAttr2.UsageType = esriNAUTDescriptor;
netAttr2.DataType = esriNADTInteger;
netAttr2.Units = esriNAUUnknown;
netAttr2.UseByDefault = false;
// Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
netFieldEval = new NetworkFieldEvaluatorClass();
netFieldEval.SetExpression("rc", "rc = 1 'Local road\n\r" +
"Select 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");
evalNetAttr.Evaluator(edgeNetSource, esriNEDAlongDigitized) = netFieldEval;
evalNetAttr.Evaluator(edgeNetSource, esriNEDAgainstDigitized) = netFieldEval;
netConstEval = new NetworkConstantEvaluatorClass();
netConstEval.ConstantValue = 0;
evalNetAttr.DefaultEvaluator(esriNETEdge) = netConstEval;
evalNetAttr.DefaultEvaluator(esriNETJunction) = netConstEval;
evalNetAttr.DefaultEvaluator(esriNETTurn) = netConstEval;
// Add the attribute to the array.
attrArray.Add(evalNetAttr);
PedestrianTime network attribute
The following is from the New Network Dataset wizard's summary for the PedestrianTime network attribute:
PedestrianTime:
Usage Type: Cost
Data Type: Double
Units Type: Minutes
Use by Default: False
Source Attribute Evaluators:
Metro_Lines (From-To): Field - [Transittim]
Metro_Lines (To-From): Field - [Transittim]
Streets (From-To): Field - [METERS] * 60 / 3000
Streets (To-From): Field - [METERS] * 60 / 3000
Transfer_Stations (From-To): Field - [Transittim]
Transfer_Stations (To-From): Field - [Transittim]
Transfer_Street_Station (From-To): Field - [Transittim]
Transfer_Street_Station (To-From): Field - [Transittim]
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: False
Source Attribute Evaluators:
Metro_Lines (From-To): Field - [Transittim]
Metro_Lines (To-From): Field - [Transittim]
Streets (From-To): Field - [METERS] * 60 / 3000
Streets (To-From): Field - [METERS] * 60 / 3000
Transfer_Stations (From-To): Field - [Transittim]
Transfer_Stations (To-From): Field - [Transittim]
Transfer_Street_Station (From-To): Field - [Transittim]
Transfer_Street_Station (To-From): Field - [Transittim]
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 EvaluatedNetworkAttributeClass();
netAttr2 = evalNetAttr as INetworkAttribute2;
netAttr2.Name = "Meters";
netAttr2.UsageType = esriNAUTCost;
netAttr2.DataType = esriNADTDouble;
netAttr2.Units = esriNAUMeters;
netAttr2.UseByDefault = false;
// Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
netFieldEval = new NetworkFieldEvaluatorClass();
netFieldEval.SetExpression("[METERS] * 60 / 3000", "");
evalNetAttr.Evaluator(streetsNetSource, esriNEDAlongDigitized) = netFieldEval;
evalNetAttr.Evaluator(streetsNetSource, esriNEDAgainstDigitized) = netFieldEval;
netFieldEval = new NetworkFieldEvaluatorClass();
netFieldEval.SetExpression("[Transittim]", "");
evalNetAttr.Evaluator(metroNetSource, esriNEDAlongDigitized) = netFieldEval;
evalNetAttr.Evaluator(metroNetSource, esriNEDAgainstDigitized) = netFieldEval;
evalNetAttr.Evaluator(tsNetSource, esriNEDAlongDigitized) = netFieldEval;
evalNetAttr.Evaluator(tsNetSource, esriNEDAgainstDigitized) = netFieldEval;
evalNetAttr.Evaluator(tssNetSource, esriNEDAlongDigitized) = netFieldEval;
evalNetAttr.Evaluator(tssNetSource, esriNEDAgainstDigitized) = netFieldEval;
netConstEval = new NetworkConstantEvaluatorClass();
netConstEval.ConstantValue = 0;
evalNetAttr.DefaultEvaluator(esriNETEdge) = netConstEval;
evalNetAttr.DefaultEvaluator(esriNETJunction) = netConstEval;
evalNetAttr.DefaultEvaluator(esriNETTurn) = netConstEval;
// Add the attribute to the array.
attrArray.Add(evalNetAttr);
Now that all the attributes have been added to the array, the array can be added to the network dataset element. See the following code example:
[Java]
deND.Attributes = attrArray;
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: DriveTime
Road Class Attribute: RoadClass
Display Length Units: Miles
Length Attribute: Meters
Time Attribute: DriveTime
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 netDirections = new NetworkDirectionsClass();
netDirections.DefaultOutputLengthUnits = esriNAUMiles;
netDirections.LengthAttributeName = "Meters";
netDirections.TimeAttributeName = "DriveTime";
netDirections.RoadClassAttributeName = "RoadClass";
// Add the NetworkDirections object to the network dataset data element.
deND.Directions = netDirections;
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 fdxc = fdsGDS as IFeatureDatasetExtensionContainer;
IFeatureDatasetExtension fdx = fdxc.FindExtension(esriDTNetworkDataset);
IDatasetContainer2 dsc2 = fdx as IDatasetContainer2;
INetworkDataset netDataset = dsc2.CreateDataset(deND)as INetworkDataset;
// Once the network dataset is created, build it.
INetworkBuild netBuild = netDataset as INetworkBuild;
netBuild.BuildNetwork(fdsGDS.Extent);
See Also:
About the ArcGIS Network Analyst extension TutorialExercise 2: Creating a multimodal network dataset
Development licensing | Deployment licensing |
---|---|
ArcGIS for Desktop Basic | ArcGIS for Desktop Basic: Network Analyst |
ArcGIS for Desktop Standard | ArcGIS for Desktop Standard: Network Analyst |
ArcGIS for Desktop Advanced | ArcGIS for Desktop Advanced: Network Analyst |
Engine Developer Kit | Engine: Network Analyst |