AE二次开发中,过滤后的图层,实现缩放至图层效果
//featureClass是自己获取的featureClass,也可是sde中获取的。 public void FilterAndZoomToLayer(IFeatureClass featureClass) { IFeatureLayer featureLayer = new FeatureLayerClass(); featureLayer.FeatureClass = featureClass; IFeatureLayerDefinition featureLayerDefinition = featureLayer as IFeatureLayerDefinition; //获取符合条件的图层要素 featureLayerDefinition.DefinitionExpression = "XZQDM like '" + xz_xzqdm + "%'"; IFeatureLayer newFeatureLayer = featureLayerDefinition.CreateSelectionLayer(featureClass.AliasName, false, null, featureLayerDefinition.DefinitionExpression); ILayer newLayer = newFeatureLayer as ILayer; mcView.AddLayer(newLayer); //实现过滤后的图层,缩放到图层 IEnvelope envelope = new EnvelopeClass(); ILayer layer = mcView.get_Layer(0); IFeatureLayer featureLayer = layer as IFeatureLayer; IQueryFilter queryFilter = new QueryFilterClass(); queryFilter.WhereClause = ""; IFeatureCursor featureCursor = featureLayer.FeatureClass.Search(queryFilter, true); IFeature feature = featureCursor.NextFeature(); while (feature != null) { IGeometry geometry = feature.Shape; IEnvelope featureExtent = geometry.Envelope; envelope.Union(featureExtent); System.Runtime.InteropServices.Marshal.ReleaseComObject(feature); feature = featureCursor.NextFeature(); } mcView.ActiveView.FullExtent = envelope; } //上面方法对于数据量较少的矢量是可以接受的,但对于一个县或一个市的数据,则加载比较慢。 //经过研究和尝试,整理了一种新的缩放至图层的方式,如下 //实现过滤后的图层,缩放到图层 IEnvelope pEnvelope = new EnvelopeClass(); //关键代码,替换了要素遍历,提高效率 IEnumGeometryBind enumGeometryBind = new EnumFeatureGeometryClass(); enumGeometryBind.BindGeometrySource(null, pFeatureClassDLTB); IEnumGeometry enumGeometry = (IEnumGeometry)enumGeometryBind; IGeometryFactory geoFactory = new GeometryEnvironment() as IGeometryFactory; IGeometry geo = geoFactory.CreateGeometryFromEnumerator(enumGeometry); pEnvelope.Union(geo.Envelope); System.Runtime.InteropServices.Marshal.ReleaseComObject(geo); System.Runtime.InteropServices.Marshal.ReleaseComObject(geoFactory); System.Runtime.InteropServices.Marshal.ReleaseComObject(enumGeometry); mcView.ActiveView.FullExtent = pEnvelope; 转自:http://blog.csdn.net/u011116642/article/details/12562929
来自:https://www.cnblogs.com/ParanoiaApe/p/8065127.html