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;}
- 过滤器是否属于查询图形
1. [C#] public IGeometryGeometry {get; set;} 2. [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 空间关系描述优秀论文