AE中有时候要根据指定的条件求要素类中的要素的并集。生成游标,取每条要素,然后求并,最后释放游标的过程很麻烦。
<pre name="code" class="csharp">用IEnumGeometryBind 接口,可以简化工作。
private IGeometry GetFrameGeometry(IFeatureClass frameClass, IQueryFilter filter)
{
<span style="white-space:pre"> </span> // <span style="font-family: Arial, Helvetica, sans-serif;">EnumFeatureGeometryClass </span><span style="font-family: Arial, Helvetica, sans-serif;"> 在ESRI.ArcGIS.Geodatabase</span><span style="font-family: Arial, Helvetica, sans-serif;"> </span>命名空间下
IEnumGeometry enumGeometry = new EnumFeatureGeometryClass();
try
{
filter.SubFields = frameClass.ShapeFieldName;
IEnumGeometryBind bind = enumGeometry as IEnumGeometryBind;
bind.BindGeometrySource(filter, frameClass);
enumGeometry.Reset();
IGeometry firstGeometry = enumGeometry.Next();
ITopologicalOperator topo = firstGeometry as ITopologicalOperator;
topo.ConstructUnion(enumGeometry);
return topo as IGeometry;
}
catch (Exception ex)
{
LogHelper.Error.Append(ex);
return null;
}
finally
{
ComReleaser.ReleaseCOMObject(enumGeometry);
}
}