创建NetWorkDataset---Shapefile篇
部分参照esri的官方例子,理解下各个参数,对照自己的NetWorkDatase创建方式(在arcmap中),多试试代码就调好了。
/// <summary>
/// 创建NetWorkDataset
/// </summary>
/// <returns>INetworkDataset.</returns>
public INetworkDataset CreateNetWorkDataset()
{
log.WriteLog("开始创建NetWorkDataset...");
//Create a new empty data element for a buildable network dataset.
IDENetworkDataset2 deNetworkDataset = new DENetworkDatasetClass();
deNetworkDataset.Buildable = true;
string sNDPath = Functions.g_WorkSpacePath + Functions.g_ROAD + "_ND.nd\\";
if (System.IO.Directory.Exists(sNDPath))
{
try
{
string[] strTemp = System.IO.Directory.GetFiles(sNDPath); //要先删除其下的所有子文件,然后删除目录,否则报错:System.IO.IOException: 目录不是空的
foreach (string str in strTemp)
{
System.IO.File.Delete(str);
}
System.IO.Directory.Delete(sNDPath);
}
catch (System.Exception ex)
{
log.WriteLog(sNDPath + "已存在,删除失败!");
return null;
}
}
// Open the shapefile and cast to the IGeoDataset interface.
IWorkspaceFactory2 workspaceFactory = new ShapefileWorkspaceFactoryClass() asIWorkspaceFactory2;
IWorkspace workspace = workspaceFactory.OpenFromFile(Functions.g_WorkSpacePath, );
IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace;
IFeatureClass featureClass = featureWorkspace.OpenFeatureClass(Functions.g_ROAD);
IGeoDataset geoDataset = (IGeoDataset)featureClass;
deNetworkDataset.NetworkType = esriNetworkDatasetType.esriNDTShapefile;
// Copy the shapefile's extent and spatial reference to the network dataset data element.
IDEGeoDataset deGeoDataset = (IDEGeoDataset)deNetworkDataset;
deGeoDataset.Extent = geoDataset.Extent;
deGeoDataset.SpatialReference = geoDataset.SpatialReference;
IDataElement dataElement = (IDataElement)deNetworkDataset; // Specify the name of the network dataset.
dataElement.Name = Functions.g_ROAD + "_ND";
// Specify the network dataset's elevation model.
deNetworkDataset.ElevationModel = esriNetworkElevationModel.esriNEMNone;
// Create an EdgeFeatureSource object and point it to the Streets feature class.
INetworkSource edgeNetworkSource = new EdgeFeatureSourceClass();
edgeNetworkSource.Name = Functions.g_ROAD;
edgeNetworkSource.ElementType = esriNetworkElementType.esriNETEdge;
// Set the edge feature source's connectivity settings.
IEdgeFeatureSource edgeFeatureSource = (IEdgeFeatureSource)edgeNetworkSource;
edgeFeatureSource.UsesSubtypes = false;
edgeFeatureSource.ClassConnectivityGroup = ;
edgeFeatureSource.ClassConnectivityPolicy =esriNetworkEdgeConnectivityPolicy.esriNECPEndVertex;
IArray sourceArray = new ArrayClass();
sourceArray.Add(edgeNetworkSource);
deNetworkDataset.Sources = sourceArray;
IArray attributeArray = new ArrayClass();
IEvaluatedNetworkAttribute evalNetAttr;
INetworkAttribute2 netAttr2;
INetworkFieldEvaluator netFieldEval;
INetworkConstantEvaluator netConstEval;
// Create an EvaluatedNetworkAttribute object and populate its settings.
evalNetAttr = new EvaluatedNetworkAttributeClass();
netAttr2 = (INetworkAttribute2)evalNetAttr;
netAttr2.Name = "Time"; //按秒算的时间消耗
netAttr2.UsageType = esriNetworkAttributeUsageType.esriNAUTCost;
netAttr2.DataType = esriNetworkAttributeDataType.esriNADTDouble;
netAttr2.Units = esriNetworkAttributeUnits.esriNAUSeconds;
netAttr2.UseByDefault = false;
// Create evaluator objects and set them on the EvaluatedNetworkAttribute object.
netFieldEval = new NetworkFieldEvaluatorClass();
netFieldEval.SetExpression("a", "。。。。。。。。。。。"); //表达式不能出错
evalNetAttr.set_Evaluator(edgeNetworkSource,esriNetworkEdgeDirection.esriNEDAlongDigitized, (INetworkEvaluator)netFieldEval);
netFieldEval = new NetworkFieldEvaluatorClass();
netFieldEval.SetExpression("a", "。。。。。。。。。");
evalNetAttr.set_Evaluator(edgeNetworkSource,esriNetworkEdgeDirection.esriNEDAgainstDigitized, (INetworkEvaluator)netFieldEval);
netConstEval = new NetworkConstantEvaluatorClass();
netConstEval.ConstantValue = false;
evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETEdge, (INetworkEvaluator)netConstEval);
evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETJunction, (INetworkEvaluator)netConstEval);
evalNetAttr.set_DefaultEvaluator(esriNetworkElementType.esriNETTurn, (INetworkEvaluator)netConstEval);
// Add the attribute to the array.
attributeArray.Add(evalNetAttr);
deNetworkDataset.Attributes = attributeArray;
//// 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);
IDatasetContainer3 datasetContainer2 = (IDatasetContainer3)workspaceExtension;
IDEDataset deDataset = (IDEDataset)deNetworkDataset;
IDataset ds = datasetContainer2.CreateDataset(deDataset);
INetworkDataset networkDataset = (INetworkDataset)ds;
log.WriteLog("NetWorkDataset创建完成,Building Network...");
// Once the network dataset is created, build it.
INetworkBuild networkBuild = (INetworkBuild)networkDataset;
networkBuild.BuildNetwork(geoDataset.Extent);
log.WriteLog("BuildNetwork完成!");
return networkDataset;
}
创建NetWorkDataset---Shapefile篇的更多相关文章
- 创建型模式篇(工厂模式Factory Pattern)
一.工厂模式(Factory Pattern) 1.定义: 在软件系统,经常面临着“某个对象”的创建工作,由于需求的变化,这个对象的具体实现经常面临着剧烈的变化,但是它却拥有比较稳定的接口.提供一种封 ...
- 创建型模式篇(单例模式Single Pattern)
一.单例模式(Singleton Pattern) 单例模式要求一个类只能有一个实例,并且提供了一个全局的访问点. 比如说,中国主席的职位是Singleton,法律规定主席选举,任何时间只能有一个主席 ...
- Windows Azure系列公开课 - 第三课:创建虚拟机 (基础篇)
Windows Azure微软智能云平台主要提供四大类服务:计算服务(Compute),数据服务 (Data Services) ,应用服务 (App Services) ,网络服务(Network) ...
- 创建NetWorkDataset---FileGDB篇
/// <summary> /// 创建NetWorkDataset /// </summary> /// <returns>INetworkDataset.< ...
- 第6篇-Java方法新栈帧的创建
在 第2篇-JVM虚拟机这样来调用Java主类的main()方法 介绍JavaCalls::call_helper()函数的实现时提到过如下一句代码: address entry_point = me ...
- 第7篇-为Java方法创建栈帧
在 第6篇-Java方法新栈帧的创建 介绍过局部变量表的创建,创建完成后的栈帧状态如下图所示. 各个寄存器的状态如下所示. // %rax寄存器中存储的是返回地址 rax: return addres ...
- 为什么ArcGIS 10.3导出 Shapefile的字段名会被截断成3个汉字?解决方法如下
为什么ArcGIS 10.3导出 Shapefile的字段名会被截断成3个汉字?低版本中不是至少可以存储4个汉字吗?原因这个问题仍然与编码类型有关.ArcGIS 10.2 以及更早的版本,ArcGIS ...
- 详解:数据库名、实例名、ORACLE_SID、数据库域名、全局数据库名、服务名及手工脚本创建oracle数据库
数据库名.实例名.数据库域名.全局数据库名.服务名 , 这是几个令很多初学者容易混淆的概念.相信很多初学者都与我一样被标题上这些个概念搞得一头雾水.我们现在就来把它们弄个明白. 一.数据库名 什么是数 ...
- android手势创建及识别
使用一些浏览器或者输入法应用时会有一些手势操作,还可以自定义手势.这些神奇的操作是怎么做的呢?这一篇重点记录手势的识别和创建.这篇的内容使用到的是android.gesture包,具体的例子参考的是S ...
随机推荐
- C语言核心之数组和指针详解
指针 相信大家对下面的代码不陌生: int i=2; int *p; p=&i;这是最简单的指针应用,也是最基本的用法.再来熟悉一下什么是指针:首先指针是一个变量,它保存的并不是平常的数据,而 ...
- PHP笔记(HTML篇)
学过很多语言,最近终于决定要学PHP了. 学习PHP,首先总要学习HTML,那么,我也从HTML开始吧! 首先学习任何编程语言,看再多书,都离不开它——帮助文档 HTML帮助文档:http://pan ...
- Shell十三问[转]
Shell十三问 转载于网络,稍加整理. (一) 为何叫做Shell? 我们知道计算机的运作不能离开硬件,但使用者却无法直接对硬件作驱动,硬件的驱动只能透过一个称为"操作系统(Operati ...
- mycat高可用方案
1.建议采用标准的mysql主从复制高可用配置并交付给mycat来完成后端mysql节点的主从自动切换. 2.mycat自身的高可用性 由HAproxy+Mycat集群+Mysql主从所组成的高可用性 ...
- Android原生游戏开发:使用JustWeEngine开发微信打飞机
使用JustWeEngine开发微信打飞机: 作者博客: 博客园 引擎地址:JustWeEngine 示例代码:EngineDemo JustWeEngine? JustWeEngine是托管在Git ...
- SQL笔记
1.增加.删除约束 ALTER TABLE 表名 ADD CONSTRAINT 约束名 UNIQUE(列1名,列名2) ALTER TABLE 表名 DROP CONSTRAINT 约束名 2.查询更 ...
- C++学习笔记(3)
本学习笔记是C++ primer plus(第六版)学习笔记.是C++学习笔记(2)的后续.复习C++基础知识的可以瞄瞄. 转载请注明出处http://www.cnblogs.com/zrtqsk/p ...
- CRC32算法
unsigned ] = { 0x00000000, 0x77073096, 0xEE0E612C, 0x990951BA, 0x076DC419, 0x706AF48F, 0xE963A535, 0 ...
- CentOS 6.5 PPTPD VPN服务器安装,解决807等问题。
需要两个组件: ppp pptpd 需要配置的地方有三处: /etc/pptpd.conf /etc/ppp/options.pptpd /etc/ppp/chap-secrets 需要开启IP转发: ...
- 聚类算法:K-means
2013-12-13 20:00:58 Yanjun K-means算法是很典型的基于距离的聚类算法,采用距离作为相似性的评价指标,即认为两个对象的距离越近,其相似度就越大.该算法认为簇是由距离 ...