SlideShare a Scribd company logo
1 of 40
GEOGRAPHY DATATYPES
in SQL Server
by jared nielsen
linkedin.com/nielsendata
GEOGRAPHY vs GEOMETRY
Geography
Plots ellipsoidal
“Round Earth”
data using
latitude, longitude
and altitude*
coordinates
Geometry
Plots polygonal,
geometric and
linear data using X,
Y and Z*
coordinates
* not implemented well
Measuring the Earth
Coordinates
Longitude = X
Latitude = Y
Altitude = Z
Measuring the Earth
Ranges
Longitude = 0 to 360°
Latitude = 90° to -90°
Altitude = 0 to ∞ (ft)
World Geodetic System
Global standards body that defines the
coordinate systems for Earth
The latest revision is WGS 84 - referred to
as EPSG:4326
www.NGA.mil
EPSG: 4326
This geodetic standard is specified in
many geography datatype queries:
UPDATE SQLDevelopers
SET GeoPosition = geography::
Point(29.5786422, -95.2049992, 4326)
BASIC GIS CONCEPTS
Well Known Text
ESRI
Shape and Data Sources
Well Known Text - WKT
www.NGA.mil
Type Example Convert to Spatial
Point Point(x,y) .STPointFromText()
MultiPoint MultiPoint( (x,y), (x,y) ) .STMPointFromText()
LineString LineString( x y, x y, x y) .STLineFromText()
MultiLineString MultiLineString( (x y, x y) (x y, x y) ) .STMLineFromText()
Polygon Polygon ( (x1 y1, x2 y2, x3 y3, x1 y1) ) .STPolyFromText()
MultiPolygon You get the idea… Keep using those
parenthesis…
.STMPolyFromText()
How LONG is your LAT?
Sometimes you should use LON/LAT (WKT)
Other times you need to use LAT/LON (SQL)
LAT LON
San Jacinto College = 29.578, -95.204
SET GeoPosition = geography::
STGeomFromText('POINT(-95.204 29.578)', 4326)
SET GeoPosition = geography::
Point(29.578, -95.204 , 4326)
Get Some Data
Positions for the International Space Station:
http://sscweb.gsfc.nasa.gov/cgi-bin/Locator.cgi
Global Country Maps:
http://www.vdstech.com/world-data.aspx
Zip Codes, School Districts, Demographics:
http://www.data.gov
Railroads, Rivers, Cities, Volcanoes:
http://webgis.wr.usgs.gov/globalgis/datasets.htm
ESRI Shapefile Converters
Convert ESRI Shapefiles to SQL Geography:
http://www.sharpgis.net/page/Shape2SQL
Queries SQL Geography to a Map:
http://www.sharpgis.net/page/SqlSpatial-Query-Tool
ESRI Metadata Translation:
http://resources.esri.com/help/9.3/ArcGISEngine/java
/gp_toolref/conversion_tools/esri_metadata_translator
_conversion_.htm
SQL SERVER SPATIAL
Make a Table
Load Data
Query Spatial-ly
Making a Table
CREATE TABLE dbo.ISSPosition(
Longitude decimal(18, 15) NULL,
Latitude decimal(18, 15) NULL,
Sampled datetime NULL,
LocalTime nvarchar(50) NULL,
GeoPosition geography NULL,
GeomShape geometry NULL
)
Loading Data
INSERT INTO ISSPosition
(Sampled, Longitude, Latitude, LocalTime)
VALUES
('01/01/2015 00:00:00',-125.4,41,'15:38:18’)
Naturally I loaded more data … one data
point per minute from January 1 to present
It turns out that the Space Station falls fast at
17,136 mph
Convert to Geography
UPDATE ISSPosition
SET GeoPosition = geography::
Point([Latitude], [Longitude], 4326)
GO
(note we are using the native SQL Point
method so we keep LAT/LON)
Query our Data
select top 180 * from dbo.ISSPosition
Not the most thrilling outcome…
Let’s try the Spatial Results Tab…
Spatial Results Tab
select top 180 * from dbo.ISSPosition
Still not that exciting… a bunch of dots
Space Station Orbit
select top 180 * from dbo.ISSPosition order
by Sampled
Now we are getting somewhere!
Comma Delimited Points
DECLARE @ISSOrbitWKT nvarchar(max)
SELECT @ISSOrbitWKT =
STUFF((SELECT TOP 180 ',' +
Convert(nvarchar(25),Longitude) + ' ' +
Convert(nvarchar(25),Latitude)
FROM dbo.ISSPosition
ORDER BY Sampled
FOR XML PATH('')) ,1,1,'')
Convert Points to LineStrings
DECLARE @ISSOrbit geography
SET @ISSOrbit =
geography::STLineFromText('LINESTRING('
+@ISSOrbitWKT+')',4326)
Space Station Orbit
SELECT @ISSOrbit
Now you have connected points in a
linestring showing the orbit…
Space Station Orbit
CREATE TABLE CoolShapes(
Name Nvarchar(100) NOT NULL,
GeoShape geography NULL)
GO
INSERT into CoolShapes (Name, GeoShape)
values (‘ISS Orbital Path’,@ISSOrbit)
I like this shape so much I’m going to keep
a copy of it
World Geography
Global Datasets
From ESRI Shapefiles
Load Global Maps
Load Global Maps
select @ISSOrbit union all select GeoMap
from dbo.world
With a UNION, we simply plot the orbit on
the Global ESRI Shapefile Map
http://www.vdstech.com/world-data.aspx
GEOGRAPHY Case Studies
INTERSECTION
BUFFERS
Spatial Methods
www.NGA.mil
Type Example Syntax
Buffer @IISOrbit.STBuffer(75000) .STBuffer(radius)
Intersect @IISOrbit.STIntersection(@China) .STIntersection(object)
Distance @China.STDistance(@Guatemala) .STDistance(object)
Crosses @IISOrbit.Crosses(@China) .STCrosses(object)
Within @SQLDeveloper.STWithin(@SanJac
intoCollege.STBuffer(4000))
.STWithin(object)
Contains @SanJacintoCollege.STContains(
@Jared)
.STContains(object)
STIntersection Method
SELECT @ISSOrbit UNION ALL SELECT GeoMap
FROM World WHERE Name='China'
A human knows that the orbit crosses China, but
how do we tell the computers?
http://www.vdstech.com/world-data.aspx
STIntersection Method
SELECT @ISSOrbit.STIntersects(@China)
We know it intersects… but WHERE?
http://www.vdstech.com/world-data.aspx
STIntersection Method
SELECT @ISSOrbit.STDifference(@China)
.STIntersection(@China)
Can you see them?
http://www.vdstech.com/world-data.aspx
STIntersection Method
SELECT @ISSOrbit.STDifference(@China)
.STIntersection(@China)
.STBuffer(75000)
UNION ALL SELECT @China
Let’s add a few .STBuffer(s)
http://www.vdstech.com/world-data.aspx
Can Your Sales Rep See the
Customer at a Trade Show?
San Jacinto College
Make Some Developers
insert into SQLDevelopers (Name, Latitude, Longitude,
Altitude) values ('Jared Nielsen Dark Matter', 29.5786422, -
95.2049992, 15)
insert into SQLDevelopers (Name, Latitude, Longitude,
Altitude) values ('Jared Nielsen', 29.5786422, -95.2049992,
15)
insert into SQLDevelopers (Name, Latitude, Longitude,
Altitude) values ('Nancy Hidy Wilson', 29.578, -95.2049, 14)
insert into SQLDevelopers (Name, Latitude, Longitude,
Altitude) values ('Robert Gremillion', 29.5552929,-
95.1133171,16)
UPDATE SQLDevelopers
SET GeoPosition = geography::Point([Latitude], [Longitude],
4326)
GO
http://www.vdstech.com/world-data.aspx
Enter Tradeshow Location
ALTER TABLE CoolShapes ADD
GeoPosition geography NULL
GO
INSERT INTO CoolShapes (Name,
GeoPosition)
VALUES ('San Jacinto College',
geography::Point(29.5786422, -
95.2049992, 4326))
http://www.vdstech.com/world-data.aspx
STIntersection Method
One Developer is Not Attending
http://www.vdstech.com/world-data.aspx
SELECT GeoPosition.STBuffer(100) FROM
CoolShapes WHERE Name='San Jacinto College'
UNION ALL
SELECT GeoPosition.STBuffer(30) FROM
SQLDevelopers
STIntersection Method
Who else is here?
http://www.vdstech.com/world-data.aspx
SELECT GeoPosition.STBuffer(100) FROM
CoolShapes WHERE Name='San Jacinto College'
UNION ALL
SELECT GeoPosition.STBuffer(30) FROM
SQLDevelopers WHERE NAME NOT IN ('Robert
Gremillion')
More Methods
http://www.vdstech.com/world-data.aspx
DECLARE @Jared geography
DECLARE @Robert geography
DECLARE @Nancy geography
DECLARE @SanJAC Geography
DECLARE @JaredGhost geography
SELECT @Jared = GeoPosition.STBuffer(5) FROM SQLDevelopers WHERE
Name = 'Jared Nielsen'
SELECT @Robert = Geoposition.STBuffer(5) from SQLDevelopers WHERE
Name='Robert Gremillion'
SELECT @Nancy = Geoposition.STBuffer(5) from SQLDevelopers wHERE
Name LIKE 'Nancy%'
SELECT @SanJAC = Geoposition.STBuffer(100) from CoolShapes WHERE
Name = 'San Jacinto College'
SELECT @JaredGhost = Geoposition.STBuffer(2) from SQLDevelopers
WHERE Name = 'Jared Nielsen Dark Matter’
More Methods
Can your sales rep see the customer?
http://www.vdstech.com/world-data.aspx
SELECT @Jared.STWithin(@SanJAC) = Boolean True
SELECT @SanJAC.STContains(@Robert) = Boolean False
SELECT @Jared.STDistance(@Nancy) = 61.832 meters
Declare @SalesRepVisualPerimeter geography
SELECT @SalesRepVisualPerimeter = @Jared.STBuffer(10)
Declare @VisualRecognitionPerimeter geography
SELECT @VisualRecognitionPerimeter=
@Nancy.STBuffer(60)
More Methods
Boolean = 1= Yes
http://www.vdstech.com/world-data.aspx
SELECT @VisualRecognitionPerimeter.STOverlaps
(@SalesRepVisualPerimeter )
JARED NIELSEN
Serial Entrepreneur
Investor
Software Architect
Questions?

More Related Content

Similar to SQL Geography Datatypes by Jared Nielsen and the FUZION Agency

Stockage, manipulation et analyse de données matricielles avec PostGIS Raster
Stockage, manipulation et analyse de données matricielles avec PostGIS RasterStockage, manipulation et analyse de données matricielles avec PostGIS Raster
Stockage, manipulation et analyse de données matricielles avec PostGIS RasterACSG Section Montréal
 
Garmin Developer Summit 2018 - Talk
Garmin Developer Summit 2018 - TalkGarmin Developer Summit 2018 - Talk
Garmin Developer Summit 2018 - TalkRichard Süselbeck
 
Garmin Developer Summit 2018 - Talk
Garmin Developer Summit 2018 - TalkGarmin Developer Summit 2018 - Talk
Garmin Developer Summit 2018 - TalkHERE Technologies
 
Handling Real-time Geostreams
Handling Real-time GeostreamsHandling Real-time Geostreams
Handling Real-time Geostreamsguest35660bc
 
Handling Real-time Geostreams
Handling Real-time GeostreamsHandling Real-time Geostreams
Handling Real-time GeostreamsRaffi Krikorian
 
Geek Sync | Having Fun with Spatial Data
Geek Sync | Having Fun with Spatial DataGeek Sync | Having Fun with Spatial Data
Geek Sync | Having Fun with Spatial DataIDERA Software
 
A Century Of Weather Data - Midwest.io
A Century Of Weather Data - Midwest.ioA Century Of Weather Data - Midwest.io
A Century Of Weather Data - Midwest.ioRandall Hunt
 
Sql Saturday Spatial Data Ss2008 Michael Stark Copy
Sql Saturday Spatial Data Ss2008 Michael Stark   CopySql Saturday Spatial Data Ss2008 Michael Stark   Copy
Sql Saturday Spatial Data Ss2008 Michael Stark Copymws580
 
Cloud conf-varna-2014-mihail mateev-spatial-data-and-microsoft-azure-sql-data...
Cloud conf-varna-2014-mihail mateev-spatial-data-and-microsoft-azure-sql-data...Cloud conf-varna-2014-mihail mateev-spatial-data-and-microsoft-azure-sql-data...
Cloud conf-varna-2014-mihail mateev-spatial-data-and-microsoft-azure-sql-data...Mihail Mateev
 
Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)
Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)
Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)Grant Goodale
 
Geospatial Graphs made easy with OrientDB - Codemotion Warsaw 2016
Geospatial Graphs made easy with OrientDB - Codemotion Warsaw 2016Geospatial Graphs made easy with OrientDB - Codemotion Warsaw 2016
Geospatial Graphs made easy with OrientDB - Codemotion Warsaw 2016Luigi Dell'Aquila
 
MongoDB for Time Series Data: Analyzing Time Series Data Using the Aggregatio...
MongoDB for Time Series Data: Analyzing Time Series Data Using the Aggregatio...MongoDB for Time Series Data: Analyzing Time Series Data Using the Aggregatio...
MongoDB for Time Series Data: Analyzing Time Series Data Using the Aggregatio...MongoDB
 
Uncovering SQL Server query problems with execution plans - Tony Davis
Uncovering SQL Server query problems with execution plans - Tony DavisUncovering SQL Server query problems with execution plans - Tony Davis
Uncovering SQL Server query problems with execution plans - Tony DavisRed Gate Software
 
Introduction to Oracle Spatial
Introduction to Oracle SpatialIntroduction to Oracle Spatial
Introduction to Oracle SpatialEhsan Hamzei
 
Average- An android project
Average- An android projectAverage- An android project
Average- An android projectIpsit Dash
 
Where the %$#^ Is Everybody? Geospatial Solutions For Oracle APEX
Where the %$#^ Is Everybody? Geospatial Solutions For Oracle APEXWhere the %$#^ Is Everybody? Geospatial Solutions For Oracle APEX
Where the %$#^ Is Everybody? Geospatial Solutions For Oracle APEXJim Czuprynski
 
OrientDB - The 2nd generation of (multi-model) NoSQL
OrientDB - The 2nd generation of  (multi-model) NoSQLOrientDB - The 2nd generation of  (multi-model) NoSQL
OrientDB - The 2nd generation of (multi-model) NoSQLRoberto Franchini
 
Geospatial Indexing and Querying with MongoDB
Geospatial Indexing and Querying with MongoDBGeospatial Indexing and Querying with MongoDB
Geospatial Indexing and Querying with MongoDBGrant Goodale
 

Similar to SQL Geography Datatypes by Jared Nielsen and the FUZION Agency (20)

GeoMesa on Spark SQL: Extracting Location Intelligence from Data
GeoMesa on Spark SQL: Extracting Location Intelligence from DataGeoMesa on Spark SQL: Extracting Location Intelligence from Data
GeoMesa on Spark SQL: Extracting Location Intelligence from Data
 
Stockage, manipulation et analyse de données matricielles avec PostGIS Raster
Stockage, manipulation et analyse de données matricielles avec PostGIS RasterStockage, manipulation et analyse de données matricielles avec PostGIS Raster
Stockage, manipulation et analyse de données matricielles avec PostGIS Raster
 
Garmin Developer Summit 2018 - Talk
Garmin Developer Summit 2018 - TalkGarmin Developer Summit 2018 - Talk
Garmin Developer Summit 2018 - Talk
 
Garmin Developer Summit 2018 - Talk
Garmin Developer Summit 2018 - TalkGarmin Developer Summit 2018 - Talk
Garmin Developer Summit 2018 - Talk
 
Handling Real-time Geostreams
Handling Real-time GeostreamsHandling Real-time Geostreams
Handling Real-time Geostreams
 
Handling Real-time Geostreams
Handling Real-time GeostreamsHandling Real-time Geostreams
Handling Real-time Geostreams
 
Geek Sync | Having Fun with Spatial Data
Geek Sync | Having Fun with Spatial DataGeek Sync | Having Fun with Spatial Data
Geek Sync | Having Fun with Spatial Data
 
A Century Of Weather Data - Midwest.io
A Century Of Weather Data - Midwest.ioA Century Of Weather Data - Midwest.io
A Century Of Weather Data - Midwest.io
 
Sql Server 2008 Spatial Analysis
Sql Server 2008 Spatial AnalysisSql Server 2008 Spatial Analysis
Sql Server 2008 Spatial Analysis
 
Sql Saturday Spatial Data Ss2008 Michael Stark Copy
Sql Saturday Spatial Data Ss2008 Michael Stark   CopySql Saturday Spatial Data Ss2008 Michael Stark   Copy
Sql Saturday Spatial Data Ss2008 Michael Stark Copy
 
Cloud conf-varna-2014-mihail mateev-spatial-data-and-microsoft-azure-sql-data...
Cloud conf-varna-2014-mihail mateev-spatial-data-and-microsoft-azure-sql-data...Cloud conf-varna-2014-mihail mateev-spatial-data-and-microsoft-azure-sql-data...
Cloud conf-varna-2014-mihail mateev-spatial-data-and-microsoft-azure-sql-data...
 
Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)
Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)
Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)
 
Geospatial Graphs made easy with OrientDB - Codemotion Warsaw 2016
Geospatial Graphs made easy with OrientDB - Codemotion Warsaw 2016Geospatial Graphs made easy with OrientDB - Codemotion Warsaw 2016
Geospatial Graphs made easy with OrientDB - Codemotion Warsaw 2016
 
MongoDB for Time Series Data: Analyzing Time Series Data Using the Aggregatio...
MongoDB for Time Series Data: Analyzing Time Series Data Using the Aggregatio...MongoDB for Time Series Data: Analyzing Time Series Data Using the Aggregatio...
MongoDB for Time Series Data: Analyzing Time Series Data Using the Aggregatio...
 
Uncovering SQL Server query problems with execution plans - Tony Davis
Uncovering SQL Server query problems with execution plans - Tony DavisUncovering SQL Server query problems with execution plans - Tony Davis
Uncovering SQL Server query problems with execution plans - Tony Davis
 
Introduction to Oracle Spatial
Introduction to Oracle SpatialIntroduction to Oracle Spatial
Introduction to Oracle Spatial
 
Average- An android project
Average- An android projectAverage- An android project
Average- An android project
 
Where the %$#^ Is Everybody? Geospatial Solutions For Oracle APEX
Where the %$#^ Is Everybody? Geospatial Solutions For Oracle APEXWhere the %$#^ Is Everybody? Geospatial Solutions For Oracle APEX
Where the %$#^ Is Everybody? Geospatial Solutions For Oracle APEX
 
OrientDB - The 2nd generation of (multi-model) NoSQL
OrientDB - The 2nd generation of  (multi-model) NoSQLOrientDB - The 2nd generation of  (multi-model) NoSQL
OrientDB - The 2nd generation of (multi-model) NoSQL
 
Geospatial Indexing and Querying with MongoDB
Geospatial Indexing and Querying with MongoDBGeospatial Indexing and Querying with MongoDB
Geospatial Indexing and Querying with MongoDB
 

Recently uploaded

EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptxthyngster
 
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service LucknowAminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknowmakika9823
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfSocial Samosa
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改atducpo
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxStephen266013
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxEmmanuel Dauda
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Sapana Sha
 
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一ffjhghh
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Delhi Call girls
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Callshivangimorya083
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...Florian Roscheck
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsappssapnasaifi408
 
Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystSamantha Rae Coolbeth
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfRachmat Ramadhan H
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationshipsccctableauusergroup
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130Suhani Kapoor
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptSonatrach
 

Recently uploaded (20)

EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
 
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service LucknowAminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
Aminabad Call Girl Agent 9548273370 , Call Girls Service Lucknow
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
 
Decoding Loan Approval: Predictive Modeling in Action
Decoding Loan Approval: Predictive Modeling in ActionDecoding Loan Approval: Predictive Modeling in Action
Decoding Loan Approval: Predictive Modeling in Action
 
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
代办国外大学文凭《原版美国UCLA文凭证书》加州大学洛杉矶分校毕业证制作成绩单修改
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docx
 
Customer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptxCustomer Service Analytics - Make Sense of All Your Data.pptx
Customer Service Analytics - Make Sense of All Your Data.pptx
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
 
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一定制英国白金汉大学毕业证(UCB毕业证书)																			成绩单原版一比一
定制英国白金汉大学毕业证(UCB毕业证书) 成绩单原版一比一
 
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
Best VIP Call Girls Noida Sector 39 Call Me: 8448380779
 
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip CallDelhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
Delhi Call Girls CP 9711199171 ☎✔👌✔ Whatsapp Hard And Sexy Vip Call
 
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...From idea to production in a day – Leveraging Azure ML and Streamlit to build...
From idea to production in a day – Leveraging Azure ML and Streamlit to build...
 
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /WhatsappsBeautiful Sapna Vip  Call Girls Hauz Khas 9711199012 Call /Whatsapps
Beautiful Sapna Vip Call Girls Hauz Khas 9711199012 Call /Whatsapps
 
Unveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data AnalystUnveiling Insights: The Role of a Data Analyst
Unveiling Insights: The Role of a Data Analyst
 
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdfMarket Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
Market Analysis in the 5 Largest Economic Countries in Southeast Asia.pdf
 
04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships04242024_CCC TUG_Joins and Relationships
04242024_CCC TUG_Joins and Relationships
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in  KishangarhDelhi 99530 vip 56974 Genuine Escort Service Call Girls in  Kishangarh
Delhi 99530 vip 56974 Genuine Escort Service Call Girls in Kishangarh
 
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
VIP Call Girls Service Miyapur Hyderabad Call +91-8250192130
 
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.pptdokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
dokumen.tips_chapter-4-transient-heat-conduction-mehmet-kanoglu.ppt
 

SQL Geography Datatypes by Jared Nielsen and the FUZION Agency

  • 1. GEOGRAPHY DATATYPES in SQL Server by jared nielsen linkedin.com/nielsendata
  • 2. GEOGRAPHY vs GEOMETRY Geography Plots ellipsoidal “Round Earth” data using latitude, longitude and altitude* coordinates Geometry Plots polygonal, geometric and linear data using X, Y and Z* coordinates * not implemented well
  • 3. Measuring the Earth Coordinates Longitude = X Latitude = Y Altitude = Z
  • 4. Measuring the Earth Ranges Longitude = 0 to 360° Latitude = 90° to -90° Altitude = 0 to ∞ (ft)
  • 5. World Geodetic System Global standards body that defines the coordinate systems for Earth The latest revision is WGS 84 - referred to as EPSG:4326 www.NGA.mil
  • 6. EPSG: 4326 This geodetic standard is specified in many geography datatype queries: UPDATE SQLDevelopers SET GeoPosition = geography:: Point(29.5786422, -95.2049992, 4326)
  • 7. BASIC GIS CONCEPTS Well Known Text ESRI Shape and Data Sources
  • 8. Well Known Text - WKT www.NGA.mil Type Example Convert to Spatial Point Point(x,y) .STPointFromText() MultiPoint MultiPoint( (x,y), (x,y) ) .STMPointFromText() LineString LineString( x y, x y, x y) .STLineFromText() MultiLineString MultiLineString( (x y, x y) (x y, x y) ) .STMLineFromText() Polygon Polygon ( (x1 y1, x2 y2, x3 y3, x1 y1) ) .STPolyFromText() MultiPolygon You get the idea… Keep using those parenthesis… .STMPolyFromText()
  • 9. How LONG is your LAT? Sometimes you should use LON/LAT (WKT) Other times you need to use LAT/LON (SQL) LAT LON San Jacinto College = 29.578, -95.204 SET GeoPosition = geography:: STGeomFromText('POINT(-95.204 29.578)', 4326) SET GeoPosition = geography:: Point(29.578, -95.204 , 4326)
  • 10. Get Some Data Positions for the International Space Station: http://sscweb.gsfc.nasa.gov/cgi-bin/Locator.cgi Global Country Maps: http://www.vdstech.com/world-data.aspx Zip Codes, School Districts, Demographics: http://www.data.gov Railroads, Rivers, Cities, Volcanoes: http://webgis.wr.usgs.gov/globalgis/datasets.htm
  • 11. ESRI Shapefile Converters Convert ESRI Shapefiles to SQL Geography: http://www.sharpgis.net/page/Shape2SQL Queries SQL Geography to a Map: http://www.sharpgis.net/page/SqlSpatial-Query-Tool ESRI Metadata Translation: http://resources.esri.com/help/9.3/ArcGISEngine/java /gp_toolref/conversion_tools/esri_metadata_translator _conversion_.htm
  • 12. SQL SERVER SPATIAL Make a Table Load Data Query Spatial-ly
  • 13. Making a Table CREATE TABLE dbo.ISSPosition( Longitude decimal(18, 15) NULL, Latitude decimal(18, 15) NULL, Sampled datetime NULL, LocalTime nvarchar(50) NULL, GeoPosition geography NULL, GeomShape geometry NULL )
  • 14. Loading Data INSERT INTO ISSPosition (Sampled, Longitude, Latitude, LocalTime) VALUES ('01/01/2015 00:00:00',-125.4,41,'15:38:18’) Naturally I loaded more data … one data point per minute from January 1 to present It turns out that the Space Station falls fast at 17,136 mph
  • 15. Convert to Geography UPDATE ISSPosition SET GeoPosition = geography:: Point([Latitude], [Longitude], 4326) GO (note we are using the native SQL Point method so we keep LAT/LON)
  • 16. Query our Data select top 180 * from dbo.ISSPosition Not the most thrilling outcome… Let’s try the Spatial Results Tab…
  • 17. Spatial Results Tab select top 180 * from dbo.ISSPosition Still not that exciting… a bunch of dots
  • 18. Space Station Orbit select top 180 * from dbo.ISSPosition order by Sampled Now we are getting somewhere!
  • 19. Comma Delimited Points DECLARE @ISSOrbitWKT nvarchar(max) SELECT @ISSOrbitWKT = STUFF((SELECT TOP 180 ',' + Convert(nvarchar(25),Longitude) + ' ' + Convert(nvarchar(25),Latitude) FROM dbo.ISSPosition ORDER BY Sampled FOR XML PATH('')) ,1,1,'')
  • 20. Convert Points to LineStrings DECLARE @ISSOrbit geography SET @ISSOrbit = geography::STLineFromText('LINESTRING(' +@ISSOrbitWKT+')',4326)
  • 21. Space Station Orbit SELECT @ISSOrbit Now you have connected points in a linestring showing the orbit…
  • 22. Space Station Orbit CREATE TABLE CoolShapes( Name Nvarchar(100) NOT NULL, GeoShape geography NULL) GO INSERT into CoolShapes (Name, GeoShape) values (‘ISS Orbital Path’,@ISSOrbit) I like this shape so much I’m going to keep a copy of it
  • 25. Load Global Maps select @ISSOrbit union all select GeoMap from dbo.world With a UNION, we simply plot the orbit on the Global ESRI Shapefile Map http://www.vdstech.com/world-data.aspx
  • 27. Spatial Methods www.NGA.mil Type Example Syntax Buffer @IISOrbit.STBuffer(75000) .STBuffer(radius) Intersect @IISOrbit.STIntersection(@China) .STIntersection(object) Distance @China.STDistance(@Guatemala) .STDistance(object) Crosses @IISOrbit.Crosses(@China) .STCrosses(object) Within @SQLDeveloper.STWithin(@SanJac intoCollege.STBuffer(4000)) .STWithin(object) Contains @SanJacintoCollege.STContains( @Jared) .STContains(object)
  • 28. STIntersection Method SELECT @ISSOrbit UNION ALL SELECT GeoMap FROM World WHERE Name='China' A human knows that the orbit crosses China, but how do we tell the computers? http://www.vdstech.com/world-data.aspx
  • 29. STIntersection Method SELECT @ISSOrbit.STIntersects(@China) We know it intersects… but WHERE? http://www.vdstech.com/world-data.aspx
  • 31. STIntersection Method SELECT @ISSOrbit.STDifference(@China) .STIntersection(@China) .STBuffer(75000) UNION ALL SELECT @China Let’s add a few .STBuffer(s) http://www.vdstech.com/world-data.aspx
  • 32. Can Your Sales Rep See the Customer at a Trade Show? San Jacinto College
  • 33. Make Some Developers insert into SQLDevelopers (Name, Latitude, Longitude, Altitude) values ('Jared Nielsen Dark Matter', 29.5786422, - 95.2049992, 15) insert into SQLDevelopers (Name, Latitude, Longitude, Altitude) values ('Jared Nielsen', 29.5786422, -95.2049992, 15) insert into SQLDevelopers (Name, Latitude, Longitude, Altitude) values ('Nancy Hidy Wilson', 29.578, -95.2049, 14) insert into SQLDevelopers (Name, Latitude, Longitude, Altitude) values ('Robert Gremillion', 29.5552929,- 95.1133171,16) UPDATE SQLDevelopers SET GeoPosition = geography::Point([Latitude], [Longitude], 4326) GO http://www.vdstech.com/world-data.aspx
  • 34. Enter Tradeshow Location ALTER TABLE CoolShapes ADD GeoPosition geography NULL GO INSERT INTO CoolShapes (Name, GeoPosition) VALUES ('San Jacinto College', geography::Point(29.5786422, - 95.2049992, 4326)) http://www.vdstech.com/world-data.aspx
  • 35. STIntersection Method One Developer is Not Attending http://www.vdstech.com/world-data.aspx SELECT GeoPosition.STBuffer(100) FROM CoolShapes WHERE Name='San Jacinto College' UNION ALL SELECT GeoPosition.STBuffer(30) FROM SQLDevelopers
  • 36. STIntersection Method Who else is here? http://www.vdstech.com/world-data.aspx SELECT GeoPosition.STBuffer(100) FROM CoolShapes WHERE Name='San Jacinto College' UNION ALL SELECT GeoPosition.STBuffer(30) FROM SQLDevelopers WHERE NAME NOT IN ('Robert Gremillion')
  • 37. More Methods http://www.vdstech.com/world-data.aspx DECLARE @Jared geography DECLARE @Robert geography DECLARE @Nancy geography DECLARE @SanJAC Geography DECLARE @JaredGhost geography SELECT @Jared = GeoPosition.STBuffer(5) FROM SQLDevelopers WHERE Name = 'Jared Nielsen' SELECT @Robert = Geoposition.STBuffer(5) from SQLDevelopers WHERE Name='Robert Gremillion' SELECT @Nancy = Geoposition.STBuffer(5) from SQLDevelopers wHERE Name LIKE 'Nancy%' SELECT @SanJAC = Geoposition.STBuffer(100) from CoolShapes WHERE Name = 'San Jacinto College' SELECT @JaredGhost = Geoposition.STBuffer(2) from SQLDevelopers WHERE Name = 'Jared Nielsen Dark Matter’
  • 38. More Methods Can your sales rep see the customer? http://www.vdstech.com/world-data.aspx SELECT @Jared.STWithin(@SanJAC) = Boolean True SELECT @SanJAC.STContains(@Robert) = Boolean False SELECT @Jared.STDistance(@Nancy) = 61.832 meters Declare @SalesRepVisualPerimeter geography SELECT @SalesRepVisualPerimeter = @Jared.STBuffer(10) Declare @VisualRecognitionPerimeter geography SELECT @VisualRecognitionPerimeter= @Nancy.STBuffer(60)
  • 39. More Methods Boolean = 1= Yes http://www.vdstech.com/world-data.aspx SELECT @VisualRecognitionPerimeter.STOverlaps (@SalesRepVisualPerimeter )