|
20铜板
[hr][hr]
未处理 System.Runtime.InteropServices.COMException
HelpLink=esri_csGeoDatabase.hlp
Message=不支持此几何类型。
[hr] Source=ESRI GeoDatabase
ErrorCode=-2147219199
StackTrace:
在 ESRI.ArcGIS.Geodatabase.IFeatureBuffer.set_Shape(IGeometry Shape)
在 WindowsFormsApplication10.Form1.addFeature(String layerName, IPoint point) 位置 C:\Users\lenovo\Desktop\Geometry实验\WindowsFormsApplication10\Form1.cs:行号 134
在 WindowsFormsApplication10.Form1.button1_Click(Object sender, EventArgs e) 位置 C:\Users\lenovo\Desktop\Geometry实验\WindowsFormsApplication10\Form1.cs:行号 156
在 System.Windows.Forms.Control.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnClick(EventArgs e)
在 System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
在 System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
在 System.Windows.Forms.Control.WndProc(Message& m)
在 System.Windows.Forms.ButtonBase.WndProc(Message& m)
在 System.Windows.Forms.Button.WndProc(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
在 System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
在 System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
在 System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
在 System.Windows.Forms.Application.Run(Form mainForm)
在 WindowsFormsApplication10.Program.Main() 位置 C:\Users\lenovo\Desktop\Geometry实验\WindowsFormsApplication10\Program.cs:行号 24
在 System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
在 System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
在 Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
在 System.Threading.ThreadHelper.ThreadStart_Context(Object state)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean ignoreSyncCtx)
在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
在 System.Threading.ThreadHelper.ThreadStart()
InnerException:
求各路大神解答。。。。。。。。。。。。。。。。
源代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.SystemUI;
using AxESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.esriSystem;
namespace WindowsFormsApplication10
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//打开地图文档
private void 打开文档_Click(object sender, EventArgs e)
{
System.Windows.Forms.OpenFileDialog openFileDialog;
openFileDialog = new OpenFileDialog();
openFileDialog.Title = "打开地图文档";
openFileDialog.Filter = "map documents(*.mxd)|*.mxd";
openFileDialog.ShowDialog();
string filepath = openFileDialog.FileName;
if (axMapControl1.CheckMxFile(filepath))
{
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerHourglass;
axMapControl1.LoadMxFile(filepath, 0, Type.Missing);
axMapControl1.MousePointer = esriControlsMousePointer.esriPointerDefault;
}
else
{
MessageBox.Show(filepath + "不是有效路径");
}
}
//获取线实体
private IFeature getPolylineFeature(string layName)
{
int i = 0;
ILayer layer = null;
for (i = 0; i < axMapControl1.LayerCount; i++)
{
layer = axMapControl1.Map.get_Layer(i);
if (layer.Name.ToLower() == layName)
{
break;
}
}
IFeatureLayer featureLayer = layer as IFeatureLayer;
IFeatureClass featureClass = featureLayer.FeatureClass;
IQueryFilter queryFilter = new QueryFilterClass();
queryFilter.WhereClause = "";
IFeatureCursor featureCursor = featureClass.Search(queryFilter, true);
IFeature feature = featureCursor.NextFeature();
if (feature != null)
{
return feature;
}
return null;
}
//获取点实体
private System.Collections.ArrayList getPointFeature(string layerName)
{
int i = 0;
ILayer layer = null;
for (i = 0; i < axMapControl1.LayerCount; i++)
{
layer = axMapControl1.get_Layer(i);
if (layer.Name.ToLower() == layerName)
{
break;
}
}
IFeatureLayer featureLayer = layer as IFeatureLayer;
IFeatureClass featureClass = featureLayer.FeatureClass;
IQueryFilter queryFilter = new QueryFilterClass();
queryFilter.WhereClause = "";
IFeatureCursor featureCursor = featureClass.Search(queryFilter, true);
IFeature feature = featureCursor.NextFeature();
System.Collections.ArrayList features = new System.Collections.ArrayList();
while (feature != null)
{
features.Add(feature as object);
feature = featureCursor.NextFeature();
}
return features;
}
//添加点实体
private void addFeature(string layerName, IPoint point)
{
int i = 0;
ILayer layer=null;
for (i = 0; i < axMapControl1.LayerCount; i++)
{
layer = axMapControl1.Map.get_Layer(i);
if (layer.Name.ToLower() == layerName)
{
break;
}
}
IFeatureLayer featureLayer = layer as IFeatureLayer;
IFeatureClass featureClass = featureLayer.FeatureClass;
IDataset dataset = (IDataset)featureClass;
IWorkspace workspace = dataset.Workspace;
IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)workspace;
workspaceEdit.StartEditing(true);
workspaceEdit.StartEditOperation();
IFeatureBuffer featureBuffer = featureClass.CreateFeatureBuffer();
IFeatureCursor featureCursor = featureClass.Insert(true);
featureBuffer.Shape = point;
object featureOID = featureCursor.InsertFeature(featureBuffer);
// object featureOID = featureCursor.UpdateFeature(point);
featureCursor.Flush();
workspaceEdit.StopEditOperation();
workspaceEdit.StopEditing(true);
System.Runtime.InteropServices.Marshal.ReleaseComObject(featureCursor);
}
//沿线创建法
private void button1_Click(object sender, EventArgs e)
{
IFeature polylineFeature;
polylineFeature = getPolylineFeature("polyline");
if (polylineFeature != null)
{
ICurve curve = polylineFeature.Shape as ICurve;
IConstructPoint constructPoint = new PointClass();
constructPoint.ConstructAlong(curve,esriSegmentExtension.esriNoExtension,10,true);
IPoint point1 = constructPoint as IPoint;
constructPoint = new PointClass();
constructPoint.ConstructAlong(curve, esriSegmentExtension.esriNoExtension, 20, true);
IPoint point2 = constructPoint as IPoint;
addFeature("point", point1);
addFeature("point", point2);
}
axMapControl1.Refresh();
}
}
}
[hr]
|
-
|