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

错误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



©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页