Published on

Published in: Technology
1 Like
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide


  1. 1. Spatial Support<br />
  2. 2. Relational and Non-Relational Data<br />Relational data uses simple data types<br />Each type has a single value<br />Generic operations work well with the types<br />Relational storage/query may not be optimal for<br />Hierarchical data<br />Sparse, variable, property bags<br />Some types <br />benefit by using a custom library<br />use extended type system (complex types, inheritance)<br />use custom storage and non-SQL APIs<br />use non-relational queries and indexing<br />
  3. 3. Spatial Data<br />Spatial data provides answers to location-based queries<br />Which roads intersect the Microsoft campus?<br />Does my land claim overlap yours?<br />List all of the Italian restaurants within 5 kilometers<br />Spatial data is part of almost every database<br />If your database includes an address<br />
  4. 4. Spatial Data Types<br />The Open Geospatial Consortium defines a hierarchy of spatial data types<br />Point<br />Linestring<br />Polygon<br />MultiPoint<br />MultiLinestring<br />MultiPolygon<br />GeomCollection<br />Non-instanciable classes based on these<br />
  5. 5. OGC Hierarchy of Spatial Types<br />
  6. 6. SQL Server 2008 and Spatial Data<br />SQL Server supports two spatial data types<br />GEOMETRY - flat earth model<br />GEOGRAPHY - round earth model<br />Both types support all of the instanciable OGC types<br />InstanceOf method can distinguish between them<br />Supports two dimension data<br />X and Y or Lat and Long members<br />Z member - elevation (user-defined semantics)<br />M member - measure (user-defined semantics)<br />
  7. 7. GEOGRAPHY Requirements<br />GEOGRAPHY type has additional requirements<br />Coordinate order is <br />Longitude/Latitude for WKT, WKB<br />Latitude/Longitude for GML<br />Exterior polygon rings must have their describing coordinates in counter-clockwise order (left-hand rule) with interior rings (holes) in clockwise-order (right-hand rule) <br />A single GEOGRAPHY object cannot span more than a logical hemisphere<br />
  8. 8. Spatial Data<br />demo <br />
  9. 9. Properties and Methods<br />The spatial data types are exposed as SQLCLR UDTs<br />Use &apos;.&apos; syntax for properties<br />Use &apos;.&apos; syntax for instance methods<br />Use &apos;::&apos; syntax for static methods<br />Methods and Properties are case-sensitive<br />Each type uses a set of properties and methods that correspond to OGC functionality<br />With Extensions<br />Geometry implements all OGC properties and methods<br />Geography implements most OGC properties and methods<br />2-D vector only implemented<br />
  10. 10. Input<br />Spatial data is stored in a proprietary binary format<br />Instance of the type can be NULL<br />Can be input as<br />Well Known binary - ST[Type]FromWKB<br />Well Known text - ST[Type]FromText<br />Geography Markup Language (GML) - GeomFromGml<br />Can also use SQLCLR functions<br />Parse<br />Point - extension function<br />Input from SQLCLR Type - SqlGeometry, SqlGeography<br />Spatial builder API – Populate, IGeometrySink/IGeographySink<br />
  11. 11. Output<br />Spatial Data Can Be Output As<br />Well Known binary - STAsBinary<br />Well Known text - STAsText<br />GML - AsGml<br />Text with Z and M values - AsTextZM<br />SQLCLR standard method<br />ToString - returns Well Known text<br />As SQLCLR object - SqlGeometry, SqlGeography<br />Other useful formats are GeoRSS, KML<br />Not Directly Supported<br />
  12. 12. SRID<br />Each instance of a spatial type must have an SRID<br />Spatial Reference Identifier<br />SRID specifies the specification used to compute it<br />SRID 4326 - GPS, default for GEOGRAPHY<br />SRID 4269 - usually used by ESRI<br />SRID 0 - no special reference, default for GEOMETRY<br />Methods that use multiple spatial types (e.g., STDistance) must have types with matching SRID<br />Else method returns NULL<br />Geography instance must reference one of these SRID stored in sys.spatial_reference_systems<br />
  13. 13. Useful Methods/Properties<br />Descriptive<br />STArea<br />STLength<br />STCentroid<br />Relation between two instances<br />STIntersects<br />STDistance<br />Manipulation<br />STUnion<br />STSymDifference<br />Collections<br />STGeometryN<br />STPointN<br />
  14. 14. Sample Query<br />Which roads intersect Microsoft’s main campus?<br />SELECT *<br />FROM roads <br />WHERE roads.geom.STIntersects(@ms)=1<br />
  15. 15. Extension Methods<br />SQL Server 2008 extends OGC methods<br />MakeValid - Converts to OGC valid instance<br />BufferWithTolerence - similar to STBuffer, allows approximation and variation<br />Reduce - Simplify a complex geography or geometry<br />NumRings, RingN - polygons with multiple rings<br />GML support<br />Z and M properties and AsTextZM method<br />Filter - provides a quick intersection set but with false positives<br />EnvelopeCenter,EnvelopeAngle for Geography types<br />
  16. 16. Spatial Indexes<br />SQL Server Spatial Indexes Based on B-Trees<br />Uses tessellation to tile 2D to linear<br />Divides space into grid of cells(uses Hilbert algorithm)<br />Meant as a first level of row elimination<br />Can produce false positives<br />Never false negatives<br />You specify<br />Bounding box of top level grid - GEOMETRY index only<br />Cells per object - number of cells recorded for matching<br />Grids <br />Four Grid Levels<br />Three Grid Densities Per Level - Low, Medium, High<br />
  17. 17. Tessellation process<br />
  18. 18. Spatial Analytics<br />demo <br />
  19. 19. Review<br />Spatial data provides answers to location-based queries<br />SQL Server supports two spatial data types<br />GEOMETRY - flat earth model<br />GEOGRAPHY - round earth model<br />Spatial data has<br />Useful properties and functions<br />Library of spatial functions<br />Three standard input and output formats<br />Spatial indexes<br />
  20. 20. Resources<br />SQL Server Spatial Data Technology Center<br />Whitepaper: Delivering Location Intelligence with Spatial Data<br />MSDN Webcast: Building Spatial Applications with SQL Server 2008, Event ID: 1032353123<br />Whitepaper: What&apos;s New for XML in SQL Server 2008<br />Whitepaper: Managing Unstructured Data with SQL Server 2008<br />
  21. 21. © 2009 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries.<br />The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.<br />