Presentation is loading. Please wait.

Presentation is loading. Please wait.

Return to Outline Copyright © 2009 by Maribeth H. Price 5-1 Chapter 5 Queries.

Similar presentations


Presentation on theme: "Return to Outline Copyright © 2009 by Maribeth H. Price 5-1 Chapter 5 Queries."— Presentation transcript:

1 Return to Outline Copyright © 2009 by Maribeth H. Price 5-1 Chapter 5 Queries

2 Return to Outline Copyright © 2009 by Maribeth H. Price 5-2 Outline GIS Concepts –About queriesAbout queries –Attribute queriesAttribute queries –Spatial queriesSpatial queries About ArcGIS –General information on queriesGeneral information on queries –Interactive selectionInteractive selection –Select By Attributes and Select By LocationSelect By Attributes and Select By Location –Selection methodsSelection methods –Creating layers from queriesCreating layers from queries

3 Return to Outline Copyright © 2009 by Maribeth H. Price 5-3 About queries

4 Return to Outline Copyright © 2009 by Maribeth H. Price 5-4 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

5 Return to Outline Copyright © 2009 by Maribeth H. Price 5-5 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

6 Return to Outline Copyright © 2009 by Maribeth H. Price 5-6 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?

7 Return to Outline Copyright © 2009 by Maribeth H. Price 5-7 Isolating for more analysis Are there any mature stands with large trees and open crowns? Where are they? [TREE_SZ96] = 'L' AND [DENSITY96] = 'A'

8 Return to Outline Copyright © 2009 by Maribeth H. Price 5-8 Exploring spatial relationships What fraction of stands are intersected by roads? What types of trees are adjacent to aspen stands?

9 Return to Outline Copyright © 2009 by Maribeth H. Price 5-9 Attribute queries

10 Return to Outline Copyright © 2009 by Maribeth H. Price 5-10 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

11 Return to Outline Copyright © 2009 by Maribeth H. Price 5-11 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”

12 Return to Outline Copyright © 2009 by Maribeth H. Price 5-12 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

13 Return to Outline Copyright © 2009 by Maribeth H. Price 5-13 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

14 Return to Outline Copyright © 2009 by Maribeth H. Price 5-14 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

15 Return to Outline Copyright © 2009 by Maribeth H. Price 5-15 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

16 Return to Outline Copyright © 2009 by Maribeth H. Price 5-16 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.

17 Return to Outline Copyright © 2009 by Maribeth H. Price 5-17 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

18 Return to Outline Copyright © 2009 by Maribeth H. Price 5-18 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

19 Return to Outline Copyright © 2009 by Maribeth H. Price 5-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] 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

20 Return to Outline Copyright © 2009 by Maribeth H. Price 5-20 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

21 Return to Outline Copyright © 2009 by Maribeth H. Price 5-21 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.

22 Return to Outline Copyright © 2009 by Maribeth H. Price 5-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 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

23 Return to Outline Copyright © 2009 by Maribeth H. Price 5-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 Return to Outline Copyright © 2009 by Maribeth H. Price 5-24 Order of operations Boolean operators have equal order or precedence Evaluation occurs from left to right Parentheses must be used to change order

25 Return to Outline Copyright © 2009 by Maribeth H. Price 5-25 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

26 Return to Outline Copyright © 2009 by Maribeth H. Price 5-26 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*

27 Return to Outline Copyright © 2009 by Maribeth H. Price 5-27 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

28 Return to Outline Copyright © 2009 by Maribeth H. Price 5-28 Spatial queries

29 Return to Outline Copyright © 2009 by Maribeth H. Price 5-29 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 geology unit? Proximity –How many aspen stands within 200 meters of a road?

30 Return to Outline Copyright © 2009 by Maribeth H. Price 5-30 Spatial operators Spatial queries can employ a number of operators to test the basic conditions of intersection, containment, and proximity.

31 Return to Outline Copyright © 2009 by Maribeth H. Price 5-31 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.

32 Return to Outline Copyright © 2009 by Maribeth H. Price 5-32 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.

33 Return to Outline Copyright © 2009 by Maribeth H. Price 5-33 Containment operators Features that enclose all of another feature contain it. Within is the inverse of contain

34 Return to Outline Copyright © 2009 by Maribeth H. Price 5-34 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. Columbia county is within Oregon. Jefferson county is completely within Oregon.

35 Return to Outline Copyright © 2009 by Maribeth H. Price 5-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 Return to Outline Copyright © 2009 by Maribeth H. Price 5-36 About ArcGIS Chapter 5. Queries

37 Return to Outline Copyright © 2009 by Maribeth H. Price 5-37 General information about queries

38 Return to Outline Copyright © 2009 by Maribeth H. Price 5-38 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

39 Return to Outline Copyright © 2009 by Maribeth H. Price 5-39 Selection tools Selection menuTable of Contents Selection tab

40 Return to Outline Copyright © 2009 by Maribeth H. Price 5-40 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

41 Return to Outline Copyright © 2009 by Maribeth H. Price 5-41 Viewing selected features Highlighted in table Highlighted in map States for which POP2000>2 million

42 Return to Outline Copyright © 2009 by Maribeth H. Price 5-42 Selection states No selection –All features exported No selected features –No features exported Selected features –Only selected features exported Example: Exporting features to a new shapefile

43 Return to Outline Copyright © 2009 by Maribeth H. Price 5-43 Clear Selection On toolbar From table options menu From main menu

44 Return to Outline Copyright © 2009 by Maribeth H. Price 5-44 Interactive selection

45 Return to Outline Copyright © 2009 by Maribeth H. Price 5-45 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.

46 Return to Outline Copyright © 2009 by Maribeth H. Price 5-46 Selectable Layers States selectable All layers selectable

47 Return to Outline Copyright © 2009 by Maribeth H. Price 5-47 Select by Graphics Use Drawing toolbar to create graphic Then Select by Graphics

48 Return to Outline Copyright © 2009 by Maribeth H. Price 5-48 Select by Attributes Select by Location

49 Return to Outline Copyright © 2009 by Maribeth H. Price 5-49 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

50 Return to Outline Copyright © 2009 by Maribeth H. Price 5-50 Select by Location Target layer Source layer Spatial operator

51 Return to Outline Copyright © 2009 by Maribeth H. Price 5-51 Intersect

52 Return to Outline Copyright © 2009 by Maribeth H. Price 5-52 Within distance of

53 Return to Outline Copyright © 2009 by Maribeth H. Price 5-53 Using a selected set

54 Return to Outline Copyright © 2009 by Maribeth H. Price 5-54 Within the same layer

55 Return to Outline Copyright © 2009 by Maribeth H. Price 5-55 Selection methods

56 Return to Outline Copyright © 2009 by Maribeth H. Price 5-56 Selection methods Available for all three types of selection

57 Return to Outline Copyright © 2009 by Maribeth H. Price 5-57 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 BCreate new selection A; Add B to current selection A AND BCreate new selection A; Select B from current selection A NOT BCreate new selection A; Remove B from current selection

58 Return to Outline Copyright © 2009 by Maribeth H. Price 5-58 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

59 Return to Outline Copyright © 2009 by Maribeth H. Price 5-59 Combining queries Cities within 50mi 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.

60 Return to Outline Copyright © 2009 by Maribeth H. Price 5-60 Spatial query Cities within 50mi of earthquakes

61 Return to Outline Copyright © 2009 by Maribeth H. Price 5-61 Attribute query Cities within 50mi of earthquakes Having > 500,000 people

62 Return to Outline Copyright © 2009 by Maribeth H. Price 5-62 Creating layers from queries

63 Return to Outline Copyright © 2009 by Maribeth H. Price 5-63 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.

64 Return to Outline Copyright © 2009 by Maribeth H. Price 5-64 Layers based on selections Still based on one original file shared by both layers Shows only a selected subset in the map and in the table Use as input for a tool, e.g. buffer only the aspen stands [cover_type] = ‘Aspen’ It’s smart to rename this so you can remember what it is.

65 Return to Outline Copyright © 2009 by Maribeth H. Price 5-65 Creating layers

66 Return to Outline Copyright © 2009 by Maribeth H. Price 5-66 Exporting selections Creates new feature class

67 Return to Outline Copyright © 2009 by Maribeth H. Price 5-67 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.

68 Return to Outline Copyright © 2009 by Maribeth H. Price 5-68


Download ppt "Return to Outline Copyright © 2009 by Maribeth H. Price 5-1 Chapter 5 Queries."

Similar presentations


Ads by Google