为什么arcengine二次开发开发系统别人打开较慢

11645人阅读
ArcEngine(7)
错误1:无法嵌入互操作类型解决办法例:
无法嵌入互操作类型“ESRI.ArcGIS.Carto.FeatureLayerClass”。请改用适用的接口
1、展开当前项目(Project)的“引用”;
2、找到引用的“ESRI.ArcGIS.Carto”,然后鼠标右键--属性。
3、将“嵌入互操作类型”改为“False”
错误2:解决方法例:
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 =
IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0) as IFeatureL
pFeatureLayer.DisplayField = &Name&;
pFeatureLayer.ShowTips =
}第二种代码:
private void axMapControl1_OnMouseMove(object sender, IMapControlEvents2_OnMouseMoveEvent e)
IFeatureLayer pFeatureLayer = axMapControl1.Map.get_Layer(0) as IFeatureL
pFeatureLayer.DisplayField = &Name&;
pFeatureLayer.ShowTips =
pTip = pFeatureLayer.get_TipText(e.mapX, e.mapY, axMapControl1.ActiveView.FullExtent.Width / 10000);
if (pTip != null)
toolTip1.SetToolTip(axMapControl1, &名称:& + pTip);
//当 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.Collections.G
using System.D
using System.D
using System.T
using System.Windows.F
using ESRI.ArcGIS.Analyst3D;
using ESRI.ArcGIS.G
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)
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)
double scale = 0.2;
if (e.Delta & 0) scale = -0.2;
ICamera pCamera = axSceneControl1.C
IPoint pPtObs = pCamera.O
IPoint pPtTar = pCamera.T
pPtObs.X += (pPtObs.X - pPtTar.X) *
pPtObs.Y += (pPtObs.Y - pPtTar.Y) *
pPtObs.Z += (pPtObs.Z - pPtTar.Z) *
pCamera.Observer = pPtO
axSceneControl1.SceneGraph.RefreshViewers();
catch (Exception ex)
错误10:SceneControl中汽车沿着指定线行走的问题(C#)
ILayer layer = axSceneControl1.SceneGraph.Scene.get_Layer(5);
IFeatureLayer featurelayer = (IFeatureLayer)
IFeatureClass featureclass = featurelayer.FeatureC
IFeature feature = featureclass.GetFeature(0);
IPolyline polyline = (IPolyline )feature.S
double d = polyline.L
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.C
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.S
IMarker3DSymbol pmark3dsymbol = new Marker3DSymbolClass();
pmark3dsymbol.CreateFromFile(&E:\\3dmax\\汽车.3DS&);
IMarkerSymbol marksy = (IMarkerSymbol)pmark3
marksy.Size = 20;
marksy.Angle = 90;
IElement pelement = new MarkerElementClass();
IMarkerElement pmarkelement = (IMarkerElement)
pmarkelement.Symbol = (IMarkerSymbol)
pelement.Geometry = point1;
IGraphicsLayer player = axSceneControl1.SceneGraph.Scene.BasicGraphicsL
IGraphicsContainer3D pgraphiccontainer3d = (IGraphicsContainer3D)
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.Support.OLE.GetIFontDispFromFont(drawFont);
textSymbol.Font = (stdole.IFontDisp)ESRI.Support.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)textS
//Set the text path of the simple text symbol
simpleTextSymbol.TextPath = textP
IPoint m_point=new ESRI.ArcGIS.Geometry.Point();
double xx = point2.X;
m_point.X = point2.X;
m_point.Y = point2.Y;
//输出字体
object oTextSymbol = textS
object opointSymbol = m_
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.Green =
rGB.Blue =
rGB.UseWindowsDithering =
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.SelectedR
DataGridViewR
RibbonForm1 form = (RibbonForm1)Application.OpenForms[0];
IMap m = form.getMapControl().M
m.ClearSelection();
for (int i = 0; i & SelRows.C i++)
row = SelRows[i];
int ID = Convert.ToInt32(row.Cells[&OBJECTID&].Value.ToString());
IFeatureLayer flyr = (IFeatureLayer)
IFeatureClass featurecls = flyr.FeatureC
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.W
rect.bottom = outRect.H
//转换成activeView,若为ILayout,则将Layout转换为IActiveView
IActiveView pActiveView = (IActiveView)pM
// 创建图像,为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();
catch (Exception excp)
MessageBox.Show(excp.Message + &将当前地图转出出错,原因未知&, &出错提示&, MessageBoxButtons.OK, MessageBoxIcon.Error);
通过IExport接口实现的导出,也需要通过IActiveView的OutPut来实现,但其转出句柄为IExport的StartExporting函数返回的DC,具体示例代码如下:
//输出当前地图至指定的文件
public void ExportMapExtent(IActiveView pView, Size outRect,string outPath)
//参数检查
if pView == null )
throw new Exception(&输入参数错误,无法生成图片文件!&);
//根据给定的文件扩展名,来决定生成不同类型的对象
ESRI.ArcGIS.Output.IExport export =
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 = outP
IEnvelope pEnvelope = pView.E
//导出参数
export.Resolution = 300;
tagRECT exportRect = new tagRECT();
exportRect.left = exportRect.top = 0;
exportRect.right = outRect.W
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 =
//可用于取消操作
ITrackCancel pCancel = new CancelTrackerClass();
export.TrackCancel = pC
pCancel.Reset();
//点击ESC键时,中止转出
pCancel.CancelOnKeyPress =
pCancel.CancelOnClick =
pCancel.ProcessMessages =
//获取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();
export.Cleanup();
bContinue = pCancel.Continue();
catch (Exception excep)
//错误信息提示
错误14:ArcEngine 最短路径分析
using ESRI.ArcGIS.C
using ESRI.ArcGIS.G
using ESRI.ArcGIS.G
using ESRI.ArcGIS.NetworkA
namespace GisEditor
/// &summary&
/// 最短路径分析
/// &/summary&
public class ClsPathFinder
private IGeometricNetwork m_ipGeometricN
private IMap m_ipM
private IPointCollection m_ipP
private IPointToEID m_ipPointToEID;
private double m_dblPathCost =0;
private IEnumNetEID m_ipEnumNetEID_J
private IEnumNetEID m_ipEnumNetEID_E
private IPolyline
#region Public Function
//返回和设置当前地图
public IMap SetOrGetMap
set{ m_ipMap =}
get{return
//打开几何数据集的网络工作空间
public void OpenFeatureDatasetNetwork(IFeatureDataset FeatureDataset)
CloseWorkspace();
if (!InitializeNetworkAndMap(FeatureDataset))
Console.WriteLine( &打开network出错&);
//输入点的集合
public IPointCollection StopPoints
set{m_ipPoints=}
get{return
//路径成本
public double PathCost
get {return m_dblPathC}
//返回路径的几何体
public IPolyline PathPolyLine()
IEIDInfo ipEIDI
IGeometry ipG
if(m_ipPolyline!=null)return m_ipP
m_ipPolyline = new PolylineClass();
IGeometryCollection ipNewGeometryColl = m_ipPolyline as IGeometryC
ISpatialReference ipSpatialReference = m_ipMap.SpatialR
IEIDHelper ipEIDHelper = new EIDHelperClass();
ipEIDHelper.GeometricNetwork = m_ipGeometricN
ipEIDHelper.OutputSpatialReference = ipSpatialR
ipEIDHelper.ReturnGeometries =
IEnumEIDInfo ipEnumEIDInfo = ipEIDHelper.CreateEnumEIDInfo(m_ipEnumNetEID_Edges);
int count = ipEnumEIDInfo.C
ipEnumEIDInfo.Reset();
for(int i =0;i&i++)
ipEIDInfo = ipEnumEIDInfo.Next();
ipGeometry = ipEIDInfo.G
ipNewGeometryColl.AddGeometryCollection( ipGeometry as IGeometryCollection);
return m_ipP
//解决路径
public void SolvePath(string WeightName)
int intEdgeUserClassID;
int intEdgeUserID;
int intEdgeUserSubID;
int intEdgeID;
IPoint ipFoundEdgeP
double dblEdgeP
ITraceFlowSolverGEN
ipTraceFlowSolver = new TraceFlowSolverClass() as ITraceFlowSolverGEN;
INetSolver ipNetSolver = ipTraceFlowSolver as INetS
INetwork ipNetwork = m_ipGeometricNetwork.N
ipNetSolver.SourceNetwork = ipN
INetElements ipNetElements = ipNetwork as INetE
int intCount = m_ipPoints.PointC
//定义一个边线旗数组
IEdgeFlag[] pEdgeFlagList = new EdgeFlagClass[intCount];
for(int i = 0;i&intCi++)
INetFlag ipNetFlag = new EdgeFlagClass()as INetF
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]=pT
ipTraceFlowSolver.PutEdgeOrigins(ref pEdgeFlagList);
INetSchema ipNetSchema = ipNetwork as INetS
INetWeight ipNetWeight = ipNetSchema.get_WeightByName(WeightName);
INetSolverWeights ipNetSolverWeights = ipTraceFlowSolver as INetSolverW
ipNetSolverWeights.FromToEdgeWeight = ipNetW//开始边线的权重
ipNetSolverWeights.ToFromEdgeWeight = ipNetW//终止边线的权重
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.Li++)
double m_Va =(double) vaRes[i];
m_dblPathCost = m_dblPathCost + m_Va;
m_ipPolyline =
catch(Exception ex)
Console.WriteLine(ex.Message);
#endregion
#region Private Function
//初始化几何网络和地图
private bool InitializeNetworkAndMap(IFeatureDataset FeatureDataset)
IFeatureClassContainer ipFeatureClassC
IFeatureClass ipFeatureC
IGeoDataset ipGeoD
ILayer ipL
IFeatureLayer ipFeatureL
IEnvelope ipEnvelope, ipMaxE
double dblSearchT
INetworkCollection ipNetworkCollection = FeatureDataset as INetworkC
int count = ipNetworkCollection.GeometricNetworkC
//获取第一个几何网络工作空间
m_ipGeometricNetwork = ipNetworkCollection.get_GeometricNetwork(0);
INetwork ipNetwork = m_ipGeometricNetwork.N
if(m_ipMap!=null)
m_ipMap = new MapClass();
ipFeatureClassContainer = m_ipGeometricNetwork as IFeatureClassC
count = ipFeatureClassContainer.ClassC
for(int i =0;i&i++)
ipFeatureClass = ipFeatureClassContainer.get_Class(i);
ipFeatureLayer = new FeatureLayerClass();
ipFeatureLayer.FeatureClass = ipFeatureC
m_ipMap.AddLayer( ipFeatureLayer);
count = m_ipMap.LayerC
ipMaxEnvelope = new EnvelopeClass();
for(int i =0;i&i++)
ipLayer = m_ipMap.get_Layer(i);
ipFeatureLayer = ipLayer as IFeatureL
ipGeoDataset = ipFeatureLayer as IGeoD
ipEnvelope = ipGeoDataset.E
ipMaxEnvelope.Union( ipEnvelope);
m_ipPointToEID = new PointToEIDClass();
m_ipPointToEID.SourceMap = m_ipM
m_ipPointToEID.GeometricNetwork = m_ipGeometricN
double dblWidth = ipMaxEnvelope.W
double dblHeight = ipMaxEnvelope.H
if( dblWidth & dblHeight)
dblSearchTol = dblWidth / 100;
dblSearchTol = dblHeight / 100;
m_ipPointToEID.SnapTolerance = dblSearchT
//关闭工作空间
private void CloseWorkspace()
m_ipGeometricNetwork =
m_ipPoints =
m_ipPointToEID =
m_ipEnumNetEID_Junctions =
m_ipEnumNetEID_Edges =
m_ipPolyline =
#endregion
在调用该类时的次序:
ClsPathFinder
if(m_ipPathFinder==null)//打开几何网络工作空间
m_ipPathFinder = new ClsPathFinder();
ipMap = this.m_ActiveView.FocusM
ipLayer = ipMap.get_Layer(0);
ipFeatureLayer = ipLayer as IFeatureL
ipFDB = ipFeatureLayer.FeatureClass.FeatureD
m_ipPathFinder.SetOrGetMap = ipM
m_ipPathFinder.OpenFeatureDatasetNetwork(ipFDB);
private void ViewMap_OnMouseDown(object sender, ESRI.ArcGIS.MapControl.IMapControlEvents2_OnMouseDownEvent e)//获取地图上鼠标输入的点
IPoint ipN
if( m_ipPoints==null)
m_ipPoints = new MultipointClass();
m_ipPathFinder.StopPoints = m_ipP
ipNew = ViewMap.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x,e.y);
object o = Type.M
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:0x
&private IFeatureClass OpenShp(string pTableName, string pShpPath)
&&&&&&&&&&& try
&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
&&&&&&&&&&&&&&&&&&&&IWorkspace pWorkspace =pWorkspaceFactory.OpenFromFile(pShpPath,0);&
&&&&&&&&&&&&&&&&&&& IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureW
&&&&&&&&&&&&&&&&&&& IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(pTableName);
&&&&&&&&&&&&&&&&&&& return pFeatureC
&&&&&&&&&&& }
&&&&&&&&&&& catch (Exception ex)
&&&&&&&&&&& {
&&&&&&&&&&&&&&&
&&&&&&&&&&& }
走到红字的那行就报错了,后来才知道不是代码的问题,是带进去的参数不对了
pShpPath&只是路径名字,比如C:\\AAA
不是文件的全路径名字
我带进去了C:\\AAA\\BBB.shp所以就出错了
原来arcengine开发shapefile时,是把一个文件夹当作一个工作空间打开了,文件夹中的每一个shape文件又对应一个featureclass
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:41333次
排名:千里之外
原创:25篇
转载:13篇
(1)(1)(1)(6)(1)(5)(3)(1)(2)(2)(16)2821人阅读
.net(115)
Arc Engine(65)
AE中对MDB,SDE等数据库操作时,打开后却往往不能及时释放资源,导致别人操作提示对象被锁定。
很多帖子说了很多原理,看的也烦且不实用,比如一句话概括的用System.Runtime.InteropServices.Marshal.ReleaseComObject(object o)释放,说的很不清楚,很多人试过觉的释放不掉。
事实上,的确是用该方法,但释放的技巧在于,新建几个AE对象就要逐步释放几个,例如:
IWorkspaceFactory Fact = new AccessWorkspaceFactoryClass ();
IFeatureWorkspace Workspace = Fact.Open(Propset,0) as IFeatureW
&&IFeatureClass Fcls = Workspace.OpenFeatureClass (&District&);
IFeatureLayer Fly = new FeatureLayerClass();
IFeature pf
IField&pfield
再对象运行结束时释放,如:
System.Runtime.InteropServices.Marshal.ReleaseComObject(Fact);
System.Runtime.InteropServices.Marshal.ReleaseComObject(Workspace);
System.Runtime.InteropServices.Marshal.ReleaseComObject(Fcls);
System.Runtime.InteropServices.Marshal.ReleaseComObject(Fly);
System.Runtime.InteropServices.Marshal.ReleaseComObject(pf);
System.Runtime.InteropServices.Marshal.ReleaseComObject(pfield);
看到吧,千万不要以为你释放了等级最高的 IWorkspaceFactory, IWorkspace就算完事了。没办法,AE有时就这么难以理解的麻烦。
原文连接:
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
(2)(2)(1)(1)(1)(3)(1)(2)(6)(3)(1)(8)(7)(2)(5)(8)(7)(2)(8)(15)(18)(19)(23)(5)(7)(2)(1)(1)(7)(3)
访问:231147次
积分:2751
积分:2751
排名:第9222名
原创:23篇
转载:147篇
评论:36条

我要回帖

更多关于 arcengine开发教程 的文章

 

随机推荐