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); //求解

好了,进行到这里的时候就能看到导航效果了。附图一张

遇到的问题:由于不存在 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

时间: 2024-10-28 07:36:43

ArcEngine 地图导航 查找路径 经纬度坐标导航 最优路径分析的相关文章

利用百度地图API,获取经纬度坐标

利用百度地图API,获取经纬度坐标 代码很简单,但在网上没找到现成的获取地图经纬度的页面. 就是想,给当前页面传递一个经纬度,自动定位到此经纬度.然后可以重新选择,选择完返回经纬度. 效果如下: 源代码下载:http://files.cnblogs.com/zjfree/select_map.rar 利用百度地图API,获取经纬度坐标,布布扣,bubuko.com

经纬度坐标与地图容器像素坐标相互转换

<!doctype html> <html> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="initial-scale=1.0, user-scalable=no, wi

iOS第三方地图-高德地图(导航sdk路径规划)

高德地图导航sdk的路径规划获取行程信息主要用到AMapNaviManager这个类 然后调下面的方法 /*! @brief 带起点的驾车路径计算 @param startPoints 起点坐标.支持多个起点,起点列表的尾点为实际导航起点,其他坐标点为辅助信息,带有方向性,可有效避免算路到马路的另一侧. @param endPoints 终点坐标.支持多个终点,终点列表的尾点为实际导航终点,其他坐标点为辅助信息,带有方向性,可有效避免算路到马路的另一侧. @param wayPoints 途经点

百度地图API详解之公交导航

原文地址:http://blog.csdn.net/sup_heaven/article/details/8461593 只是作为备忘!!! 一次调试百度地图多marker事件监听的问题,不知如何解决,后来看了原作者jz1108才知道要用闭包.觉得原作者jz1108关于百度地图的文章写的不错,所以转载到了CSDN,为了尊重原作者jz1108,特此说明. 前面我们介绍过驾车导航了,今天来说说公交导航. 什么是公交导航 公交导航功能是告诉使用者从A到B的公交出行方案,而不是某条具体的公交线路信息,这

Excel中的的经纬度坐标在地图上显示

Excel中有这样关于经纬度的数据: 22.56614225 113.9808368 22.68620526 113.9405252 22.57651183 113.957198 22.56484081 114.2445711 22.55888775 113.9507227 22.55899906 114.2413174 22.54900371 113.9722597 22.56277351 113.9565735 22.50001192 113.8956606 22.5437861 113.9

百度地图多边形画区域、获取节点经纬度坐标、判断某一点是否在此区域内

创建可绘画map: 1 <!DOCTYPE html> 2 3 <html> 4 <head> 5 <meta charset="UTF-8"> 6 <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1, user-scalable=no"> 7 <meta name=&

地图经纬度坐标与屏幕坐标的转换(android版)

我们在开发GIS系统的时候,首先要解决的就是地图的可视化问题,这个问题的关键就在于如何把地图的坐标转换成屏幕坐标,然后才到渲染着色.标注等.以下以wgs84经纬度坐标为基准,介绍一下地图经纬度坐标与屏幕坐标转换的问题.   一.比例尺 首先地图本身就是表达地球上各种事物的空间分布.联系及时间中的发展变化状态绘制的图形.如何把地球上大量的空间信息显示在有限的地图上,这就是涉及到比例尺的问题.比例尺=图上距离与实际距离的比. 比例尺有resolution和scale两个概念 Resolution是指

iOS 屏幕原点坐标 &amp;&amp; 导航栏风格的自定义

其一 屏幕原点坐标 (x ,y) 受 self.navigationController. navigationBar 的 setTranslucent (BOOL) 属性控制 在 iOS7 以后  translucent  属性默认为 YES   该属性含义是 毛玻璃 半透明效果 YES  起始 坐标 为屏幕顶端 左上角 为 (0 , 0)  ,此时 UI展示的内容可透过 导航栏 NO   起始 坐标 为屏幕顶端 左上角 为 (0 , 20 + 44) 这个说明 起始坐标 在状态栏 和 导航栏

由经纬度坐标得到腾讯地图的瓦片/切片行列号

参考:https://blog.csdn.net/mygisforum/article/details/22997879 https://blog.csdn.net/u013929284/article/details/53614281 https://blog.csdn.net/shaxiaozilove/article/details/54908569 项目需要根据数据的瓦片行列号建立文件目录,而已知的位置信息是经纬度,下面是解决方法: 一.经纬度坐标 => 投影坐标:腾讯地图使用的是Web