Copyright © 2006 by Maribeth H. Price 5-1 Chapter 5 Working with Tables
Copyright © 2006 by Maribeth H. Price 5-2 Outline Knowing types and structure of tables Managing table files Modifying appearance of tables and fields Editing fields and calculating new values Selecting records by queries Creating summary statistics for table fields Understanding cardinality in table relationships Creating joins and relates between tables
Copyright © 2006 by Maribeth H. Price 5-3 Tables Tables contain attribute data Many formats, one interface
Copyright © 2006 by Maribeth H. Price 5-4 Types of tables Attribute table –Stores attributes of map features –Associated with a spatial data layer –Has special fields for spatial information Standalone table –Stores any tabular data –Not associated with spatial data –OID instead of FID
Copyright © 2006 by Maribeth H. Price 5-5 Sources of tables Dbase files INFO files ASCII Text files (tab or comma delimited) –Excel csv files Records from SQL database systems
Copyright © 2006 by Maribeth H. Price 5-6 Parts of a table Title Field Right-click field name to get menu Records Status bar Options menu
Copyright © 2006 by Maribeth H. Price 5-7 Fields Fields have specific types available Must be defined before use Once defined, cannot be changed Naming rules –No more than 13 characters –Use only letters and numbers –Must start with a letter
Copyright © 2006 by Maribeth H. Price 5-8 Field types Geodatabases and shapefiles Short Integers stored as 2-byte binary numbers (value range from -32,000 to +32,000) Long Integers stored as 4-byte binary numbers (value range from -2 billion to +2 billion) Float Floating point values with 8 significant digits in the mantissa e12 Double Double-precision floating point values with 16 significant digits in the mantissa e13 Text Alphanumeric strings‘Maple St’ Date Date format07/12/92 BLOB Binary large object; any complex binary data including images, documents, etc.
Copyright © 2006 by Maribeth H. Price 5-9 Field characteristics Length –The total characters a text field can store Precision –The total width of digits a numeric field can store Scale –The number of decimal places Length = 10 Maple St. Maple Stre
Copyright © 2006 by Maribeth H. Price 5-10 Adjusting field width Temporary, does not affect stored file Hover over field break to get double arrow, then drag
Copyright © 2006 by Maribeth H. Price 5-11 Field properties tab Field alias Hide field
Copyright © 2006 by Maribeth H. Price 5-12 Shortcut to field properties
Copyright © 2006 by Maribeth H. Price 5-13 Formatting field display
Copyright © 2006 by Maribeth H. Price 5-14 Table appearance
Copyright © 2006 by Maribeth H. Price 5-15 Sorting tables Has no effect on original data
Copyright © 2006 by Maribeth H. Price 5-16 Selecting records
Copyright © 2006 by Maribeth H. Price 5-17 Show selected
Copyright © 2006 by Maribeth H. Price 5-18 Clear Selection On toolbar From table options menu From main menu
Copyright © 2006 by Maribeth H. Price 5-19 The Selection tab Right-click entry for context menu
Copyright © 2006 by Maribeth H. Price 5-20 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 5-21 Field statistics
Copyright © 2006 by Maribeth H. Price 5-22 Statistics Statistics for fields are based on the selected records
Copyright © 2006 by Maribeth H. Price 5-23 SQL Queries Some valid queries [POP1990] > “STATE_NAME” = ‘Alabama’ [POP2000] >= [POP1990] Note: DBF tables have field names enclosed in quotes Geodatabase tables have field names enclosed in brackets
Copyright © 2006 by Maribeth H. Price 5-24 Multiple Criteria Queries Multiple criteria queries using AND or OR “STATE_NAME” = ‘Alabama’ OR “STATE_NAME” = ‘Texas’ –Note that the field name must be repeated for each condition
Copyright © 2006 by Maribeth H. Price 5-25 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 5-26 Multiple conditions Use parentheses to enforce order of evaluation (“LU” = ‘RES’ or “LU” = ‘COM’) and “Value” > “LU” = ‘RES’ or (“LU” = ‘COM’ and “Value” > ) $75,000 $125,000 $75,000 $125,000 $75,000 $125,000 $75,000 $125,000 RESCOM
Copyright © 2006 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
Copyright © 2006 by Maribeth H. Price 5-28 Adding a new field In ArcCatalog layer properties
Copyright © 2006 by Maribeth H. Price 5-29 Adding a field In ArcMap
Copyright © 2006 by Maribeth H. Price 5-30 Editing fields Open Editor toolbarStart editing Type edits in fields Save edits, stop editing
Copyright © 2006 by Maribeth H. Price 5-31 Calculating fields Add a new field if necessary Consider whether you need decimal places!
Copyright © 2006 by Maribeth H. Price 5-32 Calculate Right-click field to calculate Enter expression
Copyright © 2006 by Maribeth H. Price 5-33 Summarize My nomination for Most Useful Function! What is it? When to use it…
Copyright © 2006 by Maribeth H. Price 5-34 How many quakes in each state? Total deaths per state? Average magnitude per state?
Copyright © 2006 by Maribeth H. Price 5-35 Summarizing tables Calculate statistics for groups of features in a table Groups by unique values in the specified field User chooses statistics to calculate Produces another table as output with groups and stats How many earthquakes in each state? Total deaths and damage in each state? Average magnitude in each state? Historic major earthquakes
Copyright © 2006 by Maribeth H. Price 5-36 Example Group earthquakes by state field Determine total deaths, total damage, and average magnitude of earthquakes in each state.
Copyright © 2006 by Maribeth H. Price 5-37 How to summarize Right-click State field Sum Deaths Sum Damage Average Mag Average MMI
Copyright © 2006 by Maribeth H. Price 5-38 Summarize Output Table Count field always generated automatically
Copyright © 2006 by Maribeth H. Price 5-39 Create map Can we now create a map of deaths by state? Standalone table
Copyright © 2006 by Maribeth H. Price 5-40 Joining tables Summarize output table States layer attributes
Copyright © 2006 by Maribeth H. Price 5-41 US Earthquake Deaths by State Join summarize output to states layer to create map of deaths
Copyright © 2006 by Maribeth H. Price 5-42 Joining tables Join tables on common field Joined table Destination tableSource table
Copyright © 2006 by Maribeth H. Price 5-43 Join facts Joins are temporary relationships between tables Tables must share a common field Treats the two tables as a single table Original stored data is not affected Can be removed when no longer needed
Copyright © 2006 by Maribeth H. Price 5-44 One-to-one joins Each record in the destination table matches exactly one record in the source table. Destination table Source table We call this a cardinality of one-to-one.
Copyright © 2006 by Maribeth H. Price 5-45 Types of Cardinality One-to-one –States to Governors –Husbands to wives One-to-many –States to cities –Districts to schools Many to one –Cities to states –Schools to districts Many-to-many –Students to classes –Stores to customers
Copyright © 2006 by Maribeth H. Price 5-46 Relational databases RestaurantRes- ID Parcel_no Jake’s Pizza Momma’s Pie Hut Big Burger Barn Res-IDNameSSN 20Jake Smith Nancy Gold Dan Smurt Karen White Judy Lewis Joshua Jones Parcel_noAddressValueOwner Maple Ave67,000Roger Clark Main St114,510Roger Clark Sherry Ave59,000Judy Lewis Store distinct tables Establish relationships between them
Copyright © 2006 by Maribeth H. Price 5-47 Rule of Joining Each record in the destination table must match one and only one record in the source table. One to one Destination table Source table Many to one
Copyright © 2006 by Maribeth H. Price 5-48 One to many Destination table Source table ? Violates the Rule of Joining Record to join to destination is ambiguous Must use a relate instead
Copyright © 2006 by Maribeth H. Price 5-49 Relates Similar to a join except that –The tables remain separate –Items selected in one table may be highlighted in the related table
Copyright © 2006 by Maribeth H. Price 5-50 States Congressional Districts Related tables
Copyright © 2006 by Maribeth H. Price 5-51 How to join or relate tables