ArcObject 10.2 获取FeatureClass的Exent

在FeatureClass中对Feature进行编辑,删除,添加要素后,可以用下面代码对要素类的Extent进行更新

((IFeatureClassManage)featureClass).UpdateExtent();

获取图层/要素类的Exent的代码为:

var featureClass = featureLayer.FeatureClass;
var geoDataset = (IGeoDataset)featureClass;
var extent = geoDataset.Extent;

也可以根据图层中的要素计算得到Extent, 代码为:
(数据量少时,可以使用下面代码)

var featureClass = routeLayer.FeatureClass;
var feature0 = featureClass.GetFeature(0);
var totalExtent = feature0.ShapeCopy.Envelope;
           
int featureCount = featureClass.FeatureCount(null);
for (int i = 1; i < featureCount; i++)
{
    var feature = featureClass.GetFeature(i);
    totalExtent.Union(feature.ShapeCopy.Envelope);
}

(数据量大时,推荐使用下面代码)

var featureClass = routeLayer.FeatureClass;
var featureCursor = featureClass.Search(null, true);
var feature0 = featureCursor.NextFeature();
var totalExtent = feature0.ShapeCopy.Envelope;
               
var feature = featureCursor.NextFeature();
while (feature != null)
{
     totalExtent.Union(feature.ShapeCopy.Envelope);
     featureCursor.NextFeature();
}
Marshal.ReleaseComObject(featureCursor);
posted @ 2020-04-08 16:14  lqqgis  阅读(358)  评论(0编辑  收藏  举报