Arcengine拓扑分析
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;
namespace LGGIS.GIS.TopologyAnalysis
{
public class TopologyAnalysisClass
{
public delegate void Check_AreaRingOrientationDelegate(IFeatureClass pClass);
public delegate void Check_FeatureNonShapeDelegate(IFeatureClass pClass);
public void Check_AreaRingOrientation(IFeatureClass pClass)
{
try
{
IWorkspaceEdit pWSEdit = ((IDataset)pClass).Workspace as IWorkspaceEdit;
IFeatureCursor pCursor = null;
IFeature pFeature = null;
ESRI.ArcGIS.Geometry.esriNonSimpleReasonEnum reason;
ITopologicalOperator4 pTopo = null;
bool bl = false;
if (pWSEdit.IsBeingEdited() == false)
{
pWSEdit.StartEditing(false);
pWSEdit.StartEditOperation();
pCursor = pClass.Search(null, false);
pFeature = pCursor.NextFeature();
while (pFeature != null)
{
if (pFeature.Shape != null)
{
pTopo = pFeature.Shape as ITopologicalOperator4;
pTopo.IsKnownSimple_2 = false;
bl = pTopo.get_IsSimpleEx(out reason);
if (bl == false && reason == esriNonSimpleReasonEnum.esriNonSimpleRingOrientation)
{
pTopo.Simplify();
pFeature.Shape = pTopo as IGeometry;
pFeature.Store();
}
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeature);
pFeature = pCursor.NextFeature();
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(pCursor);
GC.Collect();
pWSEdit.StopEditOperation();
pWSEdit.StopEditing(true);
}
else
{
pWSEdit.StartEditOperation();
pCursor = pClass.Search(null, false);
pFeature = pCursor.NextFeature();
while (pFeature != null)
{
if (pFeature.Shape != null)
{
pTopo = pFeature.Shape as ITopologicalOperator4;
pTopo.IsKnownSimple_2 = false;
bl = pTopo.get_IsSimpleEx(out reason);
if (bl == false && reason == esriNonSimpleReasonEnum.esriNonSimpleRingOrientation)
{
pTopo.Simplify();
pFeature.Shape = pTopo as IGeometry;
pFeature.Store();
}
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeature);
pFeature = pCursor.NextFeature();
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(pCursor);
GC.Collect();
pWSEdit.StopEditOperation();
}
MessageBox.Show("处理完成!");
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public void Check_FeatureNonShape(IFeatureClass pClass)
{
try
{
IWorkspaceEdit pWSEdit = ((IDataset)pClass).Workspace as IWorkspaceEdit;
IFeatureCursor pCursor = null;
IFeature pFeature = null;
pCursor = pClass.Search(null, false);
if (pWSEdit.IsBeingEdited() == false)
{
pWSEdit.StartEditing(false);
pWSEdit.StartEditOperation();
pFeature = pCursor.NextFeature();
while (pFeature != null)
{
if (pFeature.Shape == null)
{
pFeature.Delete();
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeature);
pFeature = pCursor.NextFeature();
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(pCursor);
GC.Collect();
pWSEdit.StopEditOperation();
pWSEdit.StopEditing(true);
}
else
{
pWSEdit.StartEditOperation();
pFeature = pCursor.NextFeature();
while (pFeature != null)
{
if (pFeature.Shape == null)
{
pFeature.Delete();
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeature);
pFeature = pCursor.NextFeature();
}
System.Runtime.InteropServices.Marshal.ReleaseComObject(pCursor);
GC.Collect();
pWSEdit.StopEditOperation();
}
MessageBox.Show("空值要素删除完成!");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public void Check_Inters
ectionsSelf(IFeatureClass pClass)
{
try
{
IFeatureCursor pCursor = null;
IFeature pFeature = null;
IGeometry pGeometry = null;
IGeometry pUnionGeo = null;
ITopologicalOperator4 pTopo = null;
pCursor = pClass.Search(null, false);
pFeature = pCursor.NextFeature();
pUnionGeo = pFeature.ShapeCopy;
pFeature = pCursor.NextFeature();
while (pFeature != null)
{
pTopo = pUnionGeo as ITopologicalOperator4;
pGeometry = pFeature.ShapeCopy;
pTopo.Simplify();
pUnionGeo = pTopo.Union(pGeometry);
pFeature = pCursor.NextFeature();
}
}
catch
{
}
}
}
}