ArcEngine 根据要素选择集,创建新图层

转自根据要素选择集,创建新图层

IFeatureLayer featureLayer = new FeatureLayerClass();
featureLayer.FeatureClass = featureClass;
IFeatureSelection featureSelection = featureLayer as IFeatureSelection;
IQueryFilter queryFilter1 = new QueryFilterClass();
queryFilter1.WhereClause = "XZQDM like '" + xz_xzqdm + "%'";
featureSelection.SelectFeatures(queryFilter1, esriSelectionResultEnum.esriSelectionResultNew, false);

ISelectionSet selectionSet = featureSelection.SelectionSet;
IFeatureLayer newFeatureLayer = null;
if (selectionSet.Count > 0)
{
	IFeatureLayerDefinition featureLayerDefinition = featureLayer as IFeatureLayerDefinition;
	newFeatureLayer = featureLayerDefinition.CreateSelectionLayer(featureClass.AliasName, true, null, null);
}

思路:
使用了 IFeatureLayerDefinition 对象的 CreateSelectionLayer 方法
IFeatureLayerDefinition 是一个自定义要素层接口,需要首先将所要自定义的要素图层赋给它
其方法 CreateSelectionLayer() 用来以当前图层的选择集创建一个图层,是直接将数据赋给新图层,因此原图层上出现变化并不会反映到新建的图层上
同时 IFeatureLayerDefinitionDefinitionExpression 属性可以设置一个查询字符串,通过将查询字符串传递给__DefinitionExpression__ 属性可以将满足该字符串条件的要素显示出来。
例如 pFeatureLayerDefinition.DefinitionExpression = "name = ‘a’ " ; 将所有满足name属性值为a的要素显示出来,其余均被遮住。
ArcEngine 根据要素选择集,创建新图层_第1张图片

你可能感兴趣的:(GIS)