创建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 ...
随机推荐
- Java 流(Stream)、文件(File)和IO
Java.io包几乎包含了所有操作输入.输出需要的类.所有这些流类代表了输入源和输出目标. Java.io包中的流支持很多种格式,比如:基本类型.对象.本地化字符集等等. 一个流可以理解为一个数据的序 ...
- Let it go.Let it be.Keep it up!
第三份工作仅仅持续了三个月,今天是last day. 虽然时间很短,但也是经历一场,认识了一些人,知道了一些事. 来去匆匆,难免有一点遗憾,还有一点愧疚. 只能放下,顺其自然,继续努力!
- es6学习笔记1 --let以及const
let语句的基本用法: 1.let声明的变量为块级作用域,只在最近的{}里面有效,如果在外部引用就会报错. { let a = 10; var b = "hello" } ale ...
- POJ1236Network of Schools[强连通分量|缩点]
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16571 Accepted: 65 ...
- ArrayList 保证多线程安全
一:使用synchronized关键字 二:使用Collections.synchronizedList();使用方法如下: 假如你创建的代码如下:List<Map<String,Obje ...
- 原生态ajax
用户名是否被注册过? 创建出注册信息: <h1>注册信息</h1> <input type="text" name="txtName&quo ...
- Python-12-MySQL & sqlalchemy ORM
MySQL MySQL相关文章这里不在赘述,想了解的点击下面的链接: >> MySQL安装 >> 数据库介绍 && MySQL基本使用 >> MyS ...
- Tech Websites
1,3D Game Engine Programming 2, 3, 4, 5,
- ASP.NET MVC - 探究应用程序文件夹
为了学习 ASP.NET MVC,我们将构建一个 Internet 应用程序. 第 2 部分:探究应用程序文件夹. MVC 文件夹 一个典型的 ASP.NET MVC Web 应用程序的文件夹内容如下 ...
- Netron源码解读(一):GraphControl画布对象
GraphControl是Netron中比较重要的一个类,属于所有图形作图的画布.它管理着画布上的所有图形对象的移动.变形.连接.拖放.这些功能很重要的一部分是通过对鼠标事件的处理实现的.下面我们就看 ...