Download presentation
Presentation is loading. Please wait.
Published byMerry Newman Modified over 8 years ago
1
Chapter 8- Queries 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
2
Selecting features of interest [COV_TYPE] = “TAA” Selecting aspen stands from a forest vegetation layer. Using statistics on areas (m 2 ) Minimum:12,900 Maximum:750,500 Sum:10,529,000
3
Exploring patterns Are aspen stands randomly scattered or clustered? Do they occur in particular portions of the forest? What are the distributions of stand densities?
4
Isolating for more analysis Are there any mature stands with large trees and open crowns? Where are they? [TREE_SZ96] = 'L' AND [DENSITY96] = 'A'
5
Exploring spatial relationships What fraction of stands are intersected by roads? What types of trees are adjacent to aspen stands?
6
Queries involving surfaces Over what range of elevations do aspen occur? Do aspen occur above 1500m elevation? Raster query [Elevation] > 1500
7
Attribute queries- SQL Many databases use a special query language called Structured Query Language Can write queries that work in multiple DBMS environments Queries can be saved and reused Nearly always case-sensitive
8
SQL Query Examples 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 Programs may have an interface to help users build SQL expressions In most databases, SQL expressions are case-sensitive “Smith” ≠ “SMITH”
9
Queries as sets Let T = [all students in University] Let A = [students from New York] Let B = [Geography majors] Let C = [English majors] Queries are used to extract subsets (records) of interest from a set (table). Multiple criteria may be used (such as Geography majors from New York) T A B C
10
Single criteria Let T = [all students in University] Let A = [students from New York] Let B = [Geography majors] Let C = [English majors] Select students from T where [Home_State] = “NY” Select students from T where [Major] = “Geography” T A B C
11
Double criteria Let T = [all students in University] Let A = [students from New York] Let B = [Geography majors] Let C = [English majors] Select students from T where [Home_State] = “NY” OR [Home_State] = “NJ” Select students from T where [Home_State] = “NY” AND [Major] = “Geography” T A B C
12
AND vs OR? Let T = [all students in University] Let A = [students from New York] Let B = [Geography majors] Let C = [English majors] Select students from T where [Home_State] = “NY” OR [Home_State] = “NJ” Select students from T where [Home_State] = “NY” AND [Major] = “Geography” Each condition is tested separately. If AND is used, then BOTH must be true. If OR is used, then either may be true. T A B C
13
Boolean expressions A AND BA OR B A B AND and OR are known as Boolean operators. Boolean operators are used to evaluate pairs of conditions.
14
AND vs OR? Let T = [all students in University] Let A = [students from New York] Let B = [Geography majors] Let C = [English majors] Select students from T where [Home_State] = “NY” AND [Major] = “Geography” A AND B A B T A B C
15
AND vs OR? Let T = [all students in University] Let A = [students from New York] Let B = [Geography majors] Let C = [English majors] T A B C Select students from T where [Home_State] = “NY” OR [Major] = “Geography” A OR B A B
16
What do you get? Let T = [all students in University] Let A = [students from New York] Let B = [Geography majors] Let C = [English majors] Select students from T where [Major] = “Geography” AND [Major] = English” B AND C Select students from T where [Major] = “Geography” OR [Major] = “English” B OR C Select students from T where [State] = “NY” AND [Major] = “English” A AND C Select students from T where [State = “NY” OR [Major] = “English” A OR C T A B C
17
What do you get? Let T = [all students in University] Let A = [students from New York] Let B = [GPA > 3.0] Let C = [GPA < 2.0] Select students from T where [State] = “NY” AND [GPA] > 3.0 A AND B Select students from T where [State] = “NY” OR [GPA] > 3.0 A OR B Select students from T where [GPA] > 2.0 AND [GPA] < 3.0 ? AND ? Select students from T where [GPA] > 2.0 OR [GPA] < 3.0 ? OR ? T A B C
18
Other Boolean operators A AND B A XOR BA NOT B A OR B A B Some databases use additional operators besides AND and OR.
19
What do you get? Let T = [all students in University] Let A = [students from New York] Let B = [Geography majors] Let C = [English majors] A AND B A OR B A XOR B B XOR C A NOT B B NOT C T A B C A AND B A XOR BA NOT B A OR B A B B AND A B OR A B XOR A B XOR C B NOT A C NOT B
20
Commutation of operators AND, OR and XOR are commutative – A AND B == B AND A – A OR B == B OR A – A XOR B == B XOR A NOT is not commutative –A NOT B ≠≠ B NOT A
21
Order of operations Boolean operators have equal order or precedence Evaluation occurs from left to right Parentheses must be used to change order
22
What do you get? Let T = [all students in University] Let A = [students from New York] Let B = [Geography majors] Let C = [English majors] A AND B OR C ( A AND B ) OR C A AND (B OR C) (A OR B ) AND C A OR (B AND C) T A B C A AND B A XOR BA NOT B A OR B A B
23
Test: 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
24
Multiple conditions Test using these parcels (“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 RESCOM
25
Searching for partial matches Sometimes you need to find one string within another rather than an exact match – Find all customer names beginning with “Mac” or “Mc” – Find all zip codes beginning with 0 Typically uses a “wildcard” character – *Mac* or *Mc* – 0*
26
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
27
Spatial Queries Basic spatial relationships Intersection –Does the road cross the aspen? –Do two polygons share areas or boundaries? Containment –Is the aspen inside a geology unit? –Is a road inside a geolgoy unit? Proximity –How many aspen stands within 200 meters of a road?
28
Spatial operators Spatial queries can employ a number of operators to test the basic conditions of intersection, containment, and proximity.
29
The operators test relationships between two layers at a time. –The target layer is the one containing the features to be selected –The source layer is the one containing the features being compared to. Select the roads that are intersected by aspen stands. Select the aspen stands that are intersected by roads.
30
Intersection operators Features intersect when any part of one feature touches, crosses, or overlaps another feature. The lower set includes “special cases” of intersecting features.
31
Containment operators Features that enclose all of another feature contain it. Within is the inverse of contain
32
Types of containment Contains –One feature lies inside another and may share a boundary –Oregon contains Columbia county Completely contains –One feature lies inside another without touching the boundary –Oregon does not completely contain Columbia county, but does completely contain Jefferson county Columbia Jefferson Within is the inverse of contains. Columbia county is within Oregon. Jefferson county is completely within Oregon.
33
Clementini operators Eliseo Clementini and his coauthors defined a special set of topological relationships concerning containment*. Clementini considers the boundary of a polygon to be separate from its inside or outside. The Clementini operator is equivalent to the standard operator except when the source feature lies only on the boundary of the target feature. *Eliseo Clementini, Paolino Di Felice, and Peter van Oosterom, A Small Set of Formal Topological Relationships Suitable for End-User Interaction. Proceedings of the Third International Symposium on Advances in Spatial Databases, pp. 277-295, June 23-25, 1993.
34
Clementini example The Rio Grande River lies on the border of Texas –The Contains operator would select the Rio Grande –The Clementini Contains operator would NOT select the Rio Grande because the state boundary is not considered part of Texas For the example, we ignore the Rio Grande after it leaves Texas… Conversely, the Rio Grande is within Texas using the standard operator, but is not within Texas using the Clementini operator.
35
Proximity operators This operator tests whether the target features are within a specified distance of the source features. Volcanoes within 100 km of an interstate
36
More examples Select counties that contain state capitals Select counties that are within 200 miles of Denver
37
More examples Select counties that intersect rivers Select rivers that intersect Texas
38
More examples Select cities that are within 20 miles of an interstate highway Select cities that are within counties named Washington
39
Scale and accuracy issues When testing spatial relationships, consider that features are often generalized. Consider selecting cities that lie on (intersect) rivers. A single point or line cannot adequately represent location at this scale. Selection becomes a hit or miss affair. One can use buffers to allow a little room for error.
40
Topology issues In the real world, certain boundaries coincide. This condition won’t hold true for many feature classes unless they have been specifically checked and corrected for logical consistency. Keep in mind that your data sets may contain topological inconsistencies that may affect your results. Shannon County Bennett County Pine Ridge Indian Reservation South Dakota Nebraska Here, Shannon County should contain the Pine Ridge Reservation, but it does not.
41
Extraction functions Similar to Select By Location except that they can split features that cross the boundaries. –Clip extracts features within the boundary –Erase keeps features outside the boundary clip erase
42
Extraction functions Extracts portions of features based on an overlay layer. Clip keeps the features inside the feature boundary. Erase keeps the features outside the feature boundary. clip/erase layer Roads are the input layer, land use is the clip layer.
43
The clip layer The clip and erase functions ignore internal boundaries and attributes in the clip layer. The entire region is used like a simple cookie cutter to extract features from the input layer. The attributes of the input layer are simply brought through unchanged.
44
Length/area changes Clip/erase can change the lengths or areas of features on the boundary. Geodatabase feature classes have Shape_Length and Shape_Area fields that are automatically updated. All other length or area-based fields are NOT updated. A user-defined MILES field would contain incorrect lengths after the clip.
45
On-the-fly clipping Temporary clip applied to a map layout Does not create new layers or affect lengths or areas of the source layers Can be performed on many layers simultaneously Can be removed when no longer needed Set as a data frame property
46
Clipping data frame layers
47
General information about queries in ArcMap 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
48
Selection tools Selection menu Table of Contents List By Selection
49
View by Selection Visibility Clear selection Selectable toggle Right-click to open menu Clears selection this layer only
50
Selection options
51
Viewing selected features Highlighted in table Highlighted in map States for which POP2000 > 8 million
52
Using Selected features Once a layer has a query placed upon it, all subsequent operations on that layer use ONLY the selected features. Volcanoes selected, then buffered Buffer uses only selected volcanoes Statistics only include selected volcanoes
53
Clear Selection One layer/tableAll layers/tables
54
Interactive Selection 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. Draw a circle with a specified radius.
55
Selectable Layers States selectableAll layers selectable Click to toggle selectability
56
Select by Graphics Use Drawing toolbar to create graphic Then Select by Graphics
57
Select by Attributes 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 Select layer
58
Select By Attributes Select By Location Target layer Source layer Spatial operator
59
Intersect
60
Within distance of
61
Using a selected set
62
Within the same layer
63
Selection methods Available for all three types of selection
64
The Boolean Two-Step Applying selection methods facilitates using multiple steps to apply multiple criteria—like using Boolean operators. OR NOT AND T A B C A OR B Create new selection A; Add B to current selection A AND B Create new selection A; Select B from current selection A NOT B Create new selection A; Remove B from current selection
65
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
66
Combining queries Cities within 50 mi of earthquakes Cities with population > 500,000 FEMA problem Distribute funding to quake- prone cities with large populations Both a spatial condition and an attribute condition Must be performed in sequence, although order doesn’t matter This is an AND operation.
67
Spatial query Cities within 50 mi of earthquakes
68
Attribute query Cities within 50mi of earthquakes Having > 500,000 people
69
Creating subsets from queries Creating layers Common operation following a query Creates a new layer with only the selected features Note that the new layer still refers to the original feature class with all the features. But it appears to contain only the selected features.
70
Exporting selections Creates new feature class
71
Creating a definition query 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.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.