文章目录
ILayer
ILayer is a generic interface for all layer objects. This interface has a method to draw the layer and provides access to generic layer properties.
This interface has a method to draw the layer and properties to define the minimum and maximum display scales, the spatial reference, the name, layer visibility, whether or not the layer is cached, and whether or not the layer shows map tips.
There are also properties that indicate whether the layer is valid, its supported draw phases, area of interest, and the map tip text for a given coordinate.
IFeatureLayer
Provides access to the properties and methods of a layer based on vector geographic data, which is typically a geodatabase, shapefile, or coverage feature class.
This interface has properties that specify the feature class of the layer, the data source type, the primary display field, whether or not layer symbols scale based on the map’s reference scale, and whether or not the layer is selectable.
IFeatureLayer.DisPlayFiled
The name of the layer’s primary display field.
Usually this field name contains the string “name”, or is the first string field found in the layer’s attributes. This field is used to show map tips for the layer. The value of this property must match the name of one of the fields in the layer’s FeatureClass.
IFeatureClass
Provides access to members that control the behavior and properties of a feature class.
The IFeatureClass interface is the main interface for getting and setting properties of a feature class. For example, use the IFeatureClass interface to get the type of feature class, get a count of features that satisfy some query, or create a new feature in the feature class. The IFeatureClass interface inherits from the IObjectClass interface.
IFeatureLayer和IFeatureClass的联系
1、FeaturLayer是加载在地图文档中的数据层,只是要素类的表现形式;FeatureClass是一组空间实体的集合,在数据表中存储了统一的属性和行为,每一个FeatureClass都有一个Geometry类型,如shp文件;
2、IFeatureLayer继承自ILayer,IFeatureClass继承自IClass;
3、FeatureLayer可以创建自己的对象,而FeatureClass不行:
IFeatureClass=IFeatureLayer.FeatureClass 或者
IFeatureClass=IFeatureWorkspace.openFeatureClass(“xx”)
- IMap
这相对来说比较好理解,Map就是许多图层的集合,就像 ArcMap 中的 MXD文档一样,可以包括许多图层 Layer. - ILayer
Layer 是图层对象,是数据的外壳,必须建立在数据的基础上才有意义。在 ArcMap 中,它可以表示任何图层,例如要素图层( IFeatureLayer ),栅格图层( IRasterLayer ),图形图层集合( ICompositeGraphicsLayer) - IFeatureLayer
继承自ILayer,提供了访问基于矢量数据图层的属性和方法,图层的数据可以是Geodatabase、Shapefile或Coverage数据。如果使用FeatureLayer组件类,还可以通过IGeoFeatureLayer接口获得更多的属性和方法。提供了控制要素图层的属性和方法,例如标记属性( AnnotationProperties )、注记显示设置( DisplayAnnotation ) - IFeatureClass
获取和设置要素类属性的主要接口。如获取要素类的类型,得到满足某个查询条件的要素个数,或在要素类中创建一个新的功能。
关系
其中IMap是由多个ILayer构成的,而IFeatureLayer是ILayer的一个子类,IFeatureClass是IFeatureLayer的一个属性。
这里再增加一个 IFeature 接口,IFeature是 FeatureClass 的一部分,他们之间的关系就相当于 IRow 和 ITable之间的关系一样
示例代码
private void initial_combobox1()
{
IFeatureLayer pFeatureLayer; // 获取要素图层--eg: 城市图层
IFeatureClass pFeatureClass; // 获取要素图层的数据形式--eg: 城市图层(可以查询属性表)
IFeatureCursor pFeatureCursor; // 要素的浮标-遍历要素类--eg:城市图层里的某个城市
IFeature pFeature; // 具体要素的载体-字段--eg:某个城市的某个字段,如城市的人口
pFeatureLayer = (IFeatureLayer)axMapControl1.get_Layer(0);
pFeatureClass = pFeatureLayer.FeatureClass;
pFeatureCursor = pFeatureClass.Search(null, false); //随机得到一个要素浮标
pFeature = pFeatureCursor.NextFeature();
for (int i = 0; i < pFeature.Fields.FieldCount; i++)
{
if (pFeature.Fields.Field[i] == null)
continue;
comboBox1.Items.Add(pFeature.Fields.Field[i].Name);
}
}
IFeatureLayerDefinition
Provides access to members that define a subset of the features from the underlying feature class.
IFeatureLayerDefinition.CreateSelectionLayer
CreateSelectionLayer creates a new FeatureLayer from an existing FeatureLayer.
LayerName defines the new layer’s name.
Set useCurrentSelection = TRUE here if you want to use the currently selected features on the existing layer.
joinTableNamesmay contain the name of related table(s) separated by commas. The existing join(s) will then be passed on to the new layer.
The DefinitionExpression parameter can be used to set a definition expression on the newly created layer but currently this will be defined at the feature class rather than at the layer level and will not show up in the UI. If you want to set a definition query on the newly created layer, it is best to use IFeatureLayerDefinition again to set the definition query after the layer has been created.
private void btn_NewLayer_Click(object sender, EventArgs e)
{
IFeatureLayer pFeatureLayer = (IFeatureLayer)axMapControl1.get_Layer(0);
IFeatureLayerDefinition pFLDefinition = pFeatureLayer as IFeatureLayerDefinition;
IFeatureLayer nFeatureLayer = pFLDefinition.CreateSelectionLayer("newLayer", true, null, null);
string name = nFeatureLayer.Name;
axMapControl1.AddLayer(nFeatureLayer);
}
IIdentify
The IIdentifyinterface can be used to identify features at the specified location. When this interface is on a map layer, the Identifymethod returns an array of FeatureIdentifyObject
objects.
On a FeatureIdentifyObject
, you can do a QI to the IIdentifyObj
interface to get more information about the identified feature. The IIdentifyObj
interface returns the window handle, layer, and name of the feature; it has methods to flash the feature in the display and to display a context menu at the Identify location.
图与要素的相互转换
图到要素:IFeatureClass的Search方法,FeatureSelection的SelectFeatures方法,Ildentity的Identity方法,ILayerFields接口
要素到图:IFeatureLayerDefinition的CreateSelectionLayer
参考博客
FeatureLayer和FeatureClass
arcEngine开发之IMap、ILayer、IFeatureLayer和IFeatureClass关系