Upload
peregrine-lucas
View
213
Download
0
Embed Size (px)
Citation preview
Copyright © 2006 by Maribeth H. Price
6-1
Chapter 6
Queries
Copyright © 2006 by Maribeth H. Price
6-2
Outline
• Understanding queries and how they are used• Knowing how to select features interactively
using a variety of methods• Selecting features using SQL queries on their
attributes• Selecting features based on their spatial
location with respect to other features• Using Definition Queries to create subsets of
data layers
Copyright © 2006 by Maribeth H. Price
6-3
What are queries?
• Extract certain records from a map or table
• Records meet certain criteria– Aspatial queries
• All parcels with value greater than $100,000.
– Spatial queries• All parcels that lie completely within the flood plain
Copyright © 2006 by Maribeth H. Price
6-4
Selected features
Highlighted in tableHighlighted in map
States for which POP2000>2 million
Copyright © 2006 by Maribeth H. Price
6-5
Types of Queries
• Interactive selection– Choose features by pointing to them on the
screen
• Select By Attribute– Select features based on attribute criteria
• Select By Location– Select features based on their spatial
relationships
Copyright © 2006 by Maribeth H. Price
6-6
Interactive Selection
Select Features tool
Click on feature to select
Hold down shift key to select more than one feature
Draw a rectangle that passes through features to be selected.
Copyright © 2006 by Maribeth H. Price
6-7
Selectable LayersStates selectableAll layers selectable
Copyright © 2006 by Maribeth H. Price
6-8
Selection options
Copyright © 2006 by Maribeth H. Price
6-9
Clear SelectionOn toolbar
From table options menu From main menu
Copyright © 2006 by Maribeth H. Price
6-10
The Selection tab
Right-click entry for context menu
You can also make layers selectable here by checking them
This one clears features only for this layer
Copyright © 2006 by Maribeth H. Price
6-11
Selection logic
• No selection– All features exported
• No selected features– No features exported
• Selected features– Only selected features
exported
Example: Exporting features to a new shapefile
Copyright © 2006 by Maribeth H. Price
6-12
Two ways to select features
• Selecting by Attribute– Queries based on one or more fields in the
table• Find all wells with chloride concentration > 100ppm
• Selecting by Location– Queries based on the relationship of features
to another layer• Find all wells that lie inside industrial parcels
Copyright © 2006 by Maribeth H. Price
6-13
Select By Attribute
Some Valid Queries
SELECT *FROM cities WHERE "POP1990" >= 500000
SELECT *FROM counties WHERE “BEEFCOW_92” < “BEEFCOW_87”
SELECT *FROM parcels WHERE “LU-CODE” = 42 AND “VALUE” > 50000
SELECT *FROM rentals WHERE “RENT” > 700 AND “RENT” < 1500
Note: Shapefile tables use quotes for field names; geodatabase tables use brackets
Copyright © 2006 by Maribeth H. Price
6-14
The Like Operator
• “NAME” LIKE ‘%(D)%’ – Finds all of the (D)
Democrats
• % is wildcard• Ignores Don or Danforth
• “NAME” LIKE ‘%New %’ – Would find New Hampshire
and New York, but not Newcastle or Kennewick
Copyright © 2006 by Maribeth H. Price
6-15
Boolean expressions
A AND B
A XOR B A NOT B
A OR B
A B
0
1
Blue circles represent areas where condition holds
(True) = 1
Copyright © 2006 by Maribeth H. Price
6-16
AND vs OR
“Land-use” = ‘RES’ AND
“Land-use” = ‘COM’
“Land-use” = ‘RES’ OR
“Land-use” = ‘COM’
“Pop2000” ≥ 5000 OR
“Pop2000” < 9000
“Pop2000” ≥ 5000 AND
“Pop2000” < 9000
Wrong Right
Remember—you test each feature separately
Copyright © 2006 by Maribeth H. Price
6-17
Multiple conditions
• Use parentheses to enforce order of evaluation
(“LU” = ‘RES’ or “LU” = ‘COM’) and “Value” > 100000
“LU” = ‘RES’ or (“LU” = ‘COM’ and “Value” > 100000)
$75,000
$125,000
$75,000
$125,000
$75,000
$125,000
$75,000
$125,000
RES COM
Copyright © 2006 by Maribeth H. Price
6-18
Select By Location
Select counties that completely contain state capitals
Select counties that are within 200 miles of Denver
Copyright © 2006 by Maribeth H. Price
6-19
Select By Location
Select counties that intersect rivers
Select rivers that intersect Texas
Copyright © 2006 by Maribeth H. Price
6-20
Select By Location
Select cities that are within 20 miles of an interstate highway
Select cities that are completely within counties named Washington
Copyright © 2006 by Maribeth H. Price
6-21
Selecting by location
Copyright © 2006 by Maribeth H. Price
6-22
Intersect
Copyright © 2006 by Maribeth H. Price
6-23
Within distance of
Copyright © 2006 by Maribeth H. Price
6-24
Using a selected set
Copyright © 2006 by Maribeth H. Price
6-25
Within the same layer
Copyright © 2006 by Maribeth H. Price
6-26
Selection methods
Available for all three types of selection
Copyright © 2006 by Maribeth H. Price
6-27
Applying selection methods
Create new selection: hearts = yellow
Add to current selection: hearts = red
Add to current selection: hearts = blue
Remove from selection: hearts = red
Select from selection: hearts = blue
Select from selection: hearts = orange
Copyright © 2006 by Maribeth H. Price
6-28
Select from currentCities within 50mi of earthquakes
Having > 500,000 people
Copyright © 2006 by Maribeth H. Price
6-29
Creating layers
• Common operation following a query• Creates a layer file
Copyright © 2006 by Maribeth H. Price
6-30
Creating layers
Copyright © 2006 by Maribeth H. Price
6-31
Exporting selections
Creates new shapefile
Copyright © 2006 by Maribeth H. Price
6-32
Definition Queries
• Redefine a layer to include a subset of the actual features
• Only selected features appear on map and in table
• Has no effect on data stored on disk• Temporarily treats a layer as being smaller
than it actually is• Does not require an additional data set to
be stored.
Copyright © 2006 by Maribeth H. Price
6-33