SlideShare a Scribd company logo
Welcome 
MapInfo User Conference 2014: GIS Gets Personal 
#MapInfoUC
Hands on Lab 
13D Advanced SQL Selects 
Peter Horsbøll Møller 
GIS/LI Pre-Sales Specialist 
June 13, 2014 
Every connection is a new opportunity™ 
MapInfo User Conference 2014: GIS Gets Personal 
#MapInfoUC
MapInfo User Conference 2014: GIS Gets Personal 
#MapInfoUC 
Advanced 
SQL Selects 
Practice calculating 
distances, object lengths 
and other geographic 
operations in SQL. 
Learn how to use Sub-selects 
and other advanced 
features.
Geographic Measurements 
MapBasic functions 
• Area(OBJ, ”units”) 
• ObjectLen(OBJ, ”units”) 
• Perimeter(OBJ, ”units”) 
• They also exist as Cartesian- & Spherical- versions 
• Units: ”m” 
MapInfo User Conference 2014: GIS Gets Personal 
#MapInfoUC 
”km” 
”in” 
”ft” 
”mi” 
... 
”sq m” 
”sq km” 
”hectare” 
”sq ft” 
”sq mi” 
...
MapInfo User Conference 2014: GIS Gets Personal 
#MapInfoUC 
Exercise 
Data sets 
•USStates.tab 
•USUS_HIWay.tab 
•Calculate the area of each state 
•Calculate the perimeter of each state 
•Calculate the length of each highway
Aggregations and Grouping 
With the aggregations you can extract statistical 
information from a number of records, such as Sum, 
Average and Minimum or Maximum values 
The aggregations often take a column as parameter. 
Count(*), however, just takes a * 
If you use an aggregation you’ll get just one row in the 
result, unless you specify a column to group the result by 
MapInfo User Conference 2014: GIS Gets Personal 
#MapInfoUC
MapInfo User Conference 2014: GIS Gets Personal 
#MapInfoUC 
Exercise 
Data sets 
•USStates.tab 
•USUS_HIWay.tab 
•Calculate the total area of all states 
•Calculate the total area of the selected states 
•Calculate the total length of the selected highways
MapInfo User Conference 2014: GIS Gets Personal 
#MapInfoUC 
Joining Tables 
When joining two tables thru a Select statement you need 
to specify a join condition 
This can be a alfanumerical join: 
• TABLE1.ID = TABLE2.ID 
or a spatial join: 
• TABLE1.OBJ Intersects TABLE2.OBJ 
The spatial object is taken from the first table in the join 
statement
MapInfo User Conference 2014: GIS Gets Personal 
#MapInfoUC 
Exercise 
Data sets 
•USStates.tab 
•USUS_HIWay.tab 
•Find the spatial join between highways and states, that is 
which states does the highways intersect? 
•How much of each highway (in miles) is within the 
individual states?
MapInfo User Conference 2014: GIS Gets Personal 
#MapInfoUC 
Sub Selections 
A Sub Selection returns a value or a list of values that can 
compared to bojects or alfanumerical values 
A sub select has this structure: 
Select * From TABLE1 Where COLUMN1 
In (Select COLUMN1 From TABLE2) 
Or 
Select * From TABLE1 Where OBJ Intersects 
Any (Select OBJ From TABLE2)
MapInfo User Conference 2014: GIS Gets Personal 
#MapInfoUC 
Exercise 
Data sets 
•USStates.tab 
•USUS_HIWay.tab 
•Find the states that has one or more highways crossing 
•Find the states that has no highways crossing
Measuring Distance 
MapBasic functions 
• Distance(xFrom, yFrom, xTo, yTo, ”units”) 
• Exists also as Cartesian- & Spherical- versions 
• Format$() 
• Can be used to forse a larger number of decimals: 
Format$(numeric_value, ”#.######”) 
• CentroidX(object) / CentroidY(object) 
• Extracts coordinates from the centroid of an object 
MapInfo User Conference 2014: GIS Gets Personal 
#MapInfoUC
MapInfo User Conference 2014: GIS Gets Personal 
#MapInfoUC 
Exercise 
Data sets 
•USStates.tab 
•USUS_HIWay.tab 
•USSTATECAP.tab 
•Find the distance from every state capital to Washington 
•Find the distance from every state capital to Nashville
MapInfo User Conference 2014: GIS Gets Personal 
#MapInfoUC 
Solutions 
1 Select State_Name 
, Area(obj, "sq mi") "Area sq miles" 
from STATES into Selection 
2 Select State_Name 
, Area(obj, "sq mi") "Area sq miles" 
, Perimeter(obj, "mi") "Perimeter miles" 
from STATES into Selection 
3 Select Highway 
, ObjectLen(obj, "mi") “Length miles” 
from US_HIWAY into Selection 
4 Select Sum(Area(obj, "sq mi")) "Area sq miles" 
from STATES into Selection
MapInfo User Conference 2014: GIS Gets Personal 
#MapInfoUC 
Solutions 
5 Select Sum(Area(obj, "sq mi")) "Area sq miles" 
from Selection into __SUM 
6 Select Sum(ObjectLen(obj, "mi")) “Length miles” 
from Selection into __SUM 
7 Select US_HIWAY.Highway, STATES.State_Name 
from US_HIWAY, STATES 
where US_HIWAY.Obj Intersects STATES.Obj 
order by US_HIWAY.Highway, STATES.State_Name 
into Selection
MapInfo User Conference 2014: GIS Gets Personal 
#MapInfoUC 
Solutions 
8 Select US_HIWAY.Highway, STATES.State_Name 
, ObjectLen(Overlap(US_HIWAY.Obj, STATES.Obj), "mi") "Length Miles" 
from US_HIWAY, STATES 
where US_HIWAY.Obj Intersects STATES.Obj 
order by US_HIWAY.Highway, STATES.State_Name 
into Selection 
9 Select State_Name 
from STATES 
where OBJ Intersects Any (Select OBJ From US_HIWAY) 
order by State_Name 
into Selection
MapInfo User Conference 2014: GIS Gets Personal 
#MapInfoUC 
Solutions 
10 Select State_Name 
from STATES 
where not OBJ Intersects Any (Select OBJ From US_HIWAY) 
order by State_Name 
into Selection
MapInfo User Conference 2014: GIS Gets Personal 
#MapInfoUC 
Solutions 
11 Set CoordSys Table STATECAP 
‘Select Washinton 
Fetch First From Selection 
Print Format$(CentroidX(Selection.obj), "#.######") 
+ ", " + Format$(CentroidY(Selection.obj), "#.######") 
Select Capital, State 
, Distance(-77.016167, 38.90505, CentroidX(OBJ), CentroidY(OBJ), "mi") 
"Distance To Washington" 
from STATECAP into Selection
Get the latest 
MapInfo User Conference news: 
Twitter via #MapInfoUC 
and follow us @MapInfo 
MapInfo User Conference 2014: GIS Gets Personal 
#MapInfoUC

More Related Content

PPT
Automating Repetitive Tasks with MapBasic
PPT
Taking Advantage of a Spatial Database with MapInfo Professional
PPTX
MapInfo Pro v2019: Improving the Way You Query
PPTX
MapInfo Professional 12.0 and SQL Server 2008
PPTX
The power of spatial SQL in MapInfo Professional
PDF
Precisely MapInfo Pro v2019 and Roadmap
PPTX
Muguki session on MapInfo Professional 11 and SQL Server 2008
PDF
Be Location Intelligent with MapInfo Pro v2019
Automating Repetitive Tasks with MapBasic
Taking Advantage of a Spatial Database with MapInfo Professional
MapInfo Pro v2019: Improving the Way You Query
MapInfo Professional 12.0 and SQL Server 2008
The power of spatial SQL in MapInfo Professional
Precisely MapInfo Pro v2019 and Roadmap
Muguki session on MapInfo Professional 11 and SQL Server 2008
Be Location Intelligent with MapInfo Pro v2019

What's hot (20)

PPTX
Using Spectrum on Demand from MapInfo Pro
PPTX
GEOPROCESSING IN QGIS
PDF
Nycct GIS_primer tutorial
PDF
QGIS Tutorial 1
PDF
QGIS Module 2
PDF
QGIS training class 1
PPTX
The strength of a spatial database
PDF
QGIS Module 4
PPT
Where2.0Now - Finding the heat in Thematic Maps
PDF
QGIS Tutorial 2
PPT
MapInfo Discover 3D: From 2D to 3D
PPTX
All the New Cool Stuff in QGIS 2.0
PPTX
Introduction to Tools in ArcGIS
PDF
Arc catalog introduction
PPTX
MapInfo Professional 12.5 and Discover3D 2014 - A brief overview
PDF
QGIS Module 3
PPTX
Hive query optimization infinity
PPTX
Spot db consistency checking and optimization in spatial database
PDF
QGIS training
PDF
Spatial query tutorial for nyc subway income level along subway
Using Spectrum on Demand from MapInfo Pro
GEOPROCESSING IN QGIS
Nycct GIS_primer tutorial
QGIS Tutorial 1
QGIS Module 2
QGIS training class 1
The strength of a spatial database
QGIS Module 4
Where2.0Now - Finding the heat in Thematic Maps
QGIS Tutorial 2
MapInfo Discover 3D: From 2D to 3D
All the New Cool Stuff in QGIS 2.0
Introduction to Tools in ArcGIS
Arc catalog introduction
MapInfo Professional 12.5 and Discover3D 2014 - A brief overview
QGIS Module 3
Hive query optimization infinity
Spot db consistency checking and optimization in spatial database
QGIS training
Spatial query tutorial for nyc subway income level along subway
Ad

Similar to Advanced SQL Selects (20)

PDF
Doing more with SQL
ODP
MySQL and GIS Programming
PPTX
Geek Sync | Having Fun with Spatial Data
PPT
Exercise 6
PPTX
Spatial Data Analysis .pptx by Ms. Kritiza Sharma
PPTX
M|18 Building Location-Based Services with Geospatial Data
PPTX
Sql Server 2008 Spatial Analysis
PDF
Spatial query on vanilla databases
PPTX
Review presentation for Orientation 2014
PDF
Introducción a GeoAnalytics
PPTX
MAPINFO PROJECT
PDF
3 Spatial query spatial query spatial query.pdf
PPTX
Merging statistics and geospatial information - demography / commuting / spat...
PDF
A Whirlwind Tour of Spatial Joins
PPTX
GIS: A project by project prospective
PPTX
GIS: A project by project prospective
PDF
SAGT Conference 2016 - Teaching Census through GIS
PPT
Exercise 8
PPT
remote sesing resolution for satelitte imag
PDF
Geographical Data Management for Web Applications
Doing more with SQL
MySQL and GIS Programming
Geek Sync | Having Fun with Spatial Data
Exercise 6
Spatial Data Analysis .pptx by Ms. Kritiza Sharma
M|18 Building Location-Based Services with Geospatial Data
Sql Server 2008 Spatial Analysis
Spatial query on vanilla databases
Review presentation for Orientation 2014
Introducción a GeoAnalytics
MAPINFO PROJECT
3 Spatial query spatial query spatial query.pdf
Merging statistics and geospatial information - demography / commuting / spat...
A Whirlwind Tour of Spatial Joins
GIS: A project by project prospective
GIS: A project by project prospective
SAGT Conference 2016 - Teaching Census through GIS
Exercise 8
remote sesing resolution for satelitte imag
Geographical Data Management for Web Applications
Ad

More from Peter Horsbøll Møller (20)

PDF
Using Precisely Locate API Services in MapInfo Pro
PDF
MapInfo Pro v12.5 to v2021.1 Overview
PDF
MapInfo Pro Tips & Tricks med Geograf
PDF
Introduction to MapBasic
PPTX
Eksklusivsmagning - 10 års jubilæum, Oksenvad Whiskylaug
PPTX
Llinking Spectrum dataflows to MapInfo Pro
PPTX
Clynelish - Oksenvad Whiskylaug
PPTX
Getting Started with the Ribbon library - MUGUKI User Group Meeting 2016
PPTX
Whiskysmagning: Samaroli
PPTX
Hvad sker der hos Pitney Bowes
PPTX
MapInfo Discover 2015.2 64 bit
PPTX
MapInfo Pro 64 bit og MapInfo Pro Advanced 64 bit
PPTX
MapInfo Pro Raster og de danske højdedata
PPTX
64 bits of MapInfo Pro - Danish version
PPTX
Blend, Single Grain og Single Malt Whisky
PPTX
MapInfo Pro og SQL Server - Uden opgaver
PPTX
Nyheder i MapInfo Pro 12.5 Dansk 32 bit
PPTX
The Macallan - Oksenvad Whiskylaug
PPTX
WMS, WFS og alle deres venner
PPTX
Hvad påvirker en whisky
Using Precisely Locate API Services in MapInfo Pro
MapInfo Pro v12.5 to v2021.1 Overview
MapInfo Pro Tips & Tricks med Geograf
Introduction to MapBasic
Eksklusivsmagning - 10 års jubilæum, Oksenvad Whiskylaug
Llinking Spectrum dataflows to MapInfo Pro
Clynelish - Oksenvad Whiskylaug
Getting Started with the Ribbon library - MUGUKI User Group Meeting 2016
Whiskysmagning: Samaroli
Hvad sker der hos Pitney Bowes
MapInfo Discover 2015.2 64 bit
MapInfo Pro 64 bit og MapInfo Pro Advanced 64 bit
MapInfo Pro Raster og de danske højdedata
64 bits of MapInfo Pro - Danish version
Blend, Single Grain og Single Malt Whisky
MapInfo Pro og SQL Server - Uden opgaver
Nyheder i MapInfo Pro 12.5 Dansk 32 bit
The Macallan - Oksenvad Whiskylaug
WMS, WFS og alle deres venner
Hvad påvirker en whisky

Recently uploaded (20)

PPTX
Tartificialntelligence_presentation.pptx
PDF
Univ-Connecticut-ChatGPT-Presentaion.pdf
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
Unlocking AI with Model Context Protocol (MCP)
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PPTX
Machine Learning_overview_presentation.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Approach and Philosophy of On baking technology
PDF
Mushroom cultivation and it's methods.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Encapsulation_ Review paper, used for researhc scholars
Tartificialntelligence_presentation.pptx
Univ-Connecticut-ChatGPT-Presentaion.pdf
Network Security Unit 5.pdf for BCA BBA.
Unlocking AI with Model Context Protocol (MCP)
Digital-Transformation-Roadmap-for-Companies.pptx
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Machine Learning_overview_presentation.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Reach Out and Touch Someone: Haptics and Empathic Computing
A comparative analysis of optical character recognition models for extracting...
Accuracy of neural networks in brain wave diagnosis of schizophrenia
A comparative study of natural language inference in Swahili using monolingua...
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Approach and Philosophy of On baking technology
Mushroom cultivation and it's methods.pdf
NewMind AI Weekly Chronicles - August'25-Week II
Diabetes mellitus diagnosis method based random forest with bat algorithm
Encapsulation_ Review paper, used for researhc scholars

Advanced SQL Selects

  • 1. Welcome MapInfo User Conference 2014: GIS Gets Personal #MapInfoUC
  • 2. Hands on Lab 13D Advanced SQL Selects Peter Horsbøll Møller GIS/LI Pre-Sales Specialist June 13, 2014 Every connection is a new opportunity™ MapInfo User Conference 2014: GIS Gets Personal #MapInfoUC
  • 3. MapInfo User Conference 2014: GIS Gets Personal #MapInfoUC Advanced SQL Selects Practice calculating distances, object lengths and other geographic operations in SQL. Learn how to use Sub-selects and other advanced features.
  • 4. Geographic Measurements MapBasic functions • Area(OBJ, ”units”) • ObjectLen(OBJ, ”units”) • Perimeter(OBJ, ”units”) • They also exist as Cartesian- & Spherical- versions • Units: ”m” MapInfo User Conference 2014: GIS Gets Personal #MapInfoUC ”km” ”in” ”ft” ”mi” ... ”sq m” ”sq km” ”hectare” ”sq ft” ”sq mi” ...
  • 5. MapInfo User Conference 2014: GIS Gets Personal #MapInfoUC Exercise Data sets •USStates.tab •USUS_HIWay.tab •Calculate the area of each state •Calculate the perimeter of each state •Calculate the length of each highway
  • 6. Aggregations and Grouping With the aggregations you can extract statistical information from a number of records, such as Sum, Average and Minimum or Maximum values The aggregations often take a column as parameter. Count(*), however, just takes a * If you use an aggregation you’ll get just one row in the result, unless you specify a column to group the result by MapInfo User Conference 2014: GIS Gets Personal #MapInfoUC
  • 7. MapInfo User Conference 2014: GIS Gets Personal #MapInfoUC Exercise Data sets •USStates.tab •USUS_HIWay.tab •Calculate the total area of all states •Calculate the total area of the selected states •Calculate the total length of the selected highways
  • 8. MapInfo User Conference 2014: GIS Gets Personal #MapInfoUC Joining Tables When joining two tables thru a Select statement you need to specify a join condition This can be a alfanumerical join: • TABLE1.ID = TABLE2.ID or a spatial join: • TABLE1.OBJ Intersects TABLE2.OBJ The spatial object is taken from the first table in the join statement
  • 9. MapInfo User Conference 2014: GIS Gets Personal #MapInfoUC Exercise Data sets •USStates.tab •USUS_HIWay.tab •Find the spatial join between highways and states, that is which states does the highways intersect? •How much of each highway (in miles) is within the individual states?
  • 10. MapInfo User Conference 2014: GIS Gets Personal #MapInfoUC Sub Selections A Sub Selection returns a value or a list of values that can compared to bojects or alfanumerical values A sub select has this structure: Select * From TABLE1 Where COLUMN1 In (Select COLUMN1 From TABLE2) Or Select * From TABLE1 Where OBJ Intersects Any (Select OBJ From TABLE2)
  • 11. MapInfo User Conference 2014: GIS Gets Personal #MapInfoUC Exercise Data sets •USStates.tab •USUS_HIWay.tab •Find the states that has one or more highways crossing •Find the states that has no highways crossing
  • 12. Measuring Distance MapBasic functions • Distance(xFrom, yFrom, xTo, yTo, ”units”) • Exists also as Cartesian- & Spherical- versions • Format$() • Can be used to forse a larger number of decimals: Format$(numeric_value, ”#.######”) • CentroidX(object) / CentroidY(object) • Extracts coordinates from the centroid of an object MapInfo User Conference 2014: GIS Gets Personal #MapInfoUC
  • 13. MapInfo User Conference 2014: GIS Gets Personal #MapInfoUC Exercise Data sets •USStates.tab •USUS_HIWay.tab •USSTATECAP.tab •Find the distance from every state capital to Washington •Find the distance from every state capital to Nashville
  • 14. MapInfo User Conference 2014: GIS Gets Personal #MapInfoUC Solutions 1 Select State_Name , Area(obj, "sq mi") "Area sq miles" from STATES into Selection 2 Select State_Name , Area(obj, "sq mi") "Area sq miles" , Perimeter(obj, "mi") "Perimeter miles" from STATES into Selection 3 Select Highway , ObjectLen(obj, "mi") “Length miles” from US_HIWAY into Selection 4 Select Sum(Area(obj, "sq mi")) "Area sq miles" from STATES into Selection
  • 15. MapInfo User Conference 2014: GIS Gets Personal #MapInfoUC Solutions 5 Select Sum(Area(obj, "sq mi")) "Area sq miles" from Selection into __SUM 6 Select Sum(ObjectLen(obj, "mi")) “Length miles” from Selection into __SUM 7 Select US_HIWAY.Highway, STATES.State_Name from US_HIWAY, STATES where US_HIWAY.Obj Intersects STATES.Obj order by US_HIWAY.Highway, STATES.State_Name into Selection
  • 16. MapInfo User Conference 2014: GIS Gets Personal #MapInfoUC Solutions 8 Select US_HIWAY.Highway, STATES.State_Name , ObjectLen(Overlap(US_HIWAY.Obj, STATES.Obj), "mi") "Length Miles" from US_HIWAY, STATES where US_HIWAY.Obj Intersects STATES.Obj order by US_HIWAY.Highway, STATES.State_Name into Selection 9 Select State_Name from STATES where OBJ Intersects Any (Select OBJ From US_HIWAY) order by State_Name into Selection
  • 17. MapInfo User Conference 2014: GIS Gets Personal #MapInfoUC Solutions 10 Select State_Name from STATES where not OBJ Intersects Any (Select OBJ From US_HIWAY) order by State_Name into Selection
  • 18. MapInfo User Conference 2014: GIS Gets Personal #MapInfoUC Solutions 11 Set CoordSys Table STATECAP ‘Select Washinton Fetch First From Selection Print Format$(CentroidX(Selection.obj), "#.######") + ", " + Format$(CentroidY(Selection.obj), "#.######") Select Capital, State , Distance(-77.016167, 38.90505, CentroidX(OBJ), CentroidY(OBJ), "mi") "Distance To Washington" from STATECAP into Selection
  • 19. Get the latest MapInfo User Conference news: Twitter via #MapInfoUC and follow us @MapInfo MapInfo User Conference 2014: GIS Gets Personal #MapInfoUC