目錄
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 概述表
AddField | Appends a single field name to the list of sub-fields. |
FilterOwnsGeometry | Indicates whether the filter owns the query geometry. |
Geometry | The query geometry used to filter results. |
GeometryEx | The query geometry used to filter results. |
GeometryField | The name of the Geometry field to which the filter applies. |
OutputSpatialReference | The spatial reference in which to output geometry for a given field. |
SearchOrder | The 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.】 |
SpatialRel | The spatial relationship checked by the filter. |
SpatialRelDescription | The 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. |
SubFields | The comma delimited list of field names for the filter. |
WhereClause | The 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 Geometry | Requested Geometry | 關系描述 | 備注 | |
---|---|---|---|---|
1 | interior | interior | 内-内 | 在查詢圖形和對比圖形的内部 |
2 | interior | boundary | 内-邊 | 在查詢圖形的内部,但在對比圖型的邊界上 |
3 | interior | exterior | 内-外 | 在查詢圖形的内部,但在對比圖形的外部 |
4 | boundary | interior | 邊-内 | 在查詢圖形的外部,但在對比圖形的内部 |
5 | boundary | boundary | 邊-邊 | 在查詢圖形的邊界上,但在對比圖形的邊界上 |
6 | boundary | exterior | 邊-外 | 在查詢圖形的邊界上,但在對比圖形的外部 |
7 | exterior | interior | 外-内 | 在查詢圖形的外部,但在對比圖形的内部 |
8 | exterior | boundary | 外-邊 | 在查詢圖形的外部,但在對比圖形的邊界上 |
9 | exterior | exterior | 外-外 | 在查詢圖形的外部,但在對比圖形的外部 |
說明: 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 ]
Relation | Query Geometry | Requested Geometry | String |
Contains | Line | Line | TT*FFT*** |
Contains | Point | Line | TT*FFT*** |
Contains | Point | Point | T******** |
Contains | Line | Poly | TT*FFT*** |
Contains | Poly | Poly | TT*FFT*** |
Crosses | Line | Line | TF*FF**** |
Crosses | Poly | Line | TT**F**** |
Crosses | Line | Poly | TT**T**** |
Overlaps | Line | Line | TT*T***** |
Overlaps | Point | Point | T******** |
Overlaps | Poly | Poly | TT*T***** |
Touch | Line | Line | FF*FT**** |
Touch | Poly | Line | FF*FT**** |
Touch | Line | Poly | FF*FT**** |
Touch | Poly | Poly | FF*FT**** |
Within | Line | Line | TF**F**** |
Within | Point | Line | T******** |
Within | Point | Point | T******** |
Within | Line | Poly | TF**F**** |
Within | Poly | Poly | TF**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);
- 為給定字段輸出幾何圖形的空間參考。