1. 程式人生 > >Arcengine開發所遇錯誤解決方案(持續更新)

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