Arcengine开发所遇错误解决方案(持续更新)

2023-05-16

错误1:ArcGIS无法嵌入互操作类型解决办法例:

 

无法嵌入互操作类型“ESRI.ArcGIS.Carto.FeatureLayerClass”。请改用适用的接口

 

解决:

 

1、展开当前项目(Project)的“引用”;

2、找到引用的“ESRI.ArcGIS.Carto”,然后鼠标右键--属性。

3、将“嵌入互操作类型”改为“False”

 

 

 

错误2:ArcGIS version not specified. You must call RuntimeManager.Bind before creat解决方法例:

1、打开

Program.cs把ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);这句放到Application.SetCompatibleTextRenderingDefault(false);和Application.Run(new Form1());之间应该就好了

2、在系统的入口添加下面的一行代码:

ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.EngineOrDesktop);

3、如果还不行When we migrate our code from ArcGis 9.3 to ArcGis 10 then this type of error occurs. 1.First we add Reference ESRI.ArcGis.ADF.Local

2.Add Reference ESRI.ArcGis.Version

3.Add Line 

“ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop); ”

prior to call any arcgis object.

4.In all ArcGis Reference property "Specific Version" set to false.

5.Now Go to Project menu of visual studio and there are one option "Add ArcGis License Checking" and Add this file to your project.

 

 

 

 

错误3:未能找到类型或命名空间名称“DevComponents”(是否缺少 using 指令或程序集引用?解决方法 例:

你将在VS2010里创建的项目,属性里,选择.netFramework3.5,就可以运行了,不会报错,跟版本有关。

 

 

 

错误4:解决类似"类型同时存在于ESRI.ArcGIS.AxMapControl.dll和ESRI.ArcGIS.MapControl.dll中"的错误

解决问题的要点是其中一个命名空间要取别名代替。取别名的方法如下,记得还得修改引用中程序集dll的别名

 

 

错误5:鼠标滑过显示要素tip

对于这个有两个方法:

第一种:通过将 axmapcontrol 自带的 ShowMapTips 属性设置为 true 来实现。

第二种:通过 .NET 自带的控件 ToolTip 来实现!

第一种代码:

private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
{
    axMapControl1.ShowMapTips = true;
    IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0) as IFeatureLayer;
    pFeatureLayer.DisplayField = "Name";
    pFeatureLayer.ShowTips = true;
}

第二种代码:
private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
{
 IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0) as IFeatureLayer;
    pFeatureLayer.DisplayField = "Name";
    pFeatureLayer.ShowTips = true;
    string pTip;
    pTip = pFeatureLayer.get_TipText(e.mapX, e.mapY, axMapControl1.ActiveView.FullExtent.Width / 10000);
    if (pTip != null)
    {
        toolTip1.SetToolTip(axMapControl1, "名称:" + pTip);
    }
    else           //当 ToolTip 空间显示的内容为 null 的时候,就不会显示了!相当于隐藏了!
    {
        toolTip1.SetToolTip(axMapControl1, "");
    }
}


以上两种方法都可以实现显示标注,但是第二种效果更好一点~!

 

错误6:为什么以前正常的代码,现在都编译都通不过了,提示什么“无法嵌入互操作类型...”


A:你用的是Visual Studio 2010和C# 4吧?如果是,那就对了。这个问题和Engine本身无关。
这是C# 4对COMInterop的一个改进,把创建CoClass时的类名的Class后缀去掉即可。不允许用CoClass本身,而必须用相应的接口来创建对象。
比如,

1.        IPoint p = new PointClass()

改为:

1.        IPoint p = new Point()




错误7:为什么以前正常的代码,现在一运行就报错,抛出异常BadImageFormatException

你的操作系统是64位的Windows吧?可是ArcGIS现在只有32位的,所以必须用X86平台生成项目。
打开项目属性,在“生成”选项卡中找到目标平台,把Any CPU改为x86,重新生成即可。


错误8:添加工具箱项,找到Engine的dll

这个问题还是补充地具体一些吧:
1、在VS工具箱内右键,添加选项卡,取名ArcGIS Windows Form
2、在新选项卡上右键,选择项
...
3、点浏览,找到
ESRI.ArcGIS.AxControls.dll(缺省安装在"C:\Program Files\ArcGIS\DotNet\ESRI.ArcGIS.AxControls.dll"),打开。
4、勾选中新出现的那几个ArcGIS的控件,点确定。

 


错误9:SceneControl滚轮缩放(C#)

首先,添加axSceneControl控件和linece控件,控件中添加ArcScene数据。

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Analyst3D;
using ESRI.ArcGIS.Geometry;
namespace wheel1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            this.MouseWheel += new System.Windows.Forms.MouseEventHandler
(this.axSceneControl1_Wheel);
        }
        private void Form1_Load(object sender, EventArgs e)
        {
        }
               
        private void axSceneControl1_Wheel(object sender,
System.Windows.Forms.MouseEventArgs e)
        {
            try
            {
                System.Drawing.Point pSceLoc = axSceneControl1.PointToScreen
(this.axSceneControl1.Location);
                System.Drawing.Point Pt = this.PointToScreen(e.Location);
                if (Pt.X < pSceLoc.X | Pt.X > pSceLoc.X + axSceneControl1.Width | Pt.Y <
pSceLoc.Y | Pt.Y > pSceLoc.Y + axSceneControl1.Height) return;
                double scale = 0.2;
                if (e.Delta < 0) scale = -0.2;
                ICamera pCamera = axSceneControl1.Camera;
                IPoint pPtObs = pCamera.Observer;
                IPoint pPtTar = pCamera.Target;
                pPtObs.X += (pPtObs.X - pPtTar.X) * scale;
                pPtObs.Y += (pPtObs.Y - pPtTar.Y) * scale;
                pPtObs.Z += (pPtObs.Z - pPtTar.Z) * scale;
                pCamera.Observer = pPtObs;
                axSceneControl1.SceneGraph.RefreshViewers();
            }
            catch (Exception ex)
            {
            }
        }
    }
}


错误10:SceneControl中汽车沿着指定线行走的问题(C#)

ILayer layer = axSceneControl1.SceneGraph.Scene.get_Layer(5);
            IFeatureLayer featurelayer = (IFeatureLayer)layer;
            IFeatureClass featureclass = featurelayer.FeatureClass;
            IFeature feature = featureclass.GetFeature(0);
            IPolyline polyline = (IPolyline )feature.Shape;
            double d = polyline.Length;
            IPoint point1 = new PointClass();
            IPoint point2 = new PointClass();
            for (int i = 2; i <= (int)d;i++ )
            {
                polyline.QueryPoint(esriSegmentExtension.esriNoExtension, i, false, point1);
                polyline.QueryPoint(esriSegmentExtension.esriExtendAtFrom , i-150, false, point2);
                point2 .Z =13;
                point2.X= point2.X +-50;
                ICamera camera = axSceneControl1.SceneViewer.Camera;
                IPoint point3=new PointClass ();
                point3.X = point1.X;
                point3.Y = point1.Y;
                point3.Z =13;
                camera.Target = point3;
                camera.Observer = point2;
                IScene pscene = axSceneControl1.SceneGraph.Scene;
                IMarker3DSymbol pmark3dsymbol = new Marker3DSymbolClass();
                pmark3dsymbol.CreateFromFile("E:\\3dmax\\汽车.3DS");
                IMarkerSymbol marksy = (IMarkerSymbol)pmark3dsymbol;
                marksy.Size = 20;
                marksy.Angle = 90;
                IElement pelement = new MarkerElementClass();
                IMarkerElement pmarkelement = (IMarkerElement)pelement;
                pmarkelement.Symbol = (IMarkerSymbol)marksy;
                pelement.Geometry = point1;
                IGraphicsLayer player = axSceneControl1.SceneGraph.Scene.BasicGraphicsLayer;
                IGraphicsContainer3D pgraphiccontainer3d = (IGraphicsContainer3D)player;
                pgraphiccontainer3d.DeleteAllElements();
                pgraphiccontainer3d.AddElement((IElement)pmarkelement);
                axSceneControl1.SceneGraph.RefreshViewers();
            }



错误11:Engine下在地图上写文字

void DrawTextToMap(string text, ESRI.ArcGIS.Geometry.Point point2)
        {
            //创建字体对象
            ITextSymbol textSymbol = new TextSymbol();
            //创建系统字体
            System.Drawing.Font drawFont = new System.Drawing.Font("Arial", 32, System.Drawing.FontStyle.Regular);
            //字体转换
           // textSymbol.Font = (stdole.IFontDisp)ESRI.ArcGIS.Utility.COMSupport.OLE.GetIFontDispFromFont(drawFont);
            textSymbol.Font = (stdole.IFontDisp)ESRI.ArcGIS.ADF.COMSupport.OLE.GetIFontDispFromFont(drawFont);
            textSymbol.Color = GetRGBColor(0, 0, 0);
            //创建字体路径
            ITextPath textPath = new BezierTextPath();  //to spline the text
            //Grab hold of the ISimpleTextSymbol interface through the ITextSymbol interface
            ISimpleTextSymbol simpleTextSymbol = (ISimpleTextSymbol)textSymbol;
            //Set the text path of the simple text symbol
            simpleTextSymbol.TextPath = textPath;
            IPoint m_point=new ESRI.ArcGIS.Geometry.Point();
        //    double xx = point2.X;
            m_point.X = point2.X;
            m_point.Y = point2.Y;
            //输出字体
            object oTextSymbol = textSymbol;
            object opointSymbol = m_point;
            mapControl.DrawText(m_point, text, ref oTextSymbol);   
        }


        private IRgbColor GetRGBColor(int red, int green, int blue)
        {
            //Create rgb color and grab hold of the IRGBColor interface
            IRgbColor rGB = new RgbColor();
            //Set rgb color properties
            rGB.Red = red;
            rGB.Green = green;
            rGB.Blue = blue;
            rGB.UseWindowsDithering = true;
            return rGB;
        }




错误12:查询高亮显示后,如何使查询要素放大到一定的比例尺

首先,确定你的图层是否设置了MinimumScale属性,如果设置了请把该属性去掉;
然后,利用ControlsZoomToSelectedCommandClass接口,代码如下:

ICommand pCommand = new ControlsZoomToSelectedCommandClass();
pCommand.OnCreate(axMapControl1.Object);
pCommand.OnClick();
即可实现缩放到选定要素
 
 #region 一个通过属性表中属性查找图形要素的小功能
        private void dataGridView1_SelectionChanged(object sender, EventArgs e)
        {
            DataGridViewSelectedRowCollection SelRows = this.dataGridView1.SelectedRows;
            DataGridViewRow row;
            RibbonForm1 form = (RibbonForm1)Application.OpenForms[0];
            IMap m = form.getMapControl().Map;
            m.ClearSelection();
            for (int i = 0; i < SelRows.Count; i++)
            {
              row = SelRows[i];
              int ID = Convert.ToInt32(row.Cells["OBJECTID"].Value.ToString());
              IFeatureLayer flyr = (IFeatureLayer)layer;
              IFeatureClass featurecls = flyr.FeatureClass;
              IFeature feature = featurecls.GetFeature(ID);
              m.SelectFeature(layer, feature);//获取属性表中选中行对应的图形要素
            }
            //form.getMapControl().Refresh();
            //放大到一定的比例尺 实现选中要素的显示
            ICommand pCommand = new ControlsZoomToSelectedCommandClass();
            //pCommand.OnCreate(axMapControl1.Object);
            pCommand.OnCreate(form.getMapControl().Object);
            pCommand.OnClick();


        }
        #endregion



错误13:将地图导出为图片的两种方法

在ArcGIS的开发中,我们经常需要将当前地图打印(或是转出)到图片文件中。将Map或Layout中的图象转出有两种方法,一种为通过 IActiveView的OutPut函数,另外一种是通过IExport接口来实现。第一种方法导出速度较快,实现也比较方便,但该方法对于图片的行或列数超过10000左右时,导出经常会失败(具体原因未知),第二种方法导出速度较慢,但效果较好,且可以在导出过程中通过ITrackCancel来中止导出操作。
   通过IActiveView的方式导出是通过创建Graphics对象来实现,具体示例代码如下:

/// <summary>


/// 将Map上指定范围(该范围为规则区域)内的内容输出到Image,注意,当图片的行数或列数超过10000左右时,出现原因示知的失败


/// </summary>


/// <param name="pMap">需转出的MAP</param>
/// <param name="outRect">输出的图片大小</param>
/// <param name="pEnvelope">指定的输出范围(为Envelope类型)</param>
/// <returns>输出的Image 具体需要保存为什么格式,可通过Image对象来实现</returns>
public static Image SaveCurrentToImage(IMap pMap, Size outRect, IEnvelope pEnvelope)
 {
      //赋值
      tagRECT rect = new tagRECT();
      rect.left = rect.top = 0;
      rect.right = outRect.Width;
      rect.bottom = outRect.Height;
      try
      {                
          //转换成activeView,若为ILayout,则将Layout转换为IActiveView
          IActiveView pActiveView = (IActiveView)pMap;
          // 创建图像,为24位色
          Image image = new Bitmap(outRect.Width, outRect.Height); //, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
          System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(image);


          // 填充背景色(白色)
          g.FillRectangle(Brushes.White, 0, 0, outRect.Width, outRect.Height);


          int dpi = (int)(outRect.Width / pEnvelope.Width);


          pActiveView.Output(g.GetHdc().ToInt32(), dpi, ref rect, pEnvelope, null);


          g.ReleaseHdc();            


          return image;
     }


     catch (Exception excp)
     {
        MessageBox.Show(excp.Message + "将当前地图转出出错,原因未知", "出错提示", MessageBoxButtons.OK, MessageBoxIcon.Error);


          return null;
      }
 }


   通过IExport接口实现的导出,也需要通过IActiveView的OutPut来实现,但其转出句柄为IExport的StartExporting函数返回的DC,具体示例代码如下:


//输出当前地图至指定的文件    
public void ExportMapExtent(IActiveView pView, Size outRect,string outPath)
{           
    try
    {
        //参数检查
        if pView == null )
        {
            throw new Exception("输入参数错误,无法生成图片文件!");
        }  
        //根据给定的文件扩展名,来决定生成不同类型的对象
        ESRI.ArcGIS.Output.IExport export = null;
        if (outPath.EndsWith(".jpg"))
        {
            export = new ESRI.ArcGIS.Output.ExportJPEGClass();
        }
        else if (outPath.EndsWith(".tiff"))
        {
            export = new ESRI.ArcGIS.Output.ExportTIFFClass();
        }
        else if (outPath.EndsWith(".bmp"))
        {
            export = new ESRI.ArcGIS.Output.ExportBMPClass();
        }
        else if (outPath.EndsWith(".emf"))
        {
            export = new ESRI.ArcGIS.Output.ExportEMFClass();
        }
        else if (outPath.EndsWith(".png"))
        {
            export = new ESRI.ArcGIS.Output.ExportPNGClass();
        }
        else if (outPath.EndsWith(".gif"))
        {
            export = new ESRI.ArcGIS.Output.ExportGIFClass();
        }


        export.ExportFileName = outPath;
        IEnvelope pEnvelope = pView.Extent;
        //导出参数           
        export.Resolution = 300;
        tagRECT exportRect = new tagRECT();
        exportRect.left = exportRect.top = 0;
        exportRect.right = outRect.Width;
        exportRect.bottom = (int)(exportRect.right * pEnvelope.Height / pEnvelope.Width);
        ESRI.ArcGIS.Geometry.IEnvelope envelope = new ESRI.ArcGIS.Geometry.EnvelopeClass();
        //输出范围
        envelope.PutCoords(exportRect.left, exportRect.top, exportRect.right, exportRect.bottom);
        export.PixelBounds = envelope;
        //可用于取消操作
        ITrackCancel pCancel = new CancelTrackerClass();
        export.TrackCancel = pCancel;
        pCancel.Reset();
        //点击ESC键时,中止转出
        pCancel.CancelOnKeyPress = true;
        pCancel.CancelOnClick = false;
        pCancel.ProcessMessages = true;
        //获取handle
        System.Int32 hDC = export.StartExporting();
        //开始转出
        pView.Output(hDC, (System.Int16)export.Resolution, ref exportRect, pEnvelope, pCancel);
        bool bContinue = pCancel.Continue();
        //捕获是否继续
        if (bContinue)
        {                              
            export.FinishExporting();
            export.Cleanup();
        }
        else
        {                  
            export.Cleanup();
        }
        bContinue = pCancel.Continue();               
    }
    catch (Exception excep)
    {
        //错误信息提示
    }
}



错误14:ArcEngine 最短路径分析

using System;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.NetworkAnalysis;
namespace GisEditor
{
 /// <summary>
 /// 最短路径分析
 /// </summary>
 public class ClsPathFinder
 {
  private IGeometricNetwork m_ipGeometricNetwork;
  private IMap m_ipMap;
  private IPointCollection m_ipPoints;
  private IPointToEID m_ipPointToEID;
  private double m_dblPathCost =0;
  private IEnumNetEID m_ipEnumNetEID_Junctions;
  private IEnumNetEID m_ipEnumNetEID_Edges;
  private IPolyline   m_ipPolyline;
  #region Public Function
  //返回和设置当前地图
  public IMap SetOrGetMap
  {
   set{ m_ipMap = value;}
   get{return   m_ipMap;}
  }
  //打开几何数据集的网络工作空间
  public void OpenFeatureDatasetNetwork(IFeatureDataset FeatureDataset)
  {
   CloseWorkspace();  
   if (!InitializeNetworkAndMap(FeatureDataset))
    Console.WriteLine( "打开network出错");
  }
  //输入点的集合
  public IPointCollection StopPoints
  {
   set{m_ipPoints= value;}
   get{return   m_ipPoints;}
  }
  
  //路径成本
  public double PathCost
  {
   get {return m_dblPathCost;}
  }
  
  //返回路径的几何体
  public IPolyline PathPolyLine()
  {
   IEIDInfo ipEIDInfo;
   IGeometry ipGeometry;   
   if(m_ipPolyline!=null)return m_ipPolyline;
   
   m_ipPolyline = new PolylineClass();
   IGeometryCollection ipNewGeometryColl = m_ipPolyline as IGeometryCollection;
   
   ISpatialReference ipSpatialReference = m_ipMap.SpatialReference;
   IEIDHelper ipEIDHelper = new EIDHelperClass();
   ipEIDHelper.GeometricNetwork = m_ipGeometricNetwork;  
   ipEIDHelper.OutputSpatialReference = ipSpatialReference;
   ipEIDHelper.ReturnGeometries = true;
   IEnumEIDInfo ipEnumEIDInfo = ipEIDHelper.CreateEnumEIDInfo(m_ipEnumNetEID_Edges);
   int count = ipEnumEIDInfo.Count;
   ipEnumEIDInfo.Reset();
   for(int i =0;i<count;i++)
   {
    ipEIDInfo = ipEnumEIDInfo.Next();
    ipGeometry = ipEIDInfo.Geometry;
    ipNewGeometryColl.AddGeometryCollection( ipGeometry as IGeometryCollection);
   }
   return m_ipPolyline;
  }
  
  //解决路径
  public void SolvePath(string WeightName)
  {
   try
   {  
    int intEdgeUserClassID;
    int intEdgeUserID;
    int intEdgeUserSubID;
    int intEdgeID;
    IPoint ipFoundEdgePoint;
    double dblEdgePercent;    
    
    ITraceFlowSolverGEN  ipTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN;
    INetSolver ipNetSolver = ipTraceFlowSolver as INetSolver;
    INetwork ipNetwork = m_ipGeometricNetwork.Network;
    ipNetSolver.SourceNetwork = ipNetwork;
    INetElements ipNetElements = ipNetwork as INetElements;
    int intCount = m_ipPoints.PointCount;
    //定义一个边线旗数组
    IEdgeFlag[] pEdgeFlagList = new EdgeFlagClass[intCount];
    for(int i = 0;i<intCount ;i++)
    {
     
     INetFlag ipNetFlag = new EdgeFlagClass()as INetFlag;
     IPoint  ipEdgePoint = m_ipPoints.get_Point(i);
     //查找输入点的最近的边线
     m_ipPointToEID.GetNearestEdge(ipEdgePoint, out intEdgeID,out ipFoundEdgePoint, out dblEdgePercent);
     ipNetElements.QueryIDs( intEdgeID, esriElementType.esriETEdge, out intEdgeUserClassID, out intEdgeUserID,out intEdgeUserSubID);
     ipNetFlag.UserClassID = intEdgeUserClassID;
     ipNetFlag.UserID = intEdgeUserID;
     ipNetFlag.UserSubID = intEdgeUserSubID;
     IEdgeFlag pTemp = (IEdgeFlag)(ipNetFlag as IEdgeFlag);
     pEdgeFlagList[i]=pTemp;   
    }
    ipTraceFlowSolver.PutEdgeOrigins(ref pEdgeFlagList);
    INetSchema ipNetSchema = ipNetwork as INetSchema;
    INetWeight ipNetWeight = ipNetSchema.get_WeightByName(WeightName);
    INetSolverWeights ipNetSolverWeights = ipTraceFlowSolver as INetSolverWeights;
    ipNetSolverWeights.FromToEdgeWeight = ipNetWeight;//开始边线的权重
    ipNetSolverWeights.ToFromEdgeWeight = ipNetWeight;//终止边线的权重
    object [] vaRes =new object[intCount-1];
    //通过findpath得到边线和交汇点的集合
    ipTraceFlowSolver.FindPath(esriFlowMethod.esriFMConnected,
     esriShortestPathObjFn.esriSPObjFnMinSum,
     out m_ipEnumNetEID_Junctions,out m_ipEnumNetEID_Edges, intCount-1, ref vaRes);
    //计算元素成本
    m_dblPathCost = 0;
    for (int i =0;i<vaRes.Length;i++)
    {
     double m_Va =(double) vaRes[i];
     m_dblPathCost = m_dblPathCost + m_Va;
    }     
    m_ipPolyline = null;
   }
   catch(Exception ex)
   {
    Console.WriteLine(ex.Message);
   }
  }
  #endregion
  #region Private Function
  //初始化几何网络和地图
  private bool InitializeNetworkAndMap(IFeatureDataset FeatureDataset)
  {
   IFeatureClassContainer ipFeatureClassContainer;
   IFeatureClass ipFeatureClass ;
   IGeoDataset ipGeoDataset;
   ILayer ipLayer ;
   IFeatureLayer ipFeatureLayer;
   IEnvelope ipEnvelope, ipMaxEnvelope ;
   double dblSearchTol;
   INetworkCollection ipNetworkCollection = FeatureDataset as INetworkCollection;
   int count = ipNetworkCollection.GeometricNetworkCount;
   //获取第一个几何网络工作空间
   m_ipGeometricNetwork = ipNetworkCollection.get_GeometricNetwork(0);
   INetwork ipNetwork = m_ipGeometricNetwork.Network;
   if(m_ipMap!=null)
   {
    m_ipMap = new MapClass();
    ipFeatureClassContainer = m_ipGeometricNetwork as IFeatureClassContainer;
    count = ipFeatureClassContainer.ClassCount;
    for(int i =0;i<count;i++)
    {
     ipFeatureClass = ipFeatureClassContainer.get_Class(i);     
     ipFeatureLayer = new FeatureLayerClass();
     ipFeatureLayer.FeatureClass = ipFeatureClass;    
     m_ipMap.AddLayer( ipFeatureLayer);
    }
   }
   count = m_ipMap.LayerCount;
   ipMaxEnvelope = new EnvelopeClass();
   for(int i =0;i<count;i++)
   {
    ipLayer = m_ipMap.get_Layer(i);
    ipFeatureLayer = ipLayer as IFeatureLayer;   
    ipGeoDataset = ipFeatureLayer as IGeoDataset;
    ipEnvelope = ipGeoDataset.Extent;   
    ipMaxEnvelope.Union( ipEnvelope);
   }
   m_ipPointToEID = new PointToEIDClass();
   m_ipPointToEID.SourceMap = m_ipMap;
   m_ipPointToEID.GeometricNetwork = m_ipGeometricNetwork;
   double dblWidth = ipMaxEnvelope.Width;
   double dblHeight = ipMaxEnvelope.Height;
   if( dblWidth > dblHeight)
    dblSearchTol = dblWidth / 100;
   else
    dblSearchTol = dblHeight / 100;
   m_ipPointToEID.SnapTolerance = dblSearchTol;
   return true  ;
  }
  //关闭工作空间           
  private void CloseWorkspace()
  {
   m_ipGeometricNetwork = null;
   m_ipPoints = null;
   m_ipPointToEID = null;
   m_ipEnumNetEID_Junctions = null;
   m_ipEnumNetEID_Edges = null;
   m_ipPolyline = null;
  }
 
  #endregion
 
 }
}
备注:
在调用该类时的次序:
ClsPathFinder  m_ipPathFinder;
if(m_ipPathFinder==null)//打开几何网络工作空间
   {
    m_ipPathFinder = new ClsPathFinder();
    ipMap = this.m_ActiveView.FocusMap;
    ipLayer = ipMap.get_Layer(0);
    ipFeatureLayer = ipLayer as IFeatureLayer;
    ipFDB = ipFeatureLayer.FeatureClass.FeatureDataset;
    m_ipPathFinder.SetOrGetMap = ipMap;
    m_ipPathFinder.OpenFeatureDatasetNetwork(ipFDB);
   }
private void ViewMap_OnMouseDown(object sender, ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseDownEvent e)//获取地图上鼠标输入的点
  {
   IPoint ipNew ; 
   if( m_ipPoints==null)
   {
    m_ipPoints = new MultipointClass();
    m_ipPathFinder.StopPoints = m_ipPoints;
   }
   ipNew = ViewMap.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x,e.y);
   object o = Type.Missing;
   m_ipPoints.AddPoint(ipNew,ref o,ref o);   
  }
m_ipPathFinder.SolvePath("Weight");//先解析路径
IPolyline ipPolyResult = m_ipPathFinder.PathPolyLine();//最后返回最短路径


错误 15:无法将文件“obj\x86\Debug\codeprocess.exe”复制到“bin\Debug\codeprocess.exe”。文件“bin\Debug\codeprocess.exe”正由另一进程使用,因此该进程无法访问此文件。

在任务管理器中结束这一进程就行了obj\Debug\EntryOutStock.exe

错误16:ArcEngine打开shapefile时报错 HRESULT:0x80040258

 private IFeatureClass OpenShp(string pTableName, string pShpPath)
        {
            try
            {
                    IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
                    IWorkspace pWorkspace =pWorkspaceFactory.OpenFromFile(pShpPath,0); 
                    IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
                    IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(pTableName);

                    return pFeatureClass;

            }
            catch (Exception ex)
            {
                return null;
            }
        }

走到红字的那行就报错了,后来才知道不是代码的问题,是带进去的参数不对了

pShpPath 只是路径名字,比如C:\\AAA

不是文件的全路径名字

我带进去了C:\\AAA\\BBB.shp所以就出错了

原来arcengine开发shapefile时,是把一个文件夹当作一个工作空间打开了,文件夹中的每一个shape文件又对应一个featureclass



本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Arcengine开发所遇错误解决方案(持续更新) 的相关文章

  • 组合导航(GNSS+惯性导航)

    一 GNSS 至少需要四颗星 怎么判断GNSS数据是否准确 xff1f 数据中是否携带星数 xff1f 二 惯性导航 关于磁力计的使用 xff1a 1 xff09 类似重力 xff0c 磁力也是一个矢量 地球任意位置的磁力在东北天地理系下的
  • VR/AR技术杂选

    相机频率 xff1a 一般来说 xff0c 相机频率60Hz是指相机的帧率为60fps xff0c 即frame per second 每秒钟60帧 红外探测器 xff1a 分为两种 xff0c 一种是基于光电特性 xff0c 一种是基于热
  • 百度2014校园招聘-研发工程师笔试题(济南站)

    一 xff0c 简答题 30分 1 xff0c 当前计算机系统一般会采用层次结构存储数据 xff0c 请介绍下典型计算机存储系统一般分为哪几个层次 xff0c 为什么采用分层存储数据能有效提高程序的执行效率 xff1f xff08 10分
  • 生产者消费者模式代码实现

    生产者消费者模式 xff1a 不同种类的线程间针对同一个资源的操作 问题 xff1a A xff1a 如果消费者先抢到cpu的执行权 xff0c 就会去消费数据 xff0c 但是现在的数据是默认值 xff0c 没有意义 xff0c 应该等着
  • 转载 本机运行x程序出现:Can't open display 原因及其解决方法

    在Linux Unix类操作系统上 DISPLAY用来设置将图形显示到何处 直接登陆图形界面或者登陆命令行界面后使用startx启动图形 DISPLAY环境变量将自动设置为 0 0 此时可以打开终端 输出图形程序的名称 比如xclock 来
  • 另一种root方法,Android boot.img破解

    一 破解原理 nbsp nbsp nbsp Android手机获得Root权限 其实就是让 system和 data分区获得读写的权限 这两个分区的权限配置 一般在根分区的init rc文件中 修改这个文件可永久获得root权限 众所周知
  • BPMN基础元素及任务类型

    01 BPMN定义 BPMN xff08 Business Process Modeling Notation xff0c 即业务流程建模符号 xff09 xff0c 是一种流程建模的通用和标准语言 xff0c 用来绘制业务流程图 xff0
  • Python 程序出现ImportError: cannot import name 'is_string_like' 解决办法

    今天的一个project写了如下代码 xff1a from skimage import os xff0c transform 运行后报错 xff1a from matplotlib cbook import is string like
  • ASP.NET中主题的创建和应用

    1创建ASP NET网站 模板 gt 选择 添加ASP NET文件夹 下面的属性 xff0c 将主题名改为 xff1a mytheme xff1b 添加新建项选择 外观文件 xff0c 命名为TextBox 双击TextBox skin文件
  • canvas画波形图

    最近公司要在浏览器上加个波形图 xff0c 本人搞C 43 43 的 xff0c 不会html5 xff0c 在网上搜了半天没找到一个例子 xff0c 只好自己研究了 郁闷啊 画这个图主要用到html5的canvas xff0c 不多说 x
  • layer 弹框 cropper 裁剪上传图片,thinkphp 3 使用 CropAvatar.class.php

    最近要做一个上传裁剪图片功能 xff0c 但是网上收出来的东西 xff0c 知识点都是对的 但是就是没说清楚 xff0c 也无法连续起来用 经过自己整理出来的一套代码 xff0c 亲测可用 xff01 不用多说 xff0c 直接上菜 PS
  • 解决mysql登录出现10061的问题

    问题出现的原因 xff1a 可能是系统自动关闭了mysql服务的运行 解决方法 xff1a 任务管理器 文件 运行新任务 services msc 找到mysql 启动即可成功 任务管理器 文件 运行新任务 services msc 找到m
  • Archlinux配置邮件(以qq邮箱为例)

    Archlinux配置邮件 以qq邮箱为例 安装s nail span class token function sudo span pacman S s nail 配置SMTP发送邮件 开启IMAP SMTP服务 打开qq邮箱网页版 gt
  • 电子爱好者总结的28个电子行业技术网站

    以下是一位电子爱好者总结的28个电子行业技术网站 21IC 电子 http www 21IC COM 中国电子资源网 xff1a http www ec66 com 中国电子进修网 http www studydz com 电子设计技术网
  • S_OK,S_FALSE,E_FAIL

    今天在调试一个ICOP的操作的时候 xff0c 发现连接被动关闭的时候老是会在一处断言处失败 xff0c 跟了很久终于发现了问题 在此记录一下 xff1a 断言报错的代码如下 xff1a HRESULT CIoCPWorker UnregI
  • Win7 应用程序无法正常启动(0xc000000d)的解决方法

    自从重装了WIN7系统后 xff0c VS2010编译出来的项目程序就不能正常启动 xff0c 启动的时候总是提示 应用程序无法正常启动 xff08 0xc000000d xff09 请单击 确定 关闭应用程序 在网上查找了很多解决方案 x
  • MySQL存储过程where条件执行失败的问题

    前几天对服务器实体做了属性缓存机制 xff0c 当时测试也没有出现大的问题 xff0c 昨天有人跟我说 xff0c 登陆的时候角色等级显示错误 xff0c 我复测了一下 xff0c 发现不只是等级错误 xff0c 进入游戏后角色位置 金钱
  • 程序员与厨师

    不管你信不信 反正我是信了 每一个程序员上辈子都是呆在厨房的厨子 好吧 你不信 我来证明给你看 1 下厨前 你得知道做的是早餐还是中晚餐 中晚餐的话 怎么也得走趟超市 如遇到好友聚会 怎么着也得做出一桌对得起朋友的饭菜 还有你得分析 朋友中
  • VS2010/VS2012 设置全局头文件和库路径

    在VS2010之前 xff0c 设置项目的全局头文件和库路径是非常方便的 xff0c 直接选择菜单Tools gt Options gt Projects and Solutions gt VC 43 43 Directories xff0
  • Linux下rz/sz安装及使用方法

    新搞的云服务器用SecureCRT不支持上传和下载 xff0c 没有找到rz命令 记录一下如何安装rz sz命令的方法 一 工具说明 在SecureCRT这样的ssh登录软件里 通过在Linux界面里输入rz sz命令来上传 下载文件 对于

随机推荐