ArcEngine 地图导航 查找路径 经纬度坐标导航 最优路径分析
本文来自CSDN博客。转载请标明出处 http//blog.csdn.net/zdb330906531
需求:依据经纬度坐标。取得两个起点与终点,显示最优路径实现导航。
參考官方样例后。我在arcMap上已实现效果,要求改为代码实现。
实现思路:1、创建路径 2、加入位置 3、求解
代码例如以下:
① 创建路径
public INAContext CreateSolverContext(INetworkDataset networkDataset)
{
IDENetworkDataset deNDS = GetDENetworkDataset(networkDataset);
INASolver naSolver = new NARouteSolver();//路径(NAClosestFacilitySolver 近期设施)
INAContextEdit contextEdit = naSolver.CreateContext(deNDS, naSolver.Name) as INAContextEdit;
contextEdit.Bind(networkDataset, new GPMessagesClass());
return contextEdit as INAContext;
}
public IDENetworkDataset GetDENetworkDataset(INetworkDataset networkDataset)
{
IDatasetComponent dsComponent = networkDataset as IDatasetComponent;
return dsComponent.DataElement as IDENetworkDataset;
}
调用方法:
ILayer ilayer = MapLayerHelper.GetLayerByName(axMapControl1.Map, "道路_ND");
INetworkDataset networkDataset = (ilayer as INetworkLayer).NetworkDataset;//网络数据集
INAContext m_NAContext = CreateSolverContext(networkDataset);
② 加入位置
/// <summary>
/// 在内存中创建图层
/// </summary>
/// <param name="DataSetName">数据集名称(所建图层名称)</param>
/// <param name="AliaseName">别名</param>
/// <param name="SpatialRef">空间參考</param>
/// <param name="GeometryType">几何类型</param>
/// <param name="PropertyFields">属性字段集合</param>
/// <returns>IfeatureLayer</returns>
public static IFeatureLayer CreateFeatureLayerInMemeory(string DataSetName, string AliaseName, ISpatialReference SpatialRef, esriGeometryType GeometryType, IFields PropertyFields)
{
ESRI.ArcGIS.Geodatabase.IWorkspaceFactory workspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.InMemoryWorkspaceFactoryClass();
ESRI.ArcGIS.Geodatabase.IWorkspaceName workspaceName = workspaceFactory.Create("", "MyWorkspace", null, 0);
ESRI.ArcGIS.esriSystem.IName name = (IName)workspaceName;
ESRI.ArcGIS.Geodatabase.IWorkspace inmemWor = (IWorkspace)name.Open();
IField oField = new FieldClass();
IFields oFields = new FieldsClass();
IFieldsEdit oFieldsEdit = null;
IFieldEdit oFieldEdit = null;
IFeatureClass oFeatureClass = null;
IFeatureLayer oFeatureLayer = null;
try
{
oFieldsEdit = oFields as IFieldsEdit;
oFieldEdit = oField as IFieldEdit;
if (PropertyFields != null)
{
for (int i = 0; i < PropertyFields.FieldCount; i++)
{
oFieldsEdit.AddField(PropertyFields.get_Field(i));
}
}
IGeometryDef geometryDef = new GeometryDefClass();
IGeometryDefEdit geometryDefEdit = (IGeometryDefEdit)geometryDef;
geometryDefEdit.AvgNumPoints_2 = 5;
geometryDefEdit.GeometryType_2 = GeometryType;
geometryDefEdit.GridCount_2 = 1;
geometryDefEdit.HasM_2 = false;
geometryDefEdit.HasZ_2 = false;
geometryDefEdit.SpatialReference_2 = SpatialRef; oFieldEdit.Name_2 = "SHAPE";
oFieldEdit.Type_2 = esriFieldType.esriFieldTypeGeometry;
oFieldEdit.GeometryDef_2 = geometryDef;
oFieldEdit.IsNullable_2 = true;
oFieldEdit.Required_2 = true;
oFieldsEdit.AddField(oField); oFeatureClass = (inmemWor as IFeatureWorkspace).CreateFeatureClass(DataSetName, oFields, null, null, esriFeatureType.esriFTSimple, "SHAPE", "");
(oFeatureClass as IDataset).BrowseName = DataSetName; oFeatureLayer = new FeatureLayerClass();
oFeatureLayer.Name = AliaseName;
oFeatureLayer.FeatureClass = oFeatureClass;
}
catch
{}
finally
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(oField);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oFields);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oFieldsEdit);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oFieldEdit);
System.Runtime.InteropServices.Marshal.ReleaseComObject(name);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workspaceFactory);
System.Runtime.InteropServices.Marshal.ReleaseComObject(workspaceName);
System.Runtime.InteropServices.Marshal.ReleaseComObject(inmemWor);
System.Runtime.InteropServices.Marshal.ReleaseComObject(oFeatureClass);
GC.Collect();
}
return oFeatureLayer;
}
INAClassLoader classLoader = new NAClassLoader();
classLoader.Locator = m_NAContext.Locator;
classLoader.Locator.SnapTolerance = 100;
classLoader.NAClass = m_NAContext.NAClasses.get_ItemByName("Stops") as INAClass;
//加入起点与终点位置
string[] startCoordinate = textBox1.Text.Split(',');
string[] endCoordinate = textBox2.Text.Split(',');
double x1 = SpatialReferenceHelper.ConvertDegreesToDigital(startCoordinate[0]);
double y1 = SpatialReferenceHelper.ConvertDegreesToDigital(startCoordinate[1]);
double x2 = SpatialReferenceHelper.ConvertDegreesToDigital(endCoordinate[0]);
double y2 = SpatialReferenceHelper.ConvertDegreesToDigital(endCoordinate[1]);
IPoint startPoint = new PointClass();
startPoint.PutCoords(x1, y1);
startPoint.SpatialReference = LocateHelper.GeoCoordinateSystem;
startPoint.Project(mainForm.MapForm.axMapControl1.SpatialReference);
IPoint endPoint = new PointClass();
endPoint.PutCoords(x2, y2);
endPoint.SpatialReference = LocateHelper.GeoCoordinateSystem;
endPoint.Project(mainForm.MapForm.axMapControl1.SpatialReference); IFeatureLayer featurelayer = MapApi.CreateFeatureLayerInMemeory("点图层", "点图层", LocateHelper.GeoCoordinateSystem, esriGeometryType.esriGeometryPoint, null);
IFeature feature = featurelayer.FeatureClass.CreateFeature();
feature.Shape = startPoint;
feature.Store();
feature = featurelayer.FeatureClass.CreateFeature();
feature.Shape = endPoint;
feature.Store();
③ 求解(这里建议 try catch 一下)
int rowsIn = 0, rowsLocated = 0;
IFeatureCursor featureCursor = featurelayer.FeatureClass.Search(null, true);
classLoader.Load((ICursor)featureCursor, null, ref rowsIn, ref rowsLocated);
((INAContextEdit)m_NAContext).ContextChanged(); IGPMessages gpMessages = new GPMessagesClass();
m_NAContext.Solver.Solve(m_NAContext, gpMessages, null); //求解
好了,进行到这里的时候就能看到导航效果了。附图一张
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvemRiMzMwOTA2NTMx/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">
遇到的问题:因为不存在 Network Analyst 许可,操作失败。
參考官方样例 ClosestFacilitySolver 又一次授权就可以
參考资料:
http://resources.arcgis.com/zh-cn/help/main/10.1/index.html#//00470000005w000000
http://download.csdn.net/download/PMC_520/766131
http://blog.csdn.net/chanyinhelv/article/details/15498845
ArcEngine 地图导航 查找路径 经纬度坐标导航 最优路径分析的更多相关文章
- 利用百度地图API,获取经纬度坐标
利用百度地图API,获取经纬度坐标 代码很简单,但在网上没找到现成的获取地图经纬度的页面. 就是想,给当前页面传递一个经纬度,自动定位到此经纬度.然后可以重新选择,选择完返回经纬度. 效果如下: 源代 ...
- 百度地图 echarts tooltip属性 经纬度坐标不显示
中国地图.散点图结合点击后显示当前城市数量 不显示经纬度坐标 echarts.appMap = function (id, opt) { // 实例 var chart = this.init(doc ...
- 批量调用百度地图API获取地址经纬度坐标
1 申请密匙 注册百度地图API:http://lbsyun.baidu.com/index.php?title=webapi 点击左侧 “获取密匙” ,经过填写个人信息.邮箱注册等,成功之后在开放平 ...
- iOS第三方地图-高德地图(导航sdk路径规划)
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
- Android高效率编码-第三方SDK详解系列(一)——百度地图,绘制,覆盖物,导航,定位,细腻分解!
Android高效率编码-第三方SDK详解系列(一)--百度地图,绘制,覆盖物,导航,定位,细腻分解! 这是一个系列,但是我也不确定具体会更新多少期,最近很忙,主要还是效率的问题,所以一些有效的东西还 ...
- ArcEngine下投影坐标和经纬度坐标的相互转换
jojojojo2002 原文 ArcEngine下投影坐标和经纬度坐标的相互转换 投影转经纬度 private IPoint PRJtoGCS( double x, double y) { IPoi ...
- 地图经纬度坐标与屏幕坐标的转换(android版)
我们在开发GIS系统的时候,首先要解决的就是地图的可视化问题,这个问题的关键就在于如何把地图的坐标转换成屏幕坐标,然后才到渲染着色.标注等.以下以wgs84经纬度坐标为基准,介绍一下地图经纬度坐标与屏 ...
- iOS 屏幕原点坐标 && 导航栏风格的自定义
其一 屏幕原点坐标 (x ,y) 受 self.navigationController. navigationBar 的 setTranslucent (BOOL) 属性控制 在 iOS7 以后 ...
- baidu地图api , 地理位置转 经纬度接口
更多可以查看 http://lbsyun.baidu.com/index.php?title=webapi/guide/webservice-geocoding 地理编码示例: 以下是关于地理编 ...
随机推荐
- pull的时候报错
- C - Domino piling
Problem description You are given a rectangular board of M × N squares. Also you are given an unlimi ...
- Django中关于MySQL的bug总结
bug one: You are trying to add a non-nullable field 'height' to person without a default; we can't d ...
- 构造函数中this,return的详解
function Foo(name,age){ this.name=name; this.age=age; } var foo=new Foo("Tom",14); foo.nam ...
- 查看 Android App 的 versionCode
有 App 源码时,可以直接查看 AndroidManifest.xml 文件. <manifest android:versionName="1.4" android:ve ...
- Windows下错误码全解析
windows系统下,调用函数出错时.可以调用GetLastError函数返回错误码.但是GetLastError函数返回值是DWORD类型,是一个整数.如果想要知道函数调用的真正错误原因,就需要对这 ...
- AI:恐怖谷理论的陷阱
科学人的小品:恐怖谷:娃娃为什么很可怕? 一.恐怖的来源 恐怖的来源:美学概念.思想对安全的认识,映射到美学领域,转化为美和丑.恐怖,是一种精心掩饰的丑陋. 二.桑尼与C3PO 桑尼更接近于人,为什么 ...
- C#面对“重载”的Win 32 函数
在Win32 Api中有很多添加/设置函数在参数上支持多种不同类型的结构体.这些参数定义为LPVOID* 或者LPBYTE,LPVOID*一般由Win32 分配内存空间,在C#从通过System.In ...
- C# for 遍历 IPagedList
IPagedList<Doc> ss = Doclist.ToPagedList(page, pageSize); ;i<ss.Count;i++) { var yy = ss[i] ...
- phpStudy 升级 MySQL版本
1:停止phpStudy ,Mysql 服务;删除Mysql 文件夹 替换为新版本的Mysql 2:复制一份 my-default.ini,改名 my.ini ,打开,在最后面加上: basedir= ...