Sie sind auf Seite 1von 10

Data selection and Queries in ArcGIS

BASICS
Whether you are selecting or querying data there are a minimum of 3 elements you will need; a field, an, operator
and a value

Field Operator Value

"AREA" > 1500


"TYPE" = WATER
Data Query Builder window
Building a query
This dialog lets you select features in a layer or records in a table by building a query. To create an expression,
double-click the field you want to use, click an operator, then double-click the value. You can also type directly into
the query.
For example, this query will select all the houses of more than 1,500 square feet in a coverage:
"AREA" > 1500

When you use this dialog, you are actually creating a SQL query. The syntax of the query differs depending on the
data source you are querying. The expression is sent to the data source and interpreted there rather than being
parsed in the dialog, so expressions are in the native format for the database at which they are aimed.

Values from data

User defined value


OPERATORS

The following is the full list of query operators supported by file geodatabases, shapefiles,
coverages, and other file-based data sources. They are also supported by personal and ArcSDE
geodatabases, although these data sources may require different syntax. In addition to the
operators below, personal and ArcSDE geodatabases support additional capabilities. Please see
your DBMS documentation for details.

Arithmetic operators

You use an arithmetic operator to add, subtract, multiply, and divide numeric values.

Operator Description
* Arithmetic operator for multiplication
/ Arithmetic operator for division
+ Arithmetic operator for addition
- Arithmetic operator for subtraction
Arithmetic operators

Comparison operators

You use comparison operators to compare one expression to another.

Operator Description
Less than. It can be used with strings (comparison is based on alphabetical
<
order), numbers, and dates.
Less than or equal to. It can be used with strings (comparison is based on
<=
alphabetical order), numbers, and dates.
Not equal to. It can be used with strings (comparison is based on alphabetical
<>
order), numbers, and dates.
Greater than. It can be used with strings (comparison is based on alphabetical
>
order), numbers, and dates.
Greater than or equal to. It can be used with strings (comparison is based on
alphabetical order), numbers, and dates. For example, this query selects all
>= the cities with names starting with the letters M to Z:

"CITY_NAME" >= 'M'


Selects a record if it has a value greater than or equal to x and less than or
equal to y. When preceded by NOT, it selects a record if it has a value outside
[NOT] BETWEEN
the specified range. For example, this expression selects all records with a
x AND y
value greater than or equal to 1 and less than or equal to 10:
"OBJECTID" BETWEEN 1 AND 10
This is the equivalent of the following expression:
"OBJECTID" >= 1 AND OBJECTID <= 10
However, the expression with BETWEEN provides better performance if you're
querying an indexed field.
Returns TRUE if the subquery returns at least one record; otherwise, it
returns FALSE. For example, this expression returns TRUE if the OBJECTID
field contains a value of 50:
[NOT] EXISTS
EXISTS (SELECT * FROM parcels WHERE "OBJECTID" = 50)
EXISTS is supported in file, personal, and ArcSDE geodatabases only.
Selects a record if it has one of several strings or values in a field. When
preceded by NOT, it selects a record if it doesn't have one of several strings
or values in a field. For example, this expression searches for four different
state names:
[NOT] IN
"STATE_NAME" IN ('Alabama', 'Alaska', 'California', 'Florida')
For file, personal, and ArcSDE geodatabases, this operator can also be applied to a
subquery:
"STATE_NAME" IN (SELECT "STATE_NAME" FROM states WHERE "POP" > 5000000)
Selects a record if it has a null value for the specified field. When NULL is
preceded by NOT, it selects a record if it has any value for the specified field.
IS [NOT] NULL For example, this expression selects all records with a null value for
population:

"POPULATION" IS NULL
Use the LIKE operator (instead of the = operator) with wildcards to build a
partial string search. For example, this expression selects Mississippi and
Missouri among USA state names:

"STATE_NAME" LIKE 'Miss%'


The percent symbol (%) means that anything is acceptable in its place: one
character, a hundred characters, or no character. Alternatively, if you want to search
x [NOT] LIKE y with a wildcard that represents one character, use and underscore (_). For example,
[ESCAPE 'escape- this expression finds Catherine Smith and Katherine Smith:
character'] "OWNER_NAME" LIKE '_atherine Smith'
The percent symbol and underscore wildcards work for any file-based data or
multiuser geodatabase data. LIKE works with character data on both sides of the
expression. If you need to access noncharacter data, use the CAST function. For
example, this query returns numbers that begin with 8 from the integer field
SCORE_INT:
CAST ("SCORE_INT" AS VARCHAR) LIKE '8%'
To include the percent symbol or underscore in your search string, use the ESCAPE
keyword to designate another character as the escape character, which in turn
indicates that a real percent sign or underscore immediately follows. For example,
this expression returns any string containing 10%, such as 10% DISCOUNT or A10%:
"AMOUNT" LIKE '%10$%%' ESCAPE '$'
The wildcards you use to query personal geodatabases are asterisk (*) for any
number of characters and question mark (?) for one character. The pound sign (#) is
also used as a wildcard to match a single digit (numeric value). For example, this
query returns parcel numbers A1, A2, and so on, from a personal geodatabase:
[PARCEL_NUMBER] LIKE 'A#'
Comparison operators

Logical operators
Operator Description
Combines two conditions together and selects a record if both conditions are true.
For example, the following expression selects any house with more than 1,500 square
AND feet and a garage for more than two cars:

"AREA" > 1500 AND "GARAGE" > 2


Combines two conditions together and selects a record if at least one condition is
true. For example, the following expression selects any house with more than 1,500
OR square feet or a garage for more than two cars:

"AREA" > 1500 OR "GARAGE" > 2


Selects a record if it doesn't match the expression. For example, the following
NOT expression selects all states but California:

NOT "STATE_NAME" = 'California'

Field names
The Field list in this dialog automatically lists fields with the appropriate delimiters for the type of data you are
querying:
- If you are querying data in a file geodatabase, shapefile, dBase table, coverage, INFO table, then field names
are enclosed in double quotes:
"AREA"
- If you are querying data in a personal geodatabase then field names are enclosed in square brackets:
[AREA]
- If you are querying data in an ArcSDE geodatabase (i.e., data accessed via a database connection to an ArcSDE
Enterprise geodatabase, or data accessed from a database server running ArcSDE Personal Edition or Workgroup
Edition) or an ArcIMS image service or feature service, then fields are not enclosed:
AREA
- If you are querying data in a worksheet in an Excel file (.xls file) or a text file (.txt file), fields are delimited in
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.

Strings
Strings must always be enclosed within single quotes. For example:
"STATE_NAME" = 'California'
Strings in expressions are case sensitive, except when you are querying personal geodatabase feature classes and
tables. 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, 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.
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%'
You can use greater than (>), less than (<), greater than or equal (>=), less than or equal (<=) and BETWEEN
operators to select string values based on sorting order. For example, this expression will select all the cities in a
coverage with names starting with the letters M to Z:
"CITY_NAME" >= 'M'
The not equal (<>) operator can also be used when querying strings.

Wildcard Characters
A wildcard character is a special symbol that stands for one or more characters.
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.
Wildcard characters appear as buttons on the query dialog. You can click the button to enter the wildcard into the
expression youre building. Only the wildcard characters that are appropriate to the data source of the layer or
table you are querying are displayed.
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.
With a joined table, use wildcards appropriate for the side of the join that you are querying. If the query only
applies to fields in the target table (the left-side table), use the target table wildcards. If the query only applies to
fields in the join table (the right-side table), use the join table wildcards. If the query involves fields from both sides
of the join, use the '%' and '_' wildcards.
For example, if you join a dbf file (the join table) to a personal GDB feature class (the target table):
1) Use * for queries that only involve personal GDB fields.
2) Use % for queries that only involve dbf columns.
3) Use % for queries involving columns from both sides of the table.

The NULL keyword


Null values are supported in fields for geodatabases and for date fields in shapefiles/dBASE tables and
coverages/INFO tables. If you select a field of a type that supports null values, and if that field contains any null
values in the records displayed by the Unique Values list, you'll see a NULL keyword at the top of the Unique
Values list. You can double-click the NULL keyword to add it into your expression, where you can use the IS
operator to query the field to select all its null values:
"POPULATION96" IS NULL
or IS NOT to select all its values that aren't null:
"POPULATION96" IS NOT NULL
The NULL keyword is always preceded by IS or IS NOT.

Querying numbers
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 point is always used as the decimal delimiter regardless of your regional settings. The comma cannot be used
as a decimal or thousands delimiter in a query.

Calculations
Calculations can be included in queries using these arithmetic operators: + - * /
Calculations can be between fields and numbers.
For example:
"AREA" >= "PERIMETER" * 100
Calculations can also be performed between fields.
For example, to find the countries with a population density of less than or equal to 25 people per square mile, you
could use this expression:
"POP1990" / "AREA" <= 25
Note: calculations between fields in a coverage or shapefile (or an INFO table or a dBASE table) are not supported.

Operator precedence
Expressions evaluate according to standard operator precedence rules. For example, the part of an expression
enclosed in parentheses is evaluated before the part that isnt enclosed.
This example:
HOUSEHOLDS > MALES * POP90_SQMI + AREA
evaluates differently from:
HOUSEHOLDS > MALES * (POP90_SQMI + AREA)
You can either click to add parentheses and then enter the expression you want to enclose, or highlight the
existing expression that you want to enclose and then press the Parentheses button to enclose it.

Combining expressions
Expressions can be combined together with the AND and OR operators.
AREA > 1500 AND GARAGE > 3
When you use the OR operator, at least one expression of the two expressions separated by the OR operator must
be true for the record to be selected.
RAINFALL < 20 OR SLOPE > 35
Use the NOT operator at the beginning of an expression to find features or records that don't match the specified
expression. NOT expressions can be combined with AND and OR.
SUB_REGION = 'New England' AND NOT STATE_NAME = 'Maine'

Querying dates
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.

Clearing the selected features


Use the Clear Selected Features command to unselect all the selected features and clear the selection set. You can
find this command in the Selection pulldown menu, where it operates on all the layers in the active data frame
whether or not they are currently selectable, or by right-clicking a layer, where it just operates on that layer.
A shortcut for using the Clear Selected Features command is to use one of these tools:
- Select Features tool in the Tools toolbar
- Edit tool in the Editor toolbar
and click or drag a box on the map without selecting any features. This will clear the selection sets for all the layers
in the active data frame.

SUMMARIZING AND GETTING STATISTICS FROM TABLES

Open up the attribute table and right click on any column. Access to a few tools is possible including summarize
and statistics.
Summarizing data creates a simple summary table that can be added to your map.

Getting statistics from a table


We will be doing our queries and selections on a VRI dataset. Below is a simplified description of the data

VRI
Background Information
The Forest Resources Commission recommended a review of the provincial resource inventory process in its report
The Future of our Forests. The Resources Inventory Standards Committee (RISC) was established with the objective
of achieving common standards and procedures.
The Vegetation Resources Inventory is a photo-based, two-phased vegetation inventory program consisting of:

Phase I: Photo Interpretation


Phase II: Ground Sampling

Within the ground sampling phase, Net Volume Adjustment Factor (NVAF) sampling is a mandatory component
that is integral in the calculation of inventory adjustment factors.
The Ministry of Forests and Range and forest licensees, is implementing the components of the Vegetation
Resources Inventory.

What is the Vegetation Resource Inventory designed to do?


The Vegetation Resources Inventory is designed to answer two questions:

1. Where is the resource located?


2. How much of a given vegetation resource (for example, timber or coarse woody debris) is within an
inventory unit?
Questions:
Add the VRI dataset to your map open the attribute table and answer the following questions

1. What feature type is the data?

2. What TRIM mapsheet is the data on?

3. How many features are in the dataset?

4. Go to the shape_area field. From the using the statistics function


a. What is the size of the largest polygon?
b. What is the size of the smallest polygon?

5. Look at the LINE_3_TREE_SPECIES field and compare it to the SPECIES_CD_1, SPECIES_CD_2,


SPECIES_CD_3 ... fields. What do you notice.

6. How many polygons have a SPECIES_CD_1 that is = Sw?

7. How many polygons have a SPECIES_CD_1 that start with S


8. What value do you get when you put in the following SQL statement
a. [SPECIES_CD_1] = 'PLI'
b. [SPECIES_CD_1] = 'PLI' and [SPECIES_PCT_1] > 50
c. [SPECIES_CD_1] = 'PLI' or [SPECIES_PCT_1] > 50 (why the difference between b and c)

9. How many <Null> values are in the [SPECIES_CD_2] column?

10. How many polygons Have a [SPECIES_CD_1] the is PLI and [SPECIES_PCT_1] = 60 and a [SPECIES_CD_2]
of SW [SPECIES_PCT_2] less than or equal to 30

11. What is the area in hectares of the following polygon whose map_id is 093G098 and poly_id is 1328?

12. Add a field called OPENING_ID (TEXT, 25). Populate the field with the values from MAPSHEET and
Polygon_id, separated by a hyphen (-) i.e 93G098-102

13. How many polygons are greater than 40 hectares?


a. What is the sum of these polygons?
b. What is the sum of these polygons excluding the Null values

14. Remove all queries from your data. Go to the data view and symbolize the data on [SPECIES_CD_1]. Add
the VRI_Species1.lyr

15. Add the data again and this time add the following layer file Level5.lyr
a. What is the size of the large lake (Tabor Lake) in the south portion of the data.
b. Print a map with a scale bar and north arrow that shows the area of Tabor Lake in hectares

16. How many polygons have 6 species codes?


a. What is the maximum percentage?
b. Look at the selected data on your map. Where on the mapsheet is the majority of the data
located?
c. Duplicate the same query on the layer and symbolize based on the [SPECIES_PCT_6]. In the
layout view add a scale bar and north arrow. Set the scale to 80000. Export the map to a .pdf
and load it onto your web page.

Das könnte Ihnen auch gefallen