Spatial Data in SQL Server

  • 967 views
Uploaded on

In the presentation we review the Spatial Data in SQL Server. …

In the presentation we review the Spatial Data in SQL Server.

Best Regards,

Dr. Eduardo Castro Martinez, Microsoft SQL Server MVP
http://ecastrom.blogspot.com
http://tinyurl.com/comunidadwindows

More in: Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
967
On Slideshare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
0
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. 8/11/2011 SPATIAL SUPPORT IN SQL SERVER 2008 R2 Ing. Eduardo Castro Martinez ecastro@simsasys.com http://tiny.cc/comwindows http://ecastrom.blogspot.comPresentation Source• SQL Server 2008 R2 Update for Developers Training Kit • http://www.microsoft.com/download/en/details.aspx?id=16281• Building Location-Aware Applications with the SQL Server Spatial Library • Ed Katibah, Torsten Grabs and Olivier Meyer SQL Server Microsoft CorporationRelational and Non-Relational Data• Relational data uses simple data types • Each type has a single value • Generic operations work well with the types• Relational storage/query may not be optimal for • Hierarchical data • Sparse, variable, property bags• Some types • benefit by using a custom library • use extended type system (complex types, inheritance) • use custom storage and non-SQL APIs • use non-relational queries and indexing 1
  • 2. 8/11/2011Spatial Data• Spatial data provides answers to location-based queries • Which roads intersect the Microsoft campus? • Does my land claim overlap yours? • List all of the Italian restaurants within 5 kilometers• Spatial data is part of almost every database • If your database includes an addressSpatial Data Types• The Open Geospatial Consortium defines a hierarchy of spatial data types • Point • Linestring • Polygon • MultiPoint • MultiLinestring • MultiPolygon • GeomCollection • Non-instanciable classes based on theseOGC Hierarchy of Spatial Types 2
  • 3. 8/11/2011 SQL Server 2008 Spatial SummaryOVERVIEW FEATURES• 2 Spatial Data Types (CLR UDT) • 2D Vector Data Support• Comprehensive set of Spatial Methods • Open Geospatial Consortium Simple• High Performance Spatial Indexes Features for SQL compatible• Spatial Library • Supported By Major GIS Vendors• Sink/Builder APIs ESRI, Intergraph, Autodesk, Pitney Bowes, Safe, etc.• Management Studio Integration • Standard feature in SQL Server Express, Workgroup, Web, Standard, Enterprise and Developer • Support for very large spatial objectsDETAILS• Geography data type for geodetic Data• Geometry data type for planar Data• Standard spatial methods STIntersects, STBuffer, STLength, STArea, etc.• Standard spatial format support WKT, WKB and GML• Multiple spatial indexes per column• Create new CLR-based spatial methods with the Builder API• Redistributable Spatial Library SQLSysClrTypesSQL Server Spatial Library ResourcesSQL SERVER SPATIAL LIBRARYMicrosoft SQL Server System CLR TypesThe SQL Server System CLR Types package contains the componentsimplementing the geometry, geography, and hierarchy id types in SQL Server2008 R2. This component can be installed separately from the server to allowclient applications to use these types outside of the server.X86 Package(SQLSysClrTypes_x86.msi) – 3,342 KBX64 Package (SQLSysClrTypes._x64msi) – 3,459 KBIA64 Package(SQLSysClrTypes_ia64.msi) – 5,352 KBSearch for: Microsoft SQL Server 2008 Feature Pack, October 2008---CODEPLEX SQL Server Spatial ToolsCode Samples Utilizing the SQL Server Spatial LibrarySQL Server Spatial Tools – including source code for toolsSearch for: Codeplex SQL Server Spatial ToolsSQL Server 2008 and Spatial Data• SQL Server supports two spatial data types • GEOMETRY - flat earth model • GEOGRAPHY - round earth model• Both types support all of the instanciable OGC types • InstanceOf method can distinguish between them• Supports two dimension data • X and Y or Lat and Long members • Z member - elevation (user-defined semantics) • M member - measure (user-defined semantics) 3
  • 4. 8/11/2011GEOGRAPHY Requirements• GEOGRAPHY type has additional requirements• Coordinate order is • Longitude/Latitude for WKT, WKB • Latitude/Longitude for GML• 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)• A single GEOGRAPHY object cannot span more than a logical hemisphere SPATIAL DATA demoProperties and Methods• The spatial data types are exposed as SQLCLR UDTs • Use . syntax for properties • Use . syntax for instance methods • Use :: syntax for static methods • Methods and Properties are case-sensitive• Each type uses a set of properties and methods that correspond to OGC functionality • With Extensions • Geometry implements all OGC properties and methods • Geography implements most OGC properties and methods • 2-D vector only implemented 4
  • 5. 8/11/2011Input• Spatial data is stored in a proprietary binary format• Instance of the type can be NULL• Can be input as • Well Known binary - ST[Type]FromWKB • Well Known text - ST[Type]FromText • Geography Markup Language (GML) - GeomFromGml• Can also use SQLCLR functions • Parse • Point - extension function• Input from SQLCLR Type - SqlGeometry, SqlGeography• Spatial builder API – Populate, IGeometrySink/IGeographySinkOutput• Spatial Data Can Be Output As • Well Known binary - STAsBinary • Well Known text - STAsText • GML - AsGml • Text with Z and M values - AsTextZM• SQLCLR standard method • ToString - returns Well Known text• As SQLCLR object - SqlGeometry, SqlGeography• Other useful formats are GeoRSS, KML • Not Directly SupportedSRID• Each instance of a spatial type must have an SRID • Spatial Reference Identifier• SRID specifies the specification used to compute it • SRID 4326 - GPS, default for GEOGRAPHY • SRID 4269 - usually used by ESRI • SRID 0 - no special reference, default for GEOMETRY• Methods that use multiple spatial types (e.g., STDistance) must have types with matching SRID • Else method returns NULL• Geography instance must reference one of these SRID stored in sys.spatial_reference_systems 5
  • 6. 8/11/2011Useful Methods/Properties• Descriptive • STArea • STLength • STCentroid• Relation between two instances • STIntersects • STDistance• Manipulation • STUnion • STSymDifference• Collections • STGeometryN • STPointNSample Query SELECT * Which roads intersect Microsoft’s main campus? FROM roads WHERE roads.geom.STIntersects(@ms)=1Extension Methods• SQL Server 2008 extends OGC methods • MakeValid - Converts to OGC valid instance • BufferWithTolerence - similar to STBuffer, allows approximation and variation • Reduce - Simplify a complex geography or geometry • NumRings, RingN - polygons with multiple rings • GML support • Z and M properties and AsTextZM method • Filter - provides a quick intersection set but with false positives • EnvelopeCenter,EnvelopeAngle for Geography types 6
  • 7. 8/11/2011Spatial Indexes• SQL Server Spatial Indexes Based on B-Trees • Uses tessellation to tile 2D to linear • Divides space into grid of cells(uses Hilbert algorithm)• Meant as a first level of row elimination • Can produce false positives • Never false negatives• You specify • Bounding box of top level grid - GEOMETRY index only • Cells per object - number of cells recorded for matching • Grids • Four Grid Levels • Three Grid Densities Per Level - Low, Medium, HighTessellation process SPATIAL ANALYTICS demo 7
  • 8. 8/11/2011What is CEP?Complex Event Processing (CEP) is the continuous andincremental processing of event streams from multiplesources based on declarative query and pattern specificationswith near-zero latency. Database Applications Event-driven ApplicationsQuery Ad-hoc queries or Continuous standingParadigm requests queriesLatency Seconds, hours, days Milliseconds or lessData Rate Hundreds of events/sec Tens of thousands of events/sec or more request Event output input stream response streamShuttle Tracker 519,000+ data points, covering 1 day of operationReview• Spatial data provides answers to location-based queries• SQL Server supports two spatial data types • GEOMETRY - flat earth model • GEOGRAPHY - round earth model• Spatial data has • Useful properties and functions • Library of spatial functions • Three standard input and output formats • Spatial indexes 8
  • 9. 8/11/2011Resources• SQL Server Spatial Data Technology Center http://www.microsoft.com/sql/2008/technologies/spatial.mspx• Whitepaper: Delivering Location Intelligence with Spatial Data http://www.microsoft.com/sql/techinfo/whitepapers/spatialdata.mspx• MSDN Webcast: Building Spatial Applications with SQL Server 2008, Event ID: 1032353123• Whitepaper: Whats New for XML in SQL Server 2008 http://www.microsoft.com/sql/techinfo/whitepapers/sql_2008_xml.mspx• Whitepaper: Managing Unstructured Data with SQL Server 2008 http://www.microsoft.com/sql/techinfo/whitepapers/sql_2008_unstructure d.mspx© 2009 Microsof t Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademar ks and/or trademarks in the U.S. and/or other countries.The inf ormation herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. B ecause 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. 9