ArcEngine中最短路径的实现
最短路径分析属于ArcGIS的网络分析范畴。而ArcGIS的网络分析分为两类,分别是基于几何网络和网络数据集的网络分析。它们都可以实现最短路径功能。下面先介绍基于几何网络的最短路径分析的实现。以后会陆续介绍基于网络数据集的最短路径分析以及这两种方法的区别。
几何网络是一种特殊的特征要素类,由一系列不同类别的点要素和线要素(可以度量并能图形表达)组成的,可在FeatureDataset下面创建, 可进行图形与属性的编辑。包括流向分析和追踪分析两大功能。主要接口是ITraceFlowSolver。我们先在一幅地图上做出一个几何网络才能进行最 短路径分析。下面是主要的一些步骤(ArcMap帮助中琐碎的说明有三四十项,被我省略很多):
1、打开ArcCatalog,连接到包含地图的文件夹。
2、在空白处,右键新建一个“Personal GeoDatabase”。
3、在生成的Personal GeoDatabase上右键新建一个feature dataset。
4、双击Personal GeoDatabase进去,找到刚才new出的feature dataset,右键Import导入Feature Class(Single),选择要建立几何网络的图层或者shape文件。
5、然后再右键新建一个Geometric Network,选择从已存在的图元中建立几何网络。
6、打开ArcMap,把刚才建立的“Personal GeoDatabase Feature Class”添加到地图中,这样几何网络就建立好了。
这样我们就建立好一个几何网络了。我们现在要通过编程来实现最短路径,用到的接口主要有 INetworkCollection,IGeometricNetwork,IPointToEID,ITraceFlowSolverGEN(它实现 了ITraceFlowSolver的接口),INetSchema,IEIDHelper等。主要步骤如下:
1、获取几何网络工作空间
2、定义一个边线旗数组,把离点串最近的网络元素添加进数组
3、设置开始和结束边线的权重
4、进行路径分析
5、得到路径分析的结果
上次介绍了用几何网络实现的“最短路径”,这次用网络数据集实现真正的最短路径功能,跟上次一样,先处理下数据。
1、先打开ArcCatalog,连接到目标文件夹,假定该文件下有一个名为road的道路图层。
2、在road图层上右键新建一个网络数据集,并按照其默认设置直至完成。
3、打开该地图的工作空间,把刚才新建的网络数据集添加工作空间中。
4、在网络分析菜单中选择新建最近设施点。
这时在工作空间里,可以看到多了一个名为“Closest Facility”的图层。它下面还有4个子图层,名字分别为
“Facilities”,“Incidents”,“Barriers”,“Routes”。“Facilities”就是设施点图层,也就是目的
点,“Incidents”的意思就是出发点,“Barriers”是障碍点,意思就是地图某条道路附近有一个障碍点,如果障碍点与道路距离在容限范围
内,则表示此道路不通,“Routes”就是最终的结果。这样我们编程实现最短路径的思路就出现了:
1、添加出发点。
2、添加目的点。
3、生成最优路径,获取结果。
这里的添加出发点或者目的点,是往“Facilities”或“Incidents”图层上添加元素。获取结果也是从“Routes”中获取
Polyline。往“Facilities”或“Incidents”图层上添加元素用到的主要方法是INALocator的
QueryLocationByPoint函数,生成路径主要接口是INASolver和它的Solve方法。获取结果是按属性查找,因为
“Routes”类其实就是一个图层类,只不过只是存在于内存。
CMapControlDefault m_map;
IPointCollectionPtr m_ipPointCollection; ILayerPtr ipLayer = m_map.GetLayer(); // 网络数据集
INALayerPtr ipNaLayer = ipLayer;
if (NULL == ipNaLayer)
{
return;
} INAContextPtr ipNaContext;
HRESULT hr = ipNaLayer->get_Context(&ipNaContext);
INAClassLoaderPtr ipNAClassLoader(CLSID_NAClassLoader);
INALocatorPtr ipNALocator = NULL;
hr = ipNaContext->get_Locator(&ipNALocator);
ipNALocator->put_SnapToleranceUnits(esriMeters);
ipNALocator->put_SnapTolerance();
ipNaContext;
hr = ipNAClassLoader->putref_Locator(ipNALocator); INamedSetPtr ipNamedSet = NULL;
ipNaContext->get_NAClasses(&ipNamedSet); CString szName = "Facilities";
BSTR bstrName = szName.AllocSysString();
INAClassPtr ipNAFacilitiesClass = NULL;
hr = ipNamedSet->get_ItemByName(bstrName, (IUnknown**)&ipNAFacilitiesClass);
szName = "Incidents";
bstrName = szName.AllocSysString();
INAClassPtr ipNAIncidentsClass = NULL;
hr = ipNamedSet->get_ItemByName(bstrName, (IUnknown**)&ipNAIncidentsClass);
szName = "CFRoutes";
bstrName = szName.AllocSysString();
INAClassPtr ipNARoutesClass = NULL;
hr = ipNamedSet->get_ItemByName(bstrName, (IUnknown**)&ipNARoutesClass); INALocationPtr ipNALocation1(CLSID_NALocation);
INALocationPtr ipNALocation2(CLSID_NALocation);
ipNAClassLoader->get_Locator(&ipNALocator);
IPointPtr ipBeginPoint(CLSID_Point);
m_ipPointCollection->get_Point(, &ipBeginPoint);
IPointPtr ipEndPoint(CLSID_Point);
m_ipPointCollection->get_Point(, &ipEndPoint);
IPointPtr ipPoint1(CLSID_Point);
IPointPtr ipPoint2(CLSID_Point);
double dbLVal = 0.0;
ipNALocator->QueryLocationByPoint(ipBeginPoint, &ipNALocation1, &ipPoint1, &dbLVal);
ipNALocator->QueryLocationByPoint(ipEndPoint, &ipNALocation2, &ipPoint2, &dbLVal); INALocationObjectPtr ipNALocationObject = NULL;
IFeatureClassPtr ipFeatureClass = ipNAIncidentsClass;
IFeaturePtr ipFeature = NULL;
ipFeatureClass->CreateFeature(&ipFeature);
IRowSubtypesPtr ipRowSubtypes = ipFeature;
ipRowSubtypes->InitDefaultValues();
ipFeature->putref_Shape(ipBeginPoint);
ITablePtr ipTable = NULL;
ipFeature->get_Table(&ipTable);
long nIndex = ;
szName = "Sequence";
bstrName = szName.AllocSysString();
ipTable->FindField(bstrName, &nIndex);
VARIANT var_int;
var_int.intVal = ;
var_int.vt = VT_INT;
ipFeature->put_Value(nIndex, var_int);
szName = "Name";
bstrName = szName.AllocSysString();
ipTable->FindField(bstrName, &nIndex);
ipFeature->put_Value(nIndex, COleVariant("Start Point"));
ipNALocationObject = ipFeature;
ipNALocationObject->put_NALocation(ipNALocation1);
ipFeature->Store();
IFieldsPtr ipFields(CLSID_Fields);
hr = ipTable->get_Fields(&ipFields);
long nFieldCount = ;
hr = ipFields->get_FieldCount(&nFieldCount);
for (int k = ; k < nFieldCount; k++)
{
IFieldPtr ipField(CLSID_Field);
ipFields->get_Field(k, &ipField);
BSTR bstrFieldName;
ipField->get_Name(&bstrFieldName);
CString szFieldName = bstrFieldName;
} ipFeatureClass = ipNAFacilitiesClass;
ipFeatureClass->CreateFeature(&ipFeature);
ipRowSubtypes = ipFeature;
ipRowSubtypes->InitDefaultValues();
ipFeature->putref_Shape(ipEndPoint);
ipTable = NULL;
ipFeature->get_Table(&ipTable);
nIndex = ;
szName = "Sequence";
bstrName = szName.AllocSysString();
ipTable->FindField(bstrName, &nIndex);
var_int.intVal = ;
ipFeature->put_Value(nIndex, var_int);
szName = "Name";
bstrName = szName.AllocSysString();
ipTable->FindField(bstrName, &nIndex);
ipFeature->put_Value(nIndex, COleVariant("End Point"));
ipNALocationObject = ipFeature;
ipNALocationObject->put_NALocation(ipNALocation2);
ipFeature->Store(); INAClosestFacilitySolverPtr ipNACFSolver = NULL;
ArcEngine中最短路径的实现的更多相关文章
- ArcEngine中打开各种数据源(WorkSpace)的连接
(SDE.personal/File.ShapeFile.CAD数据.影像图.影像数据集) ArcEngine 可以接受多种数据源.在开发过程中我们使用了如下几种数据源 1.企业数据库(SDE) 企业 ...
- ArcEngine中打开各种数据源(WorkSpace)的连接(转)
ArcEngine中打开各种数据源(WorkSpace)的连接 (SDE.personal/File.ShapeFile.CAD数据.影像图.影像数据集) ArcEngine 可以接受多种数据源.在开 ...
- ArcEngine中打开各种数据源(WorkSpace)的连接http://www.cnblogs.com/feilong3540717/archive/2011/08/07/2129906.html
ArcEngine中打开各种数据源(WorkSpace)的连接 ArcEngine中打开各种数据源(WorkSpace)的连接 (SDE.personal/File.ShapeFile.CAD数据.影 ...
- [转] ArcEngine中打开各种数据源(WorkSpace)的连接
原文 ArcEngine中打开各种数据源(WorkSpace)的连接(SDE.personal/File.ShapeFile.CAD数据.影像图.影像数据集) ArcEngine 可以接受多种数据源. ...
- c#+ArcEngine中的IGroupLayer的用法
转自羊子雄起原文c#+ArcEngine中的IGroupLayer的用法 在AE开发中,我们知道axMapControl.LayerCount能获取图层的数量,但是这种方法不能获取到图层组里面的图层, ...
- ArcEngine中使用上下左右键移动地图
转自愿文ArcEngine中使用上下左右键移动地图 因项目需要,需对mapcontrol控件响应上下左右键,从网上找的方法都一样,都值提到了需要设置axMapControl1的KeyIntercept ...
- C#+ArcEngine中com对象的释放问题
1.问题描述 最近在写C#下AE的开发,在循环获取数据并修改时碰到了两个问题"超出系统资源"和"超出打开游标最大数":在网上看了一些资料,发现都是说在循环中没有 ...
- ArcEngine中COM对象与其基础RCW分开后就不能再使用
操作ArcEngine中的COM对象时,为了减少内存的增长,用掉的对象要手动释放常用的方法是ReleaseComObject System.Runtime.InteropServices.Marsha ...
- ArcEngine中多边形内外环的处理(转)
ArcEngine中多边形内外环的处理 原创 2012年09月06日 22:49:11 标签: object / null / 数据库 3462 Polylgon对象是由一个或多个Ring对象的有序集 ...
随机推荐
- 洛谷 P2873 [USACO07DEC]泥水坑Mud Puddles
P2873 [USACO07DEC]泥水坑Mud Puddles 题目描述 Farmer John is leaving his house promptly at 6 AM for his dail ...
- PHP服务器环境打开配置文件
MAC 1. cd /usr/local/etc/nginx/servers vim www.xxx.com 2. 在/usr/local/etc/nginx/servers目录下,不同的 .con ...
- JAVA 水题
纯粹是让我来掌握熟练度的. 1.金蝉素数 某古寺的一块石碑上依稀刻有一些神秘的自然数. 专家研究发现:这些数是由1,3,5,7,9 这5 个奇数字排列组成的5 位素数,且同时去掉它的最高位与最低位数字 ...
- Spider_basic
网络爬虫 定义:网络蜘蛛.网络机器人,抓取网络数据的程序 总结:用Python程序去模仿人去访问网站,模仿的越逼真越好 目的:通过有效的大量数据分析市场走势.公司决策 企业获取数据的方式 公司自有数据 ...
- Spring MVC基础了解
参考网址:https://www.yiibai.com/spring_mvc/springmvc_overview.html Spring框架相关 Spring Security 一个灵活强大的身份验 ...
- 洛谷 P2095 营养膳食
洛谷 P2095 营养膳食 题目描述 Mr.L正在完成自己的增肥计划. 为了增肥,Mr.L希望吃到更多的脂肪.然而也不能只吃高脂肪食品,那样的话就会导致缺少其他营养.Mr.L通过研究发现:真正的营养膳 ...
- 解决Keystore was tampered with, or password was incorrect
使用签名文件keystore查看生成的数字签名中报错解决 Keystore was tampered with, or password was incorrect 这是由于android规定自己定义 ...
- Android Mvvm模式的理解
1. Mvvm是什么,Mvvm是怎么来的?Mvvm模式广泛应用在WPF项目开发中,使用此模式可以把UI和业务逻辑分离开,使UI设计人员和业务逻辑人员能够分工明确. Mvvm模式是根据MVP模式来的,可 ...
- js匿名函数(变量加括号就是函数)
js匿名函数(变量加括号就是函数) 一.总结 变量加括号就是函数,而函数的括号是用来传参的 1.类比:以正常函数去想匿名函数,匿名函数比正常函数只是少了函数名,本质还是一样,该怎么传参还是怎么传参,小 ...
- (嵌入式开发)自己写bootloader之编写第一阶段
最简单的bootloader的编写步骤: 1. 初始化硬件:关看门狗.设置时钟.设置SDRAM.初始化NAND FLASH 2. 如果bootloader比较大,要把它重定位到SDRAM 3. 把内核 ...