ArcGIS Engine 10 开发手册(11-12)使用代码创建 Networkdataset
发布时间: 2018-02-27
所属分类: ArcGIS Engine 10 开发手册
本文演示一个使用代码实现创建 Networkdataset的过程。
示例代码
/// <summary>
/// 个人数据库的路径,要素数据集的路径,建立网络的名称,参与网络的要素类
/// </summary>
/// <param name="_pWsName"></param>
/// <param name="_pDatasetName"></param>
/// <param name="_pNetName"></param>
/// <param name="_pFtName"></param>
void CreateNetworkDataset (string _pWsName, string _pDatasetName, string _pNetName, string _pFtName)
{
IDENetworkDataset pDENetworkDataset = new DENetworkDatasetClass ();
pDENetworkDataset.Buildable = true;
IWorkspace pWs = GetWorkspace (_pWsName);
IFeatureWorkspace pFtWs = pWs as IFeatureWorkspace;
IFeatureDataset pFtDataset = pFtWs.OpenFeatureDataset (_pDatasetName);
// 定义空间参考,负责会出错
IDEGeoDataset pDEGeoDataset = (IDEGeoDataset) pDENetworkDataset;
IGeoDataset pGeoDataset = pFtDataset as IGeoDataset;
pDEGeoDataset.Extent = pGeoDataset.Extent;
pDEGeoDataset.SpatialReference = pGeoDataset.SpatialReference;
// 网络数据集的名称
IDataElement pDataElement = (IDataElement) pDENetworkDataset;
pDataElement.Name = _pNetName;
// 参加建立网络数据集的要素类
INetworkSource pEdgeNetworkSource = new EdgeFeatureSourceClass ();
pEdgeNetworkSource.Name = _pFtName;
pEdgeNetworkSource.ElementType = esriNetworkElementType.esriNETEdge;
// 要素类的连通性
IEdgeFeatureSource pEdgeFeatureSource = (IEdgeFeatureSource) pEdgeNetworkSource;
pEdgeFeatureSource.UsesSubtypes = false;
pEdgeFeatureSource.ClassConnectivityGroup = 1;
pEdgeFeatureSource.ClassConnectivityPolicy
= esriNetworkEdgeConnectivityPolicy.esriNECPEndVertex;
//不用转弯数据
pDENetworkDataset.SupportsTurns = false;
IArray pSourceArray = new ArrayClass ();
pSourceArray.Add (pEdgeNetworkSource);
pDENetworkDataset.Sources = pSourceArray;
//网络数据集的属性设置
IArray pAttributeArray = new ArrayClass ();
// Initialize variables reused when creating attributes:
IEvaluatedNetworkAttribute pEvalNetAttr;
INetworkAttribute2 pNetAttr2;
INetworkFieldEvaluator pNetFieldEval;
INetworkConstantEvaluator pNetConstEval;
pEvalNetAttr = new EvaluatedNetworkAttributeClass ();
pNetAttr2 = (INetworkAttribute2) pEvalNetAttr;
pNetAttr2.Name = "Meters";
pNetAttr2.UsageType = esriNetworkAttributeUsageType.esriNAUTCost;
pNetAttr2.DataType = esriNetworkAttributeDataType.esriNADTDouble;
pNetAttr2.Units = esriNetworkAttributeUnits.esriNAUMeters;
pNetAttr2.UseByDefault = false;
pNetFieldEval = new NetworkFieldEvaluatorClass ();
pNetFieldEval.SetExpression ("[METERS]", "");
//方向设置
pEvalNetAttr.set_Evaluator (pEdgeNetworkSource, esriNetworkEdgeDirection.esriNEDAlongDigitized, (INetworkEvaluator) pNetFieldEval);
pEvalNetAttr.set_Evaluator (pEdgeNetworkSource, sriNetworkEdgeDirection.esriNEDAgainstDigitized, (INetworkEvaluator) pNetFieldEval);
pNetConstEval = new NetworkConstantEvaluatorClass ();
pNetConstEval.ConstantValue = 0;
pEvalNetAttr.set_DefaultEvaluator (esriNetworkElementType.esriNETEdge, (INetworkEvaluator) pNetConstEval);
pEvalNetAttr.set_DefaultEvaluator (esriNetworkElementType.esriNETJunction, (INetworkEvaluator) pNetConstEval);
pEvalNetAttr.set_DefaultEvaluator (esriNetworkElementType.esriNETTurn, (INetworkEvaluator) pNetConstEval);
// 一个网络数据集可以有多个属性,我只添加了一个
pAttributeArray.Add (pEvalNetAttr);
pDENetworkDataset.Attributes = pAttributeArray;
// 创建网络数据集,注意在创建几何网络的时候会锁定相应的要素类,因此不要 用ArcMap或者catalog等打开参相应的数据
INetworkDataset pNetworkDataset = Create (pFtDataset, pDENetworkDataset);
//建立网络
INetworkBuild pNetworkBuild = (INetworkBuild) pNetworkDataset;
pNetworkBuild.BuildNetwork (pGeoDataset.Extent);
}
/// <summary>
/// 创建无向网络
/// </summary>
/// <param name="_pFeatureDataset"></param>
/// <param name="_pDENetDataset"></param>
/// <returns></returns>
public INetworkDataset Create (IFeatureDataset _pFeatureDataset, IDENetworkDataset2 _pDENetDataset)
{
IFeatureDatasetExtensionContainer pFeatureDatasetExtensionContainer = (IFeatureDatasetExtensionContainer) _pFeatureDataset;
IFeatureDatasetExtension pFeatureDatasetExtension = pFeatureDatasetExtensionContainer.FindExtension
(esriDatasetType.esriDTNetworkDataset);
IDatasetContainer2 pDatasetContainer2 = (IDatasetContainer2) pFeatureDatasetExtension;
IDEDataset pDENetDataset = (IDEDataset) _pDENetDataset;
INetworkDataset pNetworkDataset = (INetworkDataset) DatasetContainer2.CreateDataset (pDENetDataset);
return pNetworkDataset;
}
ArcGIS Engine 10 开发手册全集
ArcGIS Engine 10 开发手册全集: ArcGIS Engine 10 开发手册
相关阅读
声明
1.本文所分享的所有需要用户下载使用的内容(包括但不限于软件、数据、图片)来自于网络或者麻辣GIS粉丝自行分享,版权归该下载资源的合法拥有者所有,如有侵权请第一时间联系本站删除。
2.下载内容仅限个人学习使用,请切勿用作商用等其他用途,否则后果自负。
手机阅读
公众号关注
知识星球
手机阅读
最新GIS干货
私享圈子
创建网络数据集总是在DatasetContainer2.CreateDataset报错 DatasetContainer2.CreateDataset