基于C#的ArcEngine二次开发38: 几何关系描述接口- ISpatialFilter 最全解析

目录

1. ISpatialFilter接口简介

2 属性与方法

2.1 概述表

2.2 ISpatialFilter.SpatialRelDescription

2.3 ISpatialFilter.SpatialRel

2.4 IQueryFilter.WhereClause Property

2.5 其他属性

3 空间关系描述优秀论文


1. ISpatialFilter接口简介

ISpatialFilter是一个包含空间和属性限制的QueryFilter,可以使用该过滤器进行要素的空间属性筛选:

  • 使用spatial filter执行空间查询,常作为IFeatureClass::Search、IFeatureClass::Select或feature layers上相似方法的参数
  • 需要Geometry,GeometryField和SpatialRel属性。
    • Geometry是源图形,根据与其的关系执行空间选择。
    • GeometryField是图形字段名,将其中的图形与源图形比较。
    • SpatialRel属性将一个esriSpatialRelEnum传入来指定空间关系。
  • 使用esriSearchOrder指定SearchOrder。当指定属性查询后,该属性将指定先执行那一部分查询,该属性仅对SDE数据源有效。
  • SaptialRelDescription是个字符串,可代替SpatialRel属性定义额外的空间关系。这种情况下,SpatialRel参数必须设置成esriSpatialRelRelation。
  • esriGeometry提供其他方式执行空间查询。

2 属性与方法

2.1 概述表

AddFieldAppends a single field name to the list of sub-fields.
FilterOwnsGeometryIndicates whether the filter owns the query geometry.
GeometryThe query geometry used to filter results.
GeometryExThe query geometry used to filter results.
GeometryFieldThe name of the Geometry field to which the filter applies.
OutputSpatialReferenceThe spatial reference in which to output geometry for a given field.
SearchOrderThe search order used by the filter.【This property only affects ArcSDE Geodatabase data. It has no effect on Personal or File Geodatabase, Coverage or Shapefile data.
SpatialRelThe spatial relationship checked by the filter.
SpatialRelDescriptionThe array elements which describe the spatial relation between the query geometry and the requested geometries. There are 9 chars in this string which can be either 'F', 'T' or '*'; e.g., TT*FFT***' represents CONTAIN.
SubFieldsThe comma delimited list of field names for the filter.
WhereClauseThe where clause for the filter.

2.2 ISpatialFilter.SpatialRelDescription

public stringSpatialRelDescription {get; set;}

用来表述查询要素和对比要素的空间关系的数组,使用9个字符进行空间关系描述,使用该参数要求SpatialRel属性取枚举值esriSpatialRelRelation.它允许比较两个几何图形之间存在的任何空间关系, 空间关系由查询几何图形的边界、内部和外部与对比图形的交点确定。A spatial relationship is defined by the intersections between the boundary, interior, and exterior of the query geometry and the requested geometry.所有被esriSpatialRelEnum定义的关系,都可以由该属性计算得到。

描述空间关系的三个基本概念:

  • 内部:形状的内部定义为整个形状减去其边界,也即其边界内部的所有部分。[Interior:The interior of a shape is defined as the entire shape minus its boundary. All shapes have interior.]
  • 边界:线和面的边界,点没有边界的概念,线的边界包含其所有终点,面的边界包含其多边形的轮廓线。[Boundary: Linear and area shapes have boundaries, but point shapes do not. The boundary of linear shapes consists of the end points of all linear parts. The boundary of area shapes consists of the linear boundary of the polygon shell(s)]
  • 外部:面的形状之外,所有形状都有外部。[Exterior:The area outside a shape. All shapes have an exterior.]

注意两个图形的外部是相交的

Each element for the first shape, the query geometry, may be tested against each element of the second shape, the requested geometry, giving nine possible spatial intersections as listed in the table below:

 Query GeometryRequested Geometry关系描述备注
1interiorinterior内-内在查询图形和对比图形的内部
2interiorboundary内-边在查询图形的内部,但在对比图型的边界上
3interiorexterior内-外在查询图形的内部,但在对比图形的外部
4boundaryinterior边-内在查询图形的外部,但在对比图形的内部
5boundaryboundary边-边在查询图形的边界上,但在对比图形的边界上
6boundaryexterior边-外在查询图形的边界上,但在对比图形的外部
7exteriorinterior外-内在查询图形的外部,但在对比图形的内部
8exteriorboundary外-边在查询图形的外部,但在对比图形的边界上
9exteriorexterior外-外在查询图形的外部,但在对比图形的外部

说明: in 'FFFTTT***', relationships 1-3 must be false, relationships 4-6 must be true, and relationships 7-9 are not tested.

组合示例:

  • Shares a boundary: '****T***'
  • Shares a boundary and interiors intersect: 'T***T****'
  • Shares a boundary and interiors do not intersect: 'F***T****'
  • Does not touch the boundary and interiors intersect: 'T***F****'

esriSpatialRelEnum含义对应的字符串

[Approximate  esriSpatialRelEnum SpatialRelDescription Strings ]

RelationQuery GeometryRequested GeometryString
ContainsLineLineTT*FFT***
ContainsPointLineTT*FFT***
ContainsPointPointT********
ContainsLinePolyTT*FFT***
ContainsPolyPolyTT*FFT***
CrossesLineLineTF*FF****
CrossesPolyLineTT**F****
CrossesLinePolyTT**T****
OverlapsLineLineTT*T*****
OverlapsPointPointT********
OverlapsPolyPolyTT*T*****
TouchLineLineFF*FT****
TouchPolyLineFF*FT****
TouchLinePolyFF*FT****
TouchPolyPolyFF*FT****
WithinLineLineTF**F****
WithinPointLineT********
WithinPointPointT********
WithinLinePolyTF**F****
WithinPolyPolyTF**F****

2.3 ISpatialFilter.SpatialRel

[C#]public esriSpatialRelEnumSpatialRel {get; set;}

说明:

  • 大多数空间关系是由边界、内部和外部的交集定义的;
  • 所有形状都有内部,直线和多边形有一个边界;
  • 大多数空间关系在检查两个特征之间的空间关系时使用容差。在大多数情况下,此公差是搜索要素的XY公差。公差范围内的所有几何图形都视为相交。在重叠情况下,公差设置最小重叠。重叠小于公差的几何图形将不会被视为重叠。

 Most spatial relationships are defined by the intersection of boundaries, interior and exterior. All shapes have an interior. Lines and polygons have a boundary. Most spatial relations use a tolerance when examining the spatial relationship between two features. In most cases this tolerance is the XY tolerance of the search feature. All geometries within the tolerance are seen as intersecting. In the overlaps case the tolerance sets the minimum overlap. Geometries that overlap less than the tolerance will not be seen as overlapping.

 

  •  用到XY容差的关系:esriSpatialRelIntersects,esriSpatialRelEnvelopeIntersects,esriSpatialRelTouches, esriSpatialRelOverlaps, esriSpatialRelCrosses, esriSpatialRelWithin,esriSpatialRelContains
  • esriSpatialRelRelation使用XY分辨率,通常比XY的容差小十倍
  • esriSpatialRelIndexIntersects不使用容差

2.4 IQueryFilter.WhereClause Property

该属性允许指定一个表达式,其实就是一个sql语句,用来返回需要的要素;如你要获取面积大于1500的多边形,则应设置该参数为"AREA" > 1500;查询语法因使用的数据库而异,应用程序可以使用工作区上的ISQLSyntax接口来确定有关所用SQL语法的信息,例如限定表和字段名中使用的定界字符以及标识符引号字符。

The syntax of the query differs depending on the data source you are using, as it is in the native format of the database or data source.  An application can use the ISQLSyntax interface on a Workspace to determine information about the SQL syntax used, such as the delimiting character used in qualifying table and field names and the identifier quote character.

关于字段名:

  • 如果查询数据是file geodatabase, shapefile, dBase table, coverage, INFO table,字段名应该使用双引号括起来,  "AREA"
  • 如果查询的是个人数据库,应该使用中括号【square brackets】括起来 [AREA]
  • 如果数据是 ArcSDE geodatabase、ArcIMS image service或feature service,不用括起来,  AREA
  • 如果是.xls或.txt,字段使用单引号【single quotes】定义 'AREA' unless you are working in the Select By Attributes dialog launched from the table window, in which case square brackets [AREA] are used.

关于字符串:

  • 字符串要使用单引号括起来:"STATE_NAME" = 'California'
  • 使用转换函数处理数据库对字段值大小写敏感的情形:Personal geodatabases stored in Access are case insensitive to field values, whereas ArcSDE, File and shapefiles are case sensitive.  To make a case insensitive search in other data formats, you can use a SQL function to convert all values to the same case. For file-based data sources, use either the UPPER or LOWER function.
    • For example, given a field value of "Florida", a WhereClause of "State_name = 'florida'" will return one USA state when run against a data in a personal geodatabase, but none with and shapefiles and ArcSDE.  A WhereClause of "State_name = 'Florida'" will return one feature in all cases.
    • For example, the following expression will select customers whose last name is stored as either Jones or JONES: UPPER("LAST_NAME") = 'JONES'
    • Other data sources have similar functions. Personal geodatabases, for example, have functions named UCASE and LCASE that perform the same function.
  • 使用LIKE运算符而非=运算符构架一个局部字符串搜索Use the LIKE operator (instead of the = operator) to build a partial string search.
    • For example, this expression would select Mississippi and Missouri among the USA state names:"STATE_NAME" LIKE 'Miss%'
    • 如果对带=的字符串使用通配符,该字符将被视为字符串的一部分,而非通配符。If you use a wildcard character in a string with the = operator, the character is treated as part of the string, not as a wildcard.

通配符的使用:

  • 代表一个或多个字符的记号
  • %表示该位置有任何位数的字符,可以是一个、100个或者没有;当你想搜索表示一个位置的通配符,_是备选方案。For any file-based data, '%' means that anything is acceptable in its place: one character, a hundred characters, or no character. Alternatively, if you want to search with a wildcard that represents one character, use '_'.
    • For example, this expression would select any name starting with the letters Cath, such as Cathy, Catherine, and Catherine Smith: "NAME" LIKE 'Cath%';使用%代替所有后边的字符
    • But this expression would find Catherine Smith and Katherine Smith:"OWNER_NAME" LIKE '_atherine smith';代替开头的一个字符
  • 使用?表示任意数字字符,使用*表示单个字符:The wildcards you use to query personal geodatabases are '*' for any number of characters and '?' for one character.
  • Use ISQLSyntax::GetSpecialCharacter to return the wildcard specific for the data source being queried.【返回指定数据源特定的通配符】
  • 对于链接表,使用与查询链接侧的通配符;查询仅面向目标侧,则使用目标侧通配符;查询仅面向链接表,则使用链接侧通配符;如果涉及两侧,则使用 % 和 \u 通配符。
    • For example, if you join a dbf file (the join table) to a personal geodatabase feature class (the target table):

      1) Use * for queries that only involve personal geodatabase fields.

      2) Use % for queries that only involve dbf columns.

      3) Use % for queries involving columns from both sides of the table.

  • 空值:Null values are supported in fields for geodatabases and for date fields in shapefiles/dBASE tables and coverages/INFO tables.
  • 不等于:The Distinct keyword is not supported by file geodatabases.  The recommended workaround is to use the IDataStatistics::UniqueValues method to return the distinct values for a field.
  • 比较数字:You can query numbers using the equal (=), not equal (<>), greater than (>), less than (<), greater than or equal (>=), and less than or equal (<=) operators.例如:"POPULATION96" >= 5000

  • 查询日期:The syntax required for querying dates depends on the data type. ArcMap will automatically write the proper syntax for you when you double-click a date value in the Unique Values list. See the SQL reference mentioned above for more about querying dates.

关于SQL的参考网址:http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=SQL_reference

2.5 其他属性

[C#]public esriSearchOrderSearchOrder {get; set;}

请注意esriSearchOrderSpatial是默认属性,  以下esriSearchOrder枚举值用于设置搜索顺序:
esriSearchOrderAttribute:Sets the search order to attribute first.
esriSearchOrderSpatial:Sets the search order to spatial first.

[C#] public boolFilterOwnsGeometry {get;}
  • 过滤器是否属于查询图形
[C#] public IGeometryGeometry {get; set;}
[C#] public void set_GeometryEx ( IGeometryGeometry, boolA_2);
  • 高级图形或图形包,如多边形、多段线、点、多点可以使用;低级图形,如路径、环、弧、曲线、线不能使用;
  • IRelationalOperator接口实现的几何图形都支持,没有被其实现的都不支持。
  • The boolean parameter represents the FilterOwnsGeometry property.

Only high-level geometries, envelopes and geometry bags can be used. High-level geometries are polygons, polylines, points, and multipoints. Low-level geometries including paths, rings, arcs and curves, and lines can not be used. To test whether a geometry is applicable, see if it implements the IRelationalOperator interface; if it does, it can be used.

[C#] public stringGeometryField {get; set;}
  • 将用于滤波的几何图像字段名
[C#]public ISpatialReference get_OutputSpatialReference (stringFieldName);
[C#]public void set_OutputSpatialReference (stringFieldName, ISpatialReferenceOutputSpatialReference);
  • 为给定字段输出几何图形的空间参考。

3 空间关系描述优秀论文

 

 

 

 

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小薛引路

喜欢的读者,可以打赏鼓励一下

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值