Presentation is loading. Please wait.

Presentation is loading. Please wait.

DAT319 - Building Location-Aware Applications in SQL Server 2008: Introducing the Spatial Data Type Michael Rys Principal Program Manager SQL Server Engine,

Similar presentations


Presentation on theme: "DAT319 - Building Location-Aware Applications in SQL Server 2008: Introducing the Spatial Data Type Michael Rys Principal Program Manager SQL Server Engine,"— Presentation transcript:

1 DAT319 - Building Location-Aware Applications in SQL Server 2008: Introducing the Spatial Data Type Michael Rys Principal Program Manager SQL Server Engine, Microsoft http://sqlblog.com/blogs/michael_rys/

2 Session Prerequisites General knowledge of SQL Server Interest in understanding how to use spatial information in your application

3 Demo A Teaser

4 Session Objectives and Agenda What is spatial? What kinds of spatial data are there? Why might you care? How can you use it? What’s coming in SQL Server 2008? Spatial types and operations Indexing Q&A

5 Spatial is about mapping... Many applications make very direct use of mapping. The map may very well be the primary output of these applications Examples: Consumer mapping products (Virtual Earth, etc.) Cadastral mapping Utility (electrical / water / gas) grid layouts Business geographics

6 Spatial is about more than mapping... Many applications may make use of spatial data, even if they do not explicitly make maps. Examples: Send warehouse pickers on efficient runs Predict bus arrival times Applying for building variances Your favorite LOB app here

7 What is Spatial Data? Vector Points LineStrings Polygons (Areas, Regions) Raster Satellite Imagery Digitized Aerial Photos

8 Spatial Data in SQL Server 2008 We’re providing vector support We’re targeting geospatial... Spatial data which is referenced to a location on the Earth Typically uses spherical coordinates or projected planar coordinates I’ll come back to this distinction in a moment...but, there is no restriction that the data is actually geospatial Only 2D for now.

9 Sample Query Which roads intersect Microsoft’s main campus? SELECT * FROM roads WHERE roads.geom.Intersects(@ms)=1

10 It’s a big problem…

11 It can be quite complex, too...

12 Flat Earth Models Round Earth (planar) (geodetic)

13 State Plane Coordinate System

14

15 The right kind of data... Where? Lat: 47.6456 Lon: -122.12551 (NAD 83) - or - E: 1321911.8 ft N: 238170.1 ft (WA N) source: http://www.metrokc.gov/gis/mapportal/iMAP_main.htm# SQL lives here.

16 E: 1270449.7 ft N: 221605 ft E: 1321911.8 ft N: 238170.1 ft...need the right treatment. Naive planar length: 0.21289 (nonsense!) Correct geodetic length: 16.4783 km Correct planar length: 54062.5 feet (16.4783 km) 47.6456, -122.12551 47.59764, -122.33293

17 Planar and Geodetic Cover Different Scenarios Planar (flat-earth) Supports legacy and legal mapping requirements: surveyors and the specialist GIS crowd Interior spaces (building layouts, etc.) Computationally simpler Conceptually more difficult for geospatial Geodetic (round-earth) Supports existing long- range mapping requirements: military, shipping, etc. Supports new local applications Computationally more complex Conceptually simpler for geospatial

18 SQL Server 2008 Spatial Support Large (>8000 byte) CLR UDTs Geodetic Type: Geography Planar Type: Geometry Indexing July CTP November CTP 2 Spatial Types Geodetic Type: Geography Planar Type: Geometry Implemented as large CLR user-defined type (UDT) Spatial Operations as methods Indexing

19 Geodetic Type New type: GEOGRAPHY GEOGRAPHY can store instances of various types Points Line strings Polygons Collections of the above Methods for computing Spatial relationships: intersects, disjoint, etc. Spatial constructions: intersection, union, etc. Metric functions: distance, area

20 Geodetic Type Exposed as a “system CLR type” Based on CLR code and built in to SQL Server 2008 Assembly available for managed access Transport formats: Well-known text and binary formats (WKT and WKB) GML XML format Most data commonly available user data is geodetic Anything expressed as latitude/longitude This is the type we expect most people to be interested in

21 Example Code Create an instance: declare @g geography set @g = geography::Parse(‘POINT(47.6456 - 122.12551)’) Create a table: create table T(id int, region geography) Select some data select * from T where region.STIntersects(@g) = 1

22 Planar Type Second type: GEOMETRY Very similar interface to geography Some semantics differ Following Open Geospatial Consortium (OGC) Simple features for SQL Single type implementation Same type represents points, lines, polygons

23 Demo Under the Covers

24 Spatial Indexing Basics In general, split predicates in two Primary filter finds all candidates, possibly with false positives (but never false negatives) Secondary filter removes false positives The index provides our primary filter Original predicate is our secondary filter Some tweaks to this scheme Sometimes possible to skip secondary filter A A B B C C D D A A B B D D A A B B Primary Filter (Index lookup) Secondary Filter (Original predicate) E E

25 The SQL Server Problem SQL Server has B-Trees Spatial indexing is usually done through other structures Quad tree, R-Tree Challenge: How do we repurpose the B-Tree to handle spatial queries? Add a level of indirection!

26 Mapping to the B-Tree B-Trees handle linearly ordered sets well We need to somehow linearly order 2-d space Either the plane or the globe We want a locality-preserving mapping from the original space to the line I.e., close objects should be close in the index Can’t be done, but we can approximate it

27 1256 3478 9101314 11121516 1256 3478 9101314 11121516 Simplified Index Example 1256 3478 9101314 11121516 1. Overlay a grid over the Spatial data space2. Identify grids for spatial object to store in index3. Identify grids for query object(s)4. Intersecting grids identifies candidates Indexing Phase Primary Filter Secondary Filter 5. Apply actual CLR method on candidates to find matches

28 Implementation of the Index Persist a table-valued function Internally rewrite queries to use the table idgeometry 1g1 2g2 3g3 idcell_id 17 37 38 39 310 113 220 Base Table T Internal Table for sixd CREATE SPATIAL INDEX sixd ON T(geography)

29 SQL Server 2008 Indexing Story Multi-Level Grid Much more flexible than a simple grid Hilbert numbering instead of Z-numbering Grid index features 4 levels Customizable grid subdivisions Customizable maximum number of cells per object Planar one grid Requires bounding box Geodetic two top-level grid projections of sphere No bounding box

30 Multi-Level Grid 4.2.3 0

31 Index Syntax Create index example: CREATE SPATIAL INDEX sixd ON spatial_table(geom_column) WITH ( BOUNDING_BOX = (0, 0, 500, 500), GRIDS = (LOW, LOW, MEDIUM, HIGH), CELLS_PER_OBJECT = 20) Use ALTER and DROP INDEX for maintenance.

32 Demo Indexing and Performance

33 Index Support New catalog views, DDL Events DBCC Checks File groups/Partitioning Aligned to base table Separate file group Full rebuild only Can be hinted Not supported: Online rebuild Parallel creation Database Tuning advisor

34 What we aren’t doing Raster data 3D Topology: Points make up LineStrings, LineStrings make up Polygons Network models Distance between cities along the road network

35 TechEd Presentations: SQL Server 2008: Beyond Relational Whitepapers: http://www.microsoft.com/sql/2008/technologies/spat ial.mspxhttp://www.microsoft.com/sql/2008/technologies/spat ial.mspx Forum: http://forums.microsoft.com/MSDN/ShowForum.aspx ?ForumID=1629&SiteID=1http://forums.microsoft.com/MSDN/ShowForum.aspx ?ForumID=1629&SiteID=1 Weblogs: http://blogs.msdn.com/isaac http://sqlblog.com/blogs/michael_rys/ Related Content

36 Resources Technical Communities, Webcasts, Blogs, Chats & User Groups http://www.microsoft.com/communities/default.mspx http://www.microsoft.com/communities/default.mspx Microsoft Learning and Certification http://www.microsoft.com/learning/default.mspx http://www.microsoft.com/learning/default.mspx Microsoft Developer Network (MSDN) & TechNet http://microsoft.com/msdn http://microsoft.com/technet http://microsoft.com/msdn http://microsoft.com/technet Trial Software and Virtual Labs http://www.microsoft.com/technet/downloads/trials/defa ult.mspx http://www.microsoft.com/technet/downloads/trials/defa ult.mspx New, as a pilot for 2007, the Breakout sessions will be available post event, in the TechEd Video Library, via the My Event page of the website Required slide: Please customize this slide with the resources relevant to your session MSDN Library Knowledge Base Forums MSDN Magazine User Groups Newsgroups E-learning Product Evaluations Videos Webcasts V-labs Blogs MVPs Certification Chats learn support connect subscribe Visit MSDN in the ATE Pavilion and get a FREE 180-day trial of MS Visual Studio Team System!

37 Complete your evaluation on the My Event pages of the website at the CommNet or the Feedback Terminals to win!

38 © 2007 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. MICROSOFT MAKES NO WARRANTIES, EXPRESS OR IMPLIED, IN THIS SUMMARY.


Download ppt "DAT319 - Building Location-Aware Applications in SQL Server 2008: Introducing the Spatial Data Type Michael Rys Principal Program Manager SQL Server Engine,"

Similar presentations


Ads by Google