Presentation is loading. Please wait.

Presentation is loading. Please wait.

Chapter 5 Queries.

Similar presentations


Presentation on theme: "Chapter 5 Queries."— Presentation transcript:

1 Chapter 5 Queries

2 Outline About queries Attribute queries Spatial queries

3 What are Queries? Operation to 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

4 Why queries? Selecting features of interest Exploring patterns
Isolating for more analysis Exploring spatial relationships

5 Attribute Queries Operation to extract specific values in the records from a table. Operation is based on SQL (Structured Query Language). SQL can write queries that work in multiple DBMS environments. Queries can be saved and reused. Nearly always case-sensitive.

6 SQL Examples Some Valid Queries SELECT *FROM cities WHERE "POP2010" >= SELECT *FROM counties WHERE “BEEFCOW_92” > “BEEFCOW_87” SELECT *FROM parcels WHERE “LU-CODE” = 42 AND “VALUE” > SELECT *FROM rentals WHERE “RENT” > 1000 AND “RENT” < 1500 In most databases, SQL expressions are case-sensitive “Smith” ≠ “SMITH”

7 Boolean expressions AND and OR are known as Boolean operators. Boolean operators are used to evaluate pairs of conditions. A AND B A OR B A B

8 AND vs OR? T A B C Let T = [all students in University] Let A = [students from New York] Let B = [Geography majors] Let C = [English majors] A AND B A B Select students from T where [Home_State] = “NY” AND [Major] = “Geography”

9 AND vs OR? T A B C Let T = [all students in University] Let A = [students from New York] Let B = [Geography majors] Let C = [English majors] A OR B A B Select students from T where [Home_State] = “NY” OR [Major] = “Geography”

10 Other Boolean operators
A AND B A XOR B A NOT B A OR B A B Some databases use additional operators besides AND and OR.

11 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

12 Boolean operators have equal order or precedence
Evaluation occurs from left to right Parentheses must be used to change order

13 Remember—you test each feature separately
Test: AND vs OR Remember—you test each feature separately Wrong Right “Land-use” = ‘RES’ AND “Land-use” = ‘COM’ “Land-use” = ‘RES’ OR “Land-use” = ‘COM’ “Pop2000” ≥ 5000 OR “Pop2000” < 9000 “Pop2000” ≥ 5000 AND “Pop2000” < 9000

14 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*

15 The Like Operator “NAME” LIKE ‘%(D)%’ % is wildcard
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

16 Basic spatial relationships
Spatial queries Operation to extract records from a data layer based on location relative to another data layer. Basic spatial relationships 1. Intersection Does the road cross the aspen? Do two polygons share areas or boundaries? 2. Containment Is the aspen inside a geology unit? Is a road inside a geology unit? 3. Proximity How many aspen stands within 200 meters of a road.

17 Spatial operators Select the aspen stands that are intersected by roads. Spatial queries can employ a number of operators to test the basic conditions of intersection, containment, and proximity. 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.

18 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.

19 Types of containment Contains Completely 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.

20 Clementini operators 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.

21 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 Rio Grande River Conversely, the Rio Grande is within Texas using the standard operator, but is not within Texas using the Clementini operator.

22 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

23 References Price, M. (2013). Mastering ArcGIS (6th ed.). McGraw-Hill
Price, M. (2013). Mastering ArcGIS (6th ed.). McGraw-Hill. Mastering ArcGIS, 6/e Instructor Edition Chapter 5: PowerPoint Notes and Figures


Download ppt "Chapter 5 Queries."

Similar presentations


Ads by Google