• 构建网络数据集(c#)


    二次开发就是搭积木,但是这种积木在AO中可以成为接口,那么我们二次开发就要想实现我们功能的相关接口组合起来,

    ArcGIS中有两种网络,无向网络和有向网络,我在这里讨论是无向网络,网络是用来模拟现实世界中的如交通道路等,这也是GIS中的一个精华,ArcGIS中用一组要素对现实世界中的网络进行抽象,比如用线要素来模拟边,用点要素模拟交汇点等,而网络不是要素,是又相关的要素构建而成的“逻辑图“,所有的分析都是在这个逻辑图上进行的,也可以说这个逻辑图是由相互关联的要素结合一定的规则,派生出来的。而在ArcGIS中无向网络可以有shpfile创建也可以由geodatabase中的数据集创建,而有向网络智能由后者。

    对ArcMap的熟练程度有助于我们更快速的开发,我们用网络分析的时候,第一步干什么,第二步干什么……也就是这个流程的熟练程度对我们开发是很有帮助的,下面我们用代码来说明下,因为这个代码很长,我只说明原理等

    重要接口Inetworkbuild,利用开发帮助也是一种技巧,这种技巧就好比我们遇到问题了Google下。

    步骤一 创建网络数据集

    IDENetworkDataset deNetworkDataset = new DENetworkDatasetClass();

    deNetworkDataset.Buildable = true;

     

    // Open the shapefile and cast to the IGeoDataset interface.

    IWorkspaceFactory workspaceFactory = new ShapefileWorkspaceFactoryClass();

    IWorkspace workspace = workspaceFactory.OpenFromFile(@

        "C:\Program Files\ArcGIS\DeveloperKit\SamplesNET\data\CreateNetworkDataset", 0);

    IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;

    IFeatureClass featureClass = featureWorkspace.OpenFeatureClass("Streets");

    IGeoDataset geoDataset = (IGeoDataset)featureClass;

     

    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 = "Streets_ND";

    步骤二:

    刚才我们创建了网络,但是并没有和相关的要素关联

    网络数据集建立了,我们说过网络数据集中应该包含相互关联的要素,而这种主要体现在边和交汇点这两个之上,同时还有一定的规则,比如道路的联通规则,所以我刚才说了逻辑图是由相互关联的要素结合一定的规则,派生出来的


    [C#]

    // Create a new EdgeFeatureSource object and point it to the Streets shapefile.

    IEdgeFeatureSource streetsEdgeFeatureSource = new EdgeFeatureSourceClass();

    INetworkSource streetsNetworkSource = (INetworkSource)streetsEdgeFeatureSource;

    streetsNetworkSource.Name = "Streets";

    streetsNetworkSource.ElementType = esriNetworkElementType.esriNETEdge;

     

    // Set the connectivity settings for the edge feature source.

    streetsEdgeFeatureSource.UsesSubtypes = false;

    streetsEdgeFeatureSource.ClassConnectivityGroup = 1;

    streetsEdgeFeatureSource.ClassConnectivityPolicy =

        esriNetworkEdgeConnectivityPolicy.esriNECPEndVertex;

    streetsEdgeFeatureSource.FromElevationFieldName = "F_ZLEV";

    streetsEdgeFeatureSource.ToElevationFieldName = "T_ZLEV";

    ArcGIS的强大在于他能跟准确的模拟这个显示,通过搞成字段可以区分立交桥


    图片

    步骤三,方向设置

    // Create a StreetNameFields object and populate its settings.

    IStreetNameFields streetNameFields = new StreetNameFieldsClass();

    streetNameFields.Priority = 1; // Priority 1 indicates the primary street name.

    streetNameFields.PrefixDirectionFieldName = "PREFIX";

    streetNameFields.PrefixTypeFieldName = "PRE_TYPE";

    streetNameFields.StreetNameFieldName = "NAME";

    streetNameFields.SuffixTypeFieldName = "TYPE";

    streetNameFields.SuffixDirectionFieldName = "SUFFIX";

     

    // Add the StreetNameFields object to a new NetworkSourceDirections object,

    // then add it to the EdgeFeatureSource created earlier.

    INetworkSourceDirections networkSourceDirections = new NetworkSourceDirectionsClass()

        ;

    IArray streetNameFieldsArray = new ArrayClass();

    streetNameFieldsArray.Add(streetNameFields);

    networkSourceDirections.StreetNameFields = streetNameFieldsArray;

    streetsNetworkSource.NetworkSourceDirections = networkSourceDirections;

     

    // Add the EdgeFeatureSource object to the data element as a source in the network dataset.

    IArray sourceArray = new ArrayClass();

    sourceArray.Add(streetsEdgeFeatureSource);

    deNetworkDataset.Sources = sourceArray;

     

    步骤四,可以有turn,也可以没有

     

    步骤五 网络权重设置

    // Create a new EvaluatedNetworkAttribute object and populate its settings.

    IEvaluatedNetworkAttribute minutesEvaluatedNetworkAttribute = new

        EvaluatedNetworkAttributeClass();

    INetworkAttribute2 minutesNetworkAttribute2 = (INetworkAttribute2)

        minutesEvaluatedNetworkAttribute;

    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 minutesFTNetworkFieldEvaluator = new

        NetworkFieldEvaluatorClass();

    minutesFTNetworkFieldEvaluator.SetExpression("[FT_Minutes]", "");

    INetworkEvaluator minutesFTNetworkEvaluator = (INetworkEvaluator)

        minutesFTNetworkFieldEvaluator;

    minutesEvaluatedNetworkAttribute.set_Evaluator(streetsNetworkSource,

        esriNetworkEdgeDirection.esriNEDAlongDigitized, minutesFTNetworkEvaluator);

     

    INetworkFieldEvaluator minutesTFNetworkFieldEvaluator = new

        NetworkFieldEvaluatorClass();

    minutesTFNetworkFieldEvaluator.SetExpression("[TF_Minutes]", "");

    INetworkEvaluator minutesTFNetworkEvaluator = (INetworkEvaluator)

        minutesTFNetworkFieldEvaluator;

    minutesEvaluatedNetworkAttribute.set_Evaluator(streetsNetworkSource,

        esriNetworkEdgeDirection.esriNEDAgainstDigitized, minutesTFNetworkEvaluator);

     

    INetworkConstantEvaluator minutesNetworkConstantEvaluator = new

        NetworkConstantEvaluatorClass();

    minutesNetworkConstantEvaluator.ConstantValue = 0;

    INetworkEvaluator minutesConstantNetworkEvaluator = (INetworkEvaluator)

        minutesNetworkConstantEvaluator;

    minutesEvaluatedNetworkAttribute.set_DefaultEvaluator

        (esriNetworkElementType.esriNETEdge, minutesConstantNetworkEvaluator);

    minutesEvaluatedNetworkAttribute.set_DefaultEvaluator

        (esriNetworkElementType.esriNETJunction, minutesConstantNetworkEvaluator);

    minutesEvaluatedNetworkAttribute.set_DefaultEvaluator

        (esriNetworkElementType.esriNETTurn, minutesConstantNetworkEvaluator);

     

    // Add the attribute to the array.

    attributeArray.Add(minutesEvaluatedNetworkAttribute);

     

    步骤六 建立网络

    // Create a new UID that references the NetworkDatasetWorkspaceExtension.

    UID ndWorkspaceExtensionUID = new UIDClass();

    ndWorkspaceExtensionUID.Value = "esriGeoDatabase.NetworkDatasetWorkspaceExtension";

     

    // Get the workspace extension and create the network dataset based on the data element.

    IWorkspaceExtensionManager workspaceExtensionManager = (IWorkspaceExtensionManager)

        workspace;

    IWorkspaceExtension workspaceExtension = workspaceExtensionManager.FindExtension

        (ndWorkspaceExtensionUID);

    IDatasetContainer2 datasetContainer2 = (IDatasetContainer2)workspaceExtension;

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

     

  • 相关阅读:
    Android的各版本间的区别总结
    深入浅出Android开发之Surface介绍
    android中完全退出当前应用程序的四种方法
    android离线地图源码
    坐标系
    mysql安装
    linux磁盘空间清理
    HttpClient教程
    TIME_WAIT过多
    c3p0配置详解
  • 原文地址:https://www.cnblogs.com/zuiyirenjian/p/1896954.html
Copyright © 2020-2023  润新知