+ All Categories
Home > Documents > Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Date post: 12-Dec-2015
Category:
Upload: frederick-pickles
View: 219 times
Download: 3 times
Share this document with a friend
33
Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison
Transcript
Page 1: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Who Needs Google Maps?(when you’ve got SQL Server)

Alastair Aitchison

Page 2: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Google MapsSnazzy Logo Search for Location

Map Display

Route between locations

Page 3: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Bing MapsSnazzy Logo Search for Location

Map Display

Route between locations

Page 4: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Yahoo MapsSnazzy Logo

Search for Location

Map DisplayRoute between

locations

Page 5: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

MapQuestSnazzy Logo

Search for Location

Map DisplayRoute between locations

Page 6: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Requirements Checklist

1. Snazzy Logo2. Pannable, Zoomable Map Display3. Search for a Location4. Calculate Route Between Destinations

This will involve: Importing data from shapefiles, integrating with SQLCLR, using SSRS, passing spatial data to/from stored procedures, and more!

Page 7: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Requirement #1 : Snazzy Logo

• Take a brand name and add on “maps”

• Therefore…

Page 8: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Requirements Checklist

1. Snazzy Logo a2. Pannable, Zoomable Map Display3. Search for a Location4. Calculate Route Between Destinations

Page 9: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Ordnance Survey Open Data

• Free, “lite” OS datasets• Different products, e.g:– VectorMap (features)

– Gazetteer (placenames)

– CodePoint Open (p’codes)

• Download or DVD• ESRI Shapefile format

Page 10: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Loading Shapefiles to SQL Server

• SQL Server does not support shapefiles• Use 3rd party tools– Commercial: Safe FME, Manifold– Free: OGR2OGR, Shape2SQL

• Check .prj file to determine geography/geometry and correct SRID

Page 11: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Shape2SQL Demo

Page 12: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Requirement #2 : Map Display

• What visualisation options does SQL Server provide?– SSMS Spatial Results tab (SQL 2008/R2)– SSRS Map Component (SQL 2008 R2 only)

• No new options in SQL Denali

Page 13: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

SSMS Spatial Results Tab Demo

Page 14: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

SSRS Map Component Demo

Page 15: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Requirement #2 : Map Display

• SSMS Spatial Results tab+ Available after SELECTing geometry/geography data+ Pannable, zoomable, labelled- Max 5,000 features- Only for use in SSMS - not embeddable / exportable

• SSRS Map Component (SQL 2008 R2)+ Good for analysis – drilldown by clicking shapes etc.+ Can be exported as static image- Slow and static. Not “slippy” interface

Page 16: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

A Silverlight Map Display App

• Silverlight provides UI and Graphics classes• SqlServer.Types.dll not Silverlight compatible• Use intermediary web service• OS Eastings / Northings -> Screen (x,y)

Page 17: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

SProc to Retrieve OS Tiles

CREATE PROCEDURE [dbo].[GetSettlementDataForTile] @TileBounds geometry

AS BEGIN DECLARE @TileHeight float = (@TileBounds.STPointN(3).STY - @TileBounds.STPointN(2).STY); DECLARE @Res float = @TileHeight / 256;

SELECT geom27700.STIntersection(@TileBounds).Reduce(@Res) FROM Settlement_Area WITH(index(geom27700_sidx)) WHERE geom27700.STIntersects(@TileBounds) = 1END

Page 18: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Silverlight Slippy Map Demo

Page 19: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Requirements Checklist

1. Snazzy Logo a2. Pannable, Zoomable Map Display a3. Search for a Location4. Calculate Route Between Destinations

Page 20: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Geocoding (Location Searching)

• Not really a Spatial Operation• Address text parsing / searchSELECT * FROM OSLocatorWHERE ROADNAME = @RoadName

• Fuzzy matching with full-text search• RegEx matching for Postcode• Supplied address is freetext user input so be

cautious of SQL injection attacks etc.

Page 21: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Geocoding Demo

Page 22: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Requirements Checklist

1. Snazzy Logo a2. Pannable, Zoomable Map Display a3. Search for a Location a4. Calculate Route Between Destinations

Page 23: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Routing

• Not sufficient to have a table of LineStrings• Network topology – how are roads connected?• Graph theory:

Node (Point) Edge (LineString)

Page 24: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Brute Force Routing with T-SQL

• Recursive CTE• Anchor member selects LineString edges that

begin at chosen start node• Recursive member joins from STEndPoint() of

last edge to STStartPoint() of next edge• Create geometry of route already travelled to

avoid infinite loops• Expand outwards until end node found

Page 25: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Smart Routing with SQLCLR

• A* algorithm• Heuristics prioritise edges more likely to lie on

least cost route to goal• “Least cost” does not have to mean “shortest”• Additional properties of each node:

g: cost of route already travelled to reach this nodeh: estimated remaining cost from this node to goalf: g + h

Page 26: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

A* Algorithm in Operation

Start Goal

A B

C

D

E

Page 27: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

A* Algorithm in Operation

3 7

2 10.2

2.8 8.2

Start Goal

A B

C

D

E

Page 28: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

A* Algorithm in Operation

X

2 10.2

2.8 8.2

Start Goal

A B

C

D

E

Page 29: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

A* Algorithm in Operation

X

2 10.2

2.88.5

1

Start Goal

A B

C

D

E

Page 30: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

A* Algorithm in Operation

X

2 10.2

2.88.5

1

Goal reached!Route cost: 12.2

Start Goal

A B

C

D

E

Page 31: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Requirements Checklist

1. Snazzy Logo a2. Pannable, Zoomable Map Display a3. Search for a Location a4. Calculate Route Between Destinations a

Put it all together and what have you got?

Page 32: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

SQLBitMaps in action…

Page 33: Who Needs Google Maps? (when you’ve got SQL Server) Alastair Aitchison.

Want More?

: @alastaira #sqlbits8

: http://alastaira.wordpress.com

MSDN Spatial Forum: http://social.msdn.microsoft.com/Forums/en-GB/sqlspatial/threads


Recommended