SlideShare ist ein Scribd-Unternehmen logo
1 von 35
Downloaden Sie, um offline zu lesen
DOING MORE WITH SQL 
John Reiser 
MAC URISA 2014
#MACURISA2014 
DBMS Systems 
! Many of the modern DBMSs support spatial data. 
! Oracle, MS SQL, PostgreSQL are most often used. 
! PostgreSQL is 
! open source/free to use and modify 
! incredibly reliable, extensible, powerful 
! provides spatial capabilities through PostGIS 
! DBMSs allow for “enterprise” functionality, like 
multiple users/concurrency, high output, etc.
#MACURISA2014 
Structured Query Language 
! SQL is the standardized method of interacting with 
a database 
! Even Access allows you to use SQL 
! Common, hopefully familiar, statements: 
! Select (read from database) 
! Insert (new records into a DBMS) 
! Update (existing records in DBMS) 
! Delete (remove records from DBMS) 
! Where (limits your results)
#MACURISA2014 
Select Statements 
! Most common SQL 
query you will 
encounter 
! “Select By Attributes” 
has this as the 
foundation 
! Nothing more than 
“SELECT * FROM 
gis_layer WHERE…”
#MACURISA2014 
Joins 
! In ArcGIS or Access, you join two (or more) tables 
together using a primary key. 
! If the keys match, the secondary tables are tacked 
on to the first 
! Again, geospatial is special, so GIS has another 
type of join
#MACURISA2014 
Combining Tables 
! The simplest combination of two tables would be to 
combine each record from table A with each record 
from table B. 
! The Cartesian Product. 
! Example: A has 2 records, B has 3. 
! A ✕ B: {(A1, B1), (A1, B2), (A1, B3), 
(A2, B1), (A2, B2), (A2, B3)} 
! Let’s take a deck of cards as an example.
#MACURISA2014 
Joins 
! Think of a Join as limiting the Cartesian Product of 
two tables down to just the specific records desired. 
! The manner in which you form your SELECT … JOIN 
will be important: 
! Ensure the desired records and columns are returned. 
! Speed of the JOIN performed.
#MACURISA2014 
Spatial Joins 
! Relationship not determined by key, but by 
proximity or connectivity 
! Contains/Within/Overlaps 
! One feature falls entirely within another 
! Touches/Intersects/Crosses 
! One feature touches another 
! Equals or Disjoint
#MACURISA2014 
Set Theory 
! General terms first, because these concepts are 
used across GIS and not just in SQL. 
! Union 
! Intersection 
! Relative Complement 
! Symmetric Difference 
! Terms should be 
somewhat familiar…
#MACURISA2014 
Union 
! ArcToolbox: returns a set where all features are 
returned, however new features created where they 
intersect. 
! SQL: Set of all values from both tables. 
! Join: An FULL JOIN – all values from two tables, 
with NULL values where there are not shared values. 
! Venn:
#MACURISA2014 
Unions are not Cartesian 
! Union / FULL JOIN will leave NULLs where there 
are not matches across tables. All records will be 
returned, however the records will not be “shuffled” 
together like the cards example. 
! FULL JOINs still require a WHERE or ON predicate 
to create the join.
#MACURISA2014 
Example of Cartesian vs FULL 
! From Wikipedia:
#MACURISA2014 
Cartesian Product
#MACURISA2014 
FULL JOIN
#MACURISA2014 
Intersection 
! ArcToolbox: returns a set where the geometries of 
two different feature classes overlap. 
! SQL: Only where the two tables share values. 
! Join: An INNER JOIN – intersection of two tables. 
! Venn:
#MACURISA2014 
LEFT & RIGHT JOINs 
! ArcToolbox: called Update. 
! SQL: All records in Table A, along with some columns/ 
records from Table B. 
! Join: A LEFT JOIN – columns from B will contain NULL if 
there is no match. All records from A returned. (A RIGHT 
JOIN is just an easy way of writing the reverse.) 
! Venn: 
! Examples?
#MACURISA2014 
Symmetric Difference 
! ArcToolbox: returns a set where the geometries 
feature class A do not overlap feature class B. 
! SQL: Only where the two tables do not share 
values. 
! Join: An FULL JOIN, WHERE a.value <> b.value 
! Venn: 
! Examples?
#MACURISA2014 
Many types of Joins 
! INNER and OUTER (LEFT, RIGHT, FULL) 
! Different from Cartesian Product because some 
comparison value needs to be tested for truth. 
! Truth testing can be =, <>, <, > can also be the 
result of a function. 
! Spatial Joins in SQL: 
! ST_Intersects(a.shape, b.shape) 
! ST_Contains(a.shape, b.shape), ST_Within() 
! ST_Overlaps(a.shape, b.shape) 
! ST_Touches(a.shape, b.shape)
Let’s look at some spatial joins.
#MACURISA2014 
Fire Stations in Town 
! How can we calculate 
the number of fire 
stations within a 
municipality? 
! Can we find the most? 
! Can we find the least? 
! How about those towns 
with no fire stations? 
! How about those with a 
specific number of fire 
stations?
#MACURISA2014 
Fire Stations
#MACURISA2014 
Watch your groups!
#MACURISA2014 
Lowest Count… right?
#MACURISA2014 
Left Join on ST_Contains()
#MACURISA2014 
Aggregates in WHERE
#MACURISA2014 
Quick Subquery
#MACURISA2014 
Bus Routes 
! How can we find the towns 
that are along a given bus 
route? 
! How do we find the routes 
that cross through a town? 
! How do we find the towns 
without service? 
! bus.line = 553 
AND 
ST_Intersects( 
bus.shape, 
mun.shape)
#MACURISA2014 
Self-Joins 
! A table can be referenced 
twice in the same query. 
! How could we use this to 
generate a “neighbor” list? 
! How would we generate 
that list of towns? 
! FROM nj_munis m, 
njmunis x 
WHERE m.mun <> 
x.mun AND 
ST_Touches(m.shape 
, x.shape)
#MACURISA2014 
Denny's & La Quinta 
! Using SQL to remove 
the humor from jokes… 
SELECT d.city, d.state, 
ST_Transform(d.shape,2163) <-> 
ST_Transform(l.shape,2163) as 
distance 
FROM dennys d, laquinta l 
WHERE (ST_Transform(d.shape,2163) 
<-> ST_Transform(l.shape,2163)) 
< 150 
ORDER BY 3;
A Denny's between two 
La Quintas. 
Huntsville, Alabama
#MACURISA2014 
Power of SQL 
! Speed. 
! Flexibility. 
! Data integrity and control. 
! Automated reports as data changes. 
! Views and functions can help automate and 
streamline your GIS workflow. 
! A bit of a learning curve, but SQL is a standard 
and is supported and understood by a wide variety 
of applications and data stores.
#MACURISA2014 
More Info and Thanks! 
! John Reiser 
email: jreiser@njgeo.org 
twitter: @johnjreiser 
code: github.com/johnjreiser 
! Articles on New Jersey Geographer: 
http://njgeo.org/ 
! "Mitch Hedberg & GIS" (using PostgreSQL): 
http://njgeo.org/2014/01/30/mitch-hedberg-and-gis/

Weitere ähnliche Inhalte

Andere mochten auch

Getting your Data Out There: An Introduction to Distributed GIS
Getting your Data Out There:An Introduction to Distributed GISGetting your Data Out There:An Introduction to Distributed GIS
Getting your Data Out There: An Introduction to Distributed GISJohn Reiser
 
GIS & Facilities - NJAPPA Talk - April 26 2012
GIS & Facilities - NJAPPA Talk - April 26 2012GIS & Facilities - NJAPPA Talk - April 26 2012
GIS & Facilities - NJAPPA Talk - April 26 2012John Reiser
 
Using Dashboards to Understand Spatial Data
Using Dashboards to Understand Spatial DataUsing Dashboards to Understand Spatial Data
Using Dashboards to Understand Spatial DataJohn Reiser
 
Classification Systems
Classification SystemsClassification Systems
Classification SystemsJohn Reiser
 
Introduction to 3D Data
Introduction to 3D DataIntroduction to 3D Data
Introduction to 3D DataJohn Reiser
 
Network Analysis in ArcGIS
Network Analysis in ArcGISNetwork Analysis in ArcGIS
Network Analysis in ArcGISJohn Reiser
 
Data Models - GIS I
Data Models - GIS IData Models - GIS I
Data Models - GIS IJohn Reiser
 
Intro to GIS and Remote Sensing
Intro to GIS and Remote SensingIntro to GIS and Remote Sensing
Intro to GIS and Remote SensingJohn Reiser
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Beat Signer
 
Sql for Everything: GIS on the Web
Sql for Everything: GIS on the WebSql for Everything: GIS on the Web
Sql for Everything: GIS on the WebBill Morris
 
C-Si Module Manufacturers in India
C-Si Module Manufacturers in IndiaC-Si Module Manufacturers in India
C-Si Module Manufacturers in IndiaAkash Jauhari
 
New paradigm for national mapping organization
New paradigm for national mapping organizationNew paradigm for national mapping organization
New paradigm for national mapping organizationEsri India
 
The New Paradigm Towards Geo Enabled Economy
 The New Paradigm Towards Geo Enabled Economy The New Paradigm Towards Geo Enabled Economy
The New Paradigm Towards Geo Enabled EconomyEsri India
 
How culture can make or break a company
How culture can make or break a companyHow culture can make or break a company
How culture can make or break a companyAkash Jauhari
 
Are indian stock market driven more by sentiments than fundamentals- A Resear...
Are indian stock market driven more by sentiments than fundamentals- A Resear...Are indian stock market driven more by sentiments than fundamentals- A Resear...
Are indian stock market driven more by sentiments than fundamentals- A Resear...Akash Jauhari
 
Are Indian Stock driven by pure Sentiments
Are Indian Stock driven by pure SentimentsAre Indian Stock driven by pure Sentiments
Are Indian Stock driven by pure SentimentsAkash Jauhari
 

Andere mochten auch (17)

Getting your Data Out There: An Introduction to Distributed GIS
Getting your Data Out There:An Introduction to Distributed GISGetting your Data Out There:An Introduction to Distributed GIS
Getting your Data Out There: An Introduction to Distributed GIS
 
GIS & Facilities - NJAPPA Talk - April 26 2012
GIS & Facilities - NJAPPA Talk - April 26 2012GIS & Facilities - NJAPPA Talk - April 26 2012
GIS & Facilities - NJAPPA Talk - April 26 2012
 
GPS - Fall 2011
GPS - Fall 2011GPS - Fall 2011
GPS - Fall 2011
 
Using Dashboards to Understand Spatial Data
Using Dashboards to Understand Spatial DataUsing Dashboards to Understand Spatial Data
Using Dashboards to Understand Spatial Data
 
Classification Systems
Classification SystemsClassification Systems
Classification Systems
 
Introduction to 3D Data
Introduction to 3D DataIntroduction to 3D Data
Introduction to 3D Data
 
Network Analysis in ArcGIS
Network Analysis in ArcGISNetwork Analysis in ArcGIS
Network Analysis in ArcGIS
 
Data Models - GIS I
Data Models - GIS IData Models - GIS I
Data Models - GIS I
 
Intro to GIS and Remote Sensing
Intro to GIS and Remote SensingIntro to GIS and Remote Sensing
Intro to GIS and Remote Sensing
 
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
Structured Query Language (SQL) - Lecture 5 - Introduction to Databases (1007...
 
Sql for Everything: GIS on the Web
Sql for Everything: GIS on the WebSql for Everything: GIS on the Web
Sql for Everything: GIS on the Web
 
C-Si Module Manufacturers in India
C-Si Module Manufacturers in IndiaC-Si Module Manufacturers in India
C-Si Module Manufacturers in India
 
New paradigm for national mapping organization
New paradigm for national mapping organizationNew paradigm for national mapping organization
New paradigm for national mapping organization
 
The New Paradigm Towards Geo Enabled Economy
 The New Paradigm Towards Geo Enabled Economy The New Paradigm Towards Geo Enabled Economy
The New Paradigm Towards Geo Enabled Economy
 
How culture can make or break a company
How culture can make or break a companyHow culture can make or break a company
How culture can make or break a company
 
Are indian stock market driven more by sentiments than fundamentals- A Resear...
Are indian stock market driven more by sentiments than fundamentals- A Resear...Are indian stock market driven more by sentiments than fundamentals- A Resear...
Are indian stock market driven more by sentiments than fundamentals- A Resear...
 
Are Indian Stock driven by pure Sentiments
Are Indian Stock driven by pure SentimentsAre Indian Stock driven by pure Sentiments
Are Indian Stock driven by pure Sentiments
 

Ähnlich wie Doing more with SQL

DB2 Interview Questions - Part 1
DB2 Interview Questions - Part 1DB2 Interview Questions - Part 1
DB2 Interview Questions - Part 1ReKruiTIn.com
 
Strata 2014: Design Challenges for Real Predictive Platforms
Strata 2014: Design Challenges for Real Predictive Platforms Strata 2014: Design Challenges for Real Predictive Platforms
Strata 2014: Design Challenges for Real Predictive Platforms Max Gasner
 
Bt0075 rdbms with mysql 1
Bt0075 rdbms with mysql 1Bt0075 rdbms with mysql 1
Bt0075 rdbms with mysql 1Techglyphs
 
ORACLE PL/SQL TUTORIALS - OVERVIEW - SQL COMMANDS
ORACLE PL/SQL TUTORIALS - OVERVIEW - SQL COMMANDSORACLE PL/SQL TUTORIALS - OVERVIEW - SQL COMMANDS
ORACLE PL/SQL TUTORIALS - OVERVIEW - SQL COMMANDSNewyorksys.com
 
Structure Query Language (SQL).pptx
Structure Query Language (SQL).pptxStructure Query Language (SQL).pptx
Structure Query Language (SQL).pptxNalinaKumari2
 
SQL Interview Questions For Experienced
SQL Interview Questions For ExperiencedSQL Interview Questions For Experienced
SQL Interview Questions For Experiencedzynofustechnology
 
Excel Tutorials - VLOOKUP and HLOOKUP Functions
Excel Tutorials - VLOOKUP and HLOOKUP FunctionsExcel Tutorials - VLOOKUP and HLOOKUP Functions
Excel Tutorials - VLOOKUP and HLOOKUP FunctionsMerve Nur Taş
 
Steps towards of sql server developer
Steps towards of sql server developerSteps towards of sql server developer
Steps towards of sql server developerAhsan Kabir
 
Structure query language (sql)
Structure query language (sql)Structure query language (sql)
Structure query language (sql)Nalina Kumari
 
ITT PROJECT IN EXCEL AND WORD
ITT PROJECT IN EXCEL AND WORDITT PROJECT IN EXCEL AND WORD
ITT PROJECT IN EXCEL AND WORDAVIRAL161
 
Real-time Data De-duplication using Locality-sensitive Hashing powered by Sto...
Real-time Data De-duplication using Locality-sensitive Hashing powered by Sto...Real-time Data De-duplication using Locality-sensitive Hashing powered by Sto...
Real-time Data De-duplication using Locality-sensitive Hashing powered by Sto...DECK36
 
ISOT Presentation.pptx
ISOT Presentation.pptxISOT Presentation.pptx
ISOT Presentation.pptxsirtBhopal1
 
Excel Introductory lesson.pptx
Excel Introductory lesson.pptxExcel Introductory lesson.pptx
Excel Introductory lesson.pptxGeeth Wihanga
 
GROUP-4-Database-Connectivity-with-MySqL.pptx
GROUP-4-Database-Connectivity-with-MySqL.pptxGROUP-4-Database-Connectivity-with-MySqL.pptx
GROUP-4-Database-Connectivity-with-MySqL.pptxJohnLhoydMaderable
 
A "M"ind Bending Experience. Power Query for Power BI and Beyond.
A "M"ind Bending Experience. Power Query for Power BI and Beyond.A "M"ind Bending Experience. Power Query for Power BI and Beyond.
A "M"ind Bending Experience. Power Query for Power BI and Beyond.Alex Powers
 

Ähnlich wie Doing more with SQL (20)

SQL cheat sheet.pdf
SQL cheat sheet.pdfSQL cheat sheet.pdf
SQL cheat sheet.pdf
 
DB2 Interview Questions - Part 1
DB2 Interview Questions - Part 1DB2 Interview Questions - Part 1
DB2 Interview Questions - Part 1
 
Strata 2014: Design Challenges for Real Predictive Platforms
Strata 2014: Design Challenges for Real Predictive Platforms Strata 2014: Design Challenges for Real Predictive Platforms
Strata 2014: Design Challenges for Real Predictive Platforms
 
Bt0075 rdbms with mysql 1
Bt0075 rdbms with mysql 1Bt0075 rdbms with mysql 1
Bt0075 rdbms with mysql 1
 
DataStructures
DataStructuresDataStructures
DataStructures
 
ORACLE PL/SQL TUTORIALS - OVERVIEW - SQL COMMANDS
ORACLE PL/SQL TUTORIALS - OVERVIEW - SQL COMMANDSORACLE PL/SQL TUTORIALS - OVERVIEW - SQL COMMANDS
ORACLE PL/SQL TUTORIALS - OVERVIEW - SQL COMMANDS
 
Structure Query Language (SQL).pptx
Structure Query Language (SQL).pptxStructure Query Language (SQL).pptx
Structure Query Language (SQL).pptx
 
SQL Interview Questions For Experienced
SQL Interview Questions For ExperiencedSQL Interview Questions For Experienced
SQL Interview Questions For Experienced
 
Excel Tutorials - VLOOKUP and HLOOKUP Functions
Excel Tutorials - VLOOKUP and HLOOKUP FunctionsExcel Tutorials - VLOOKUP and HLOOKUP Functions
Excel Tutorials - VLOOKUP and HLOOKUP Functions
 
Sql basics
Sql  basicsSql  basics
Sql basics
 
Steps towards of sql server developer
Steps towards of sql server developerSteps towards of sql server developer
Steps towards of sql server developer
 
Structure query language (sql)
Structure query language (sql)Structure query language (sql)
Structure query language (sql)
 
ITT PROJECT IN EXCEL AND WORD
ITT PROJECT IN EXCEL AND WORDITT PROJECT IN EXCEL AND WORD
ITT PROJECT IN EXCEL AND WORD
 
Real-time Data De-duplication using Locality-sensitive Hashing powered by Sto...
Real-time Data De-duplication using Locality-sensitive Hashing powered by Sto...Real-time Data De-duplication using Locality-sensitive Hashing powered by Sto...
Real-time Data De-duplication using Locality-sensitive Hashing powered by Sto...
 
Sql
SqlSql
Sql
 
ISOT Presentation.pptx
ISOT Presentation.pptxISOT Presentation.pptx
ISOT Presentation.pptx
 
Excel Introductory lesson.pptx
Excel Introductory lesson.pptxExcel Introductory lesson.pptx
Excel Introductory lesson.pptx
 
GROUP-4-Database-Connectivity-with-MySqL.pptx
GROUP-4-Database-Connectivity-with-MySqL.pptxGROUP-4-Database-Connectivity-with-MySqL.pptx
GROUP-4-Database-Connectivity-with-MySqL.pptx
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
A "M"ind Bending Experience. Power Query for Power BI and Beyond.
A "M"ind Bending Experience. Power Query for Power BI and Beyond.A "M"ind Bending Experience. Power Query for Power BI and Beyond.
A "M"ind Bending Experience. Power Query for Power BI and Beyond.
 

Mehr von John Reiser

Python and GIS: Improving Your Workflow
Python and GIS: Improving Your WorkflowPython and GIS: Improving Your Workflow
Python and GIS: Improving Your WorkflowJohn Reiser
 
Python Programming and GIS
Python Programming and GISPython Programming and GIS
Python Programming and GISJohn Reiser
 
Portfolio Workshop
Portfolio WorkshopPortfolio Workshop
Portfolio WorkshopJohn Reiser
 
GIS Day at BCC 2012
GIS Day at BCC 2012GIS Day at BCC 2012
GIS Day at BCC 2012John Reiser
 
New Jersey Land Change Viewer
New Jersey Land Change ViewerNew Jersey Land Change Viewer
New Jersey Land Change ViewerJohn Reiser
 
Measurement and Scale
Measurement and ScaleMeasurement and Scale
Measurement and ScaleJohn Reiser
 
Data Storage and Processing
Data Storage and ProcessingData Storage and Processing
Data Storage and ProcessingJohn Reiser
 
IMGIS - Brief History of Mapping
IMGIS - Brief History of MappingIMGIS - Brief History of Mapping
IMGIS - Brief History of MappingJohn Reiser
 
Internet-enabled GIS - Spring 2011
Internet-enabled GIS - Spring 2011Internet-enabled GIS - Spring 2011
Internet-enabled GIS - Spring 2011John Reiser
 
Internet-enabled GIS for Planners
Internet-enabled GIS for PlannersInternet-enabled GIS for Planners
Internet-enabled GIS for PlannersJohn Reiser
 

Mehr von John Reiser (15)

Python and GIS: Improving Your Workflow
Python and GIS: Improving Your WorkflowPython and GIS: Improving Your Workflow
Python and GIS: Improving Your Workflow
 
Python Programming and GIS
Python Programming and GISPython Programming and GIS
Python Programming and GIS
 
Portfolio Workshop
Portfolio WorkshopPortfolio Workshop
Portfolio Workshop
 
GIS Day at BCC 2012
GIS Day at BCC 2012GIS Day at BCC 2012
GIS Day at BCC 2012
 
Mapping the Way
Mapping the WayMapping the Way
Mapping the Way
 
New Jersey Land Change Viewer
New Jersey Land Change ViewerNew Jersey Land Change Viewer
New Jersey Land Change Viewer
 
Measurement and Scale
Measurement and ScaleMeasurement and Scale
Measurement and Scale
 
Map Projections
Map ProjectionsMap Projections
Map Projections
 
Geodatabases
GeodatabasesGeodatabases
Geodatabases
 
GIS Modeling
GIS ModelingGIS Modeling
GIS Modeling
 
Data Storage and Processing
Data Storage and ProcessingData Storage and Processing
Data Storage and Processing
 
GIS Data Types
GIS Data TypesGIS Data Types
GIS Data Types
 
IMGIS - Brief History of Mapping
IMGIS - Brief History of MappingIMGIS - Brief History of Mapping
IMGIS - Brief History of Mapping
 
Internet-enabled GIS - Spring 2011
Internet-enabled GIS - Spring 2011Internet-enabled GIS - Spring 2011
Internet-enabled GIS - Spring 2011
 
Internet-enabled GIS for Planners
Internet-enabled GIS for PlannersInternet-enabled GIS for Planners
Internet-enabled GIS for Planners
 

Kürzlich hochgeladen

Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Association for Project Management
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17Celine George
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxkarenfajardo43
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptxmary850239
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdfMr Bounab Samir
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management SystemChristalin Nelson
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfJemuel Francisco
 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptxJonalynLegaspi2
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...DhatriParmar
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxVanesaIglesias10
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxlancelewisportillo
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQuiz Club NITW
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleCeline George
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptxDhatriParmar
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxDhatriParmar
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfPrerana Jadhav
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operationalssuser3e220a
 

Kürzlich hochgeladen (20)

Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
Team Lead Succeed – Helping you and your team achieve high-performance teamwo...
 
How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17How to Fix XML SyntaxError in Odoo the 17
How to Fix XML SyntaxError in Odoo the 17
 
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptxGrade Three -ELLNA-REVIEWER-ENGLISH.pptx
Grade Three -ELLNA-REVIEWER-ENGLISH.pptx
 
4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx4.11.24 Poverty and Inequality in America.pptx
4.11.24 Poverty and Inequality in America.pptx
 
MS4 level being good citizen -imperative- (1) (1).pdf
MS4 level   being good citizen -imperative- (1) (1).pdfMS4 level   being good citizen -imperative- (1) (1).pdf
MS4 level being good citizen -imperative- (1) (1).pdf
 
Transaction Management in Database Management System
Transaction Management in Database Management SystemTransaction Management in Database Management System
Transaction Management in Database Management System
 
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdfGrade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
Grade 9 Quarter 4 Dll Grade 9 Quarter 4 DLL.pdf
 
week 1 cookery 8 fourth - quarter .pptx
week 1 cookery 8  fourth  -  quarter .pptxweek 1 cookery 8  fourth  -  quarter .pptx
week 1 cookery 8 fourth - quarter .pptx
 
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
Blowin' in the Wind of Caste_ Bob Dylan's Song as a Catalyst for Social Justi...
 
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptxINCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
INCLUSIVE EDUCATION PRACTICES FOR TEACHERS AND TRAINERS.pptx
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
ROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptxROLES IN A STAGE PRODUCTION in arts.pptx
ROLES IN A STAGE PRODUCTION in arts.pptx
 
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptxQ4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
Q4-PPT-Music9_Lesson-1-Romantic-Opera.pptx
 
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITWQ-Factor General Quiz-7th April 2024, Quiz Club NITW
Q-Factor General Quiz-7th April 2024, Quiz Club NITW
 
Multi Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP ModuleMulti Domain Alias In the Odoo 17 ERP Module
Multi Domain Alias In the Odoo 17 ERP Module
 
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
Unraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptxUnraveling Hypertext_ Analyzing  Postmodern Elements in  Literature.pptx
Unraveling Hypertext_ Analyzing Postmodern Elements in Literature.pptx
 
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptxMan or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
Man or Manufactured_ Redefining Humanity Through Biopunk Narratives.pptx
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdf
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
Expanded definition: technical and operational
Expanded definition: technical and operationalExpanded definition: technical and operational
Expanded definition: technical and operational
 

Doing more with SQL

  • 1. DOING MORE WITH SQL John Reiser MAC URISA 2014
  • 2. #MACURISA2014 DBMS Systems ! Many of the modern DBMSs support spatial data. ! Oracle, MS SQL, PostgreSQL are most often used. ! PostgreSQL is ! open source/free to use and modify ! incredibly reliable, extensible, powerful ! provides spatial capabilities through PostGIS ! DBMSs allow for “enterprise” functionality, like multiple users/concurrency, high output, etc.
  • 3. #MACURISA2014 Structured Query Language ! SQL is the standardized method of interacting with a database ! Even Access allows you to use SQL ! Common, hopefully familiar, statements: ! Select (read from database) ! Insert (new records into a DBMS) ! Update (existing records in DBMS) ! Delete (remove records from DBMS) ! Where (limits your results)
  • 4. #MACURISA2014 Select Statements ! Most common SQL query you will encounter ! “Select By Attributes” has this as the foundation ! Nothing more than “SELECT * FROM gis_layer WHERE…”
  • 5.
  • 6. #MACURISA2014 Joins ! In ArcGIS or Access, you join two (or more) tables together using a primary key. ! If the keys match, the secondary tables are tacked on to the first ! Again, geospatial is special, so GIS has another type of join
  • 7. #MACURISA2014 Combining Tables ! The simplest combination of two tables would be to combine each record from table A with each record from table B. ! The Cartesian Product. ! Example: A has 2 records, B has 3. ! A ✕ B: {(A1, B1), (A1, B2), (A1, B3), (A2, B1), (A2, B2), (A2, B3)} ! Let’s take a deck of cards as an example.
  • 8.
  • 9.
  • 10. #MACURISA2014 Joins ! Think of a Join as limiting the Cartesian Product of two tables down to just the specific records desired. ! The manner in which you form your SELECT … JOIN will be important: ! Ensure the desired records and columns are returned. ! Speed of the JOIN performed.
  • 11. #MACURISA2014 Spatial Joins ! Relationship not determined by key, but by proximity or connectivity ! Contains/Within/Overlaps ! One feature falls entirely within another ! Touches/Intersects/Crosses ! One feature touches another ! Equals or Disjoint
  • 12. #MACURISA2014 Set Theory ! General terms first, because these concepts are used across GIS and not just in SQL. ! Union ! Intersection ! Relative Complement ! Symmetric Difference ! Terms should be somewhat familiar…
  • 13. #MACURISA2014 Union ! ArcToolbox: returns a set where all features are returned, however new features created where they intersect. ! SQL: Set of all values from both tables. ! Join: An FULL JOIN – all values from two tables, with NULL values where there are not shared values. ! Venn:
  • 14. #MACURISA2014 Unions are not Cartesian ! Union / FULL JOIN will leave NULLs where there are not matches across tables. All records will be returned, however the records will not be “shuffled” together like the cards example. ! FULL JOINs still require a WHERE or ON predicate to create the join.
  • 15. #MACURISA2014 Example of Cartesian vs FULL ! From Wikipedia:
  • 18. #MACURISA2014 Intersection ! ArcToolbox: returns a set where the geometries of two different feature classes overlap. ! SQL: Only where the two tables share values. ! Join: An INNER JOIN – intersection of two tables. ! Venn:
  • 19. #MACURISA2014 LEFT & RIGHT JOINs ! ArcToolbox: called Update. ! SQL: All records in Table A, along with some columns/ records from Table B. ! Join: A LEFT JOIN – columns from B will contain NULL if there is no match. All records from A returned. (A RIGHT JOIN is just an easy way of writing the reverse.) ! Venn: ! Examples?
  • 20. #MACURISA2014 Symmetric Difference ! ArcToolbox: returns a set where the geometries feature class A do not overlap feature class B. ! SQL: Only where the two tables do not share values. ! Join: An FULL JOIN, WHERE a.value <> b.value ! Venn: ! Examples?
  • 21. #MACURISA2014 Many types of Joins ! INNER and OUTER (LEFT, RIGHT, FULL) ! Different from Cartesian Product because some comparison value needs to be tested for truth. ! Truth testing can be =, <>, <, > can also be the result of a function. ! Spatial Joins in SQL: ! ST_Intersects(a.shape, b.shape) ! ST_Contains(a.shape, b.shape), ST_Within() ! ST_Overlaps(a.shape, b.shape) ! ST_Touches(a.shape, b.shape)
  • 22. Let’s look at some spatial joins.
  • 23. #MACURISA2014 Fire Stations in Town ! How can we calculate the number of fire stations within a municipality? ! Can we find the most? ! Can we find the least? ! How about those towns with no fire stations? ! How about those with a specific number of fire stations?
  • 27. #MACURISA2014 Left Join on ST_Contains()
  • 30. #MACURISA2014 Bus Routes ! How can we find the towns that are along a given bus route? ! How do we find the routes that cross through a town? ! How do we find the towns without service? ! bus.line = 553 AND ST_Intersects( bus.shape, mun.shape)
  • 31. #MACURISA2014 Self-Joins ! A table can be referenced twice in the same query. ! How could we use this to generate a “neighbor” list? ! How would we generate that list of towns? ! FROM nj_munis m, njmunis x WHERE m.mun <> x.mun AND ST_Touches(m.shape , x.shape)
  • 32. #MACURISA2014 Denny's & La Quinta ! Using SQL to remove the humor from jokes… SELECT d.city, d.state, ST_Transform(d.shape,2163) <-> ST_Transform(l.shape,2163) as distance FROM dennys d, laquinta l WHERE (ST_Transform(d.shape,2163) <-> ST_Transform(l.shape,2163)) < 150 ORDER BY 3;
  • 33. A Denny's between two La Quintas. Huntsville, Alabama
  • 34. #MACURISA2014 Power of SQL ! Speed. ! Flexibility. ! Data integrity and control. ! Automated reports as data changes. ! Views and functions can help automate and streamline your GIS workflow. ! A bit of a learning curve, but SQL is a standard and is supported and understood by a wide variety of applications and data stores.
  • 35. #MACURISA2014 More Info and Thanks! ! John Reiser email: jreiser@njgeo.org twitter: @johnjreiser code: github.com/johnjreiser ! Articles on New Jersey Geographer: http://njgeo.org/ ! "Mitch Hedberg & GIS" (using PostgreSQL): http://njgeo.org/2014/01/30/mitch-hedberg-and-gis/