ArcEngine空间操作
接口类:ITopologicalOperator
引用空间:using ESRI.ArcGIS.Geometry;
常见空间方法:UNION、Buffer 、Intersect 、Clip、Difference
1、UNION 合并
示例代码
public IGeometry UnionFeature(IFeatureLayer m_roadLayer,IQueryFilter filter) {
//开启编辑
IWorkspaceEdit workspaceEdit = (IWorkspaceEdit)(m_roadLayer.FeatureClass.FeatureDataset as IDataset).Workspace;
try
{
//过滤要素
IFeatureCursor featureCursor = m_roadLayer.FeatureClass.Search(filter, true);
//开启编辑
workspaceEdit.StartEditing(true);
workspaceEdit.StartEditOperation();
//第一个要素
IFeature firstFeature = featureCursor.NextFeature();
IFeature pFeature;
//合并对象
IGeometry unionGeometry = firstFeature.ShapeCopy;
//下一个要素(从第二个开始)
while ((pFeature = featureCursor.NextFeature()) != null)
{
// top类 合并要素
ITopologicalOperator topological = unionGeometry as ITopologicalOperator;
topological.Simplify();
//合并要素
unionGeometry = (topological).Union(pFeature.ShapeCopy);
}
//保存停止编辑
workspaceEdit.StopEditing(true);
workspaceEdit.StopEditOperation();
return unionGeometry;
}
catch
{
return null;
}
finally
{
workspaceEdit.StopEditing(true);
workspaceEdit.StopEditOperation();
}
}
注:多要素使用 void ConstructUnion(IEnumGeometry geometries);
2、Buffer 缓冲
同上:IGeometry Buffer(double distance);
3、Intersect 相交
同上:IGeometry Intersect(IGeometry other, esriGeometryDimension resultDimension);
4、Clip 裁剪
同上:void Clip(IEnvelope clipperEnvelope);
5、Difference 差异
同上:IGeometry Difference(IGeometry other);
声明
1)文章来源项目实践,已经过作者测试验证,文章存在任何疑问或错误,请指正,感谢您的阅读!
2)转载请标注来源,谢谢!