// 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";
// 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);
// 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;
// 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);