//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;
}