Spatial Support
Relational and Non-Relational DataRelational data uses simple data typesEach type has a single valueGeneric operations work well with the typesRelational storage/query may not be optimal forHierarchical dataSparse, variable, property bagsSome types benefit by using a custom libraryuse extended type system (complex types, inheritance)use custom storage and non-SQL APIsuse non-relational queries and indexing
Spatial DataSpatial data provides answers to location-based queriesWhich roads intersect the Microsoft campus?Does my land claim overlap yours?List all of the Italian restaurants within 5 kilometersSpatial data is part of almost every databaseIf your database includes an address
Spatial Data TypesThe Open Geospatial Consortium defines a hierarchy of spatial data typesPointLinestringPolygonMultiPointMultiLinestringMultiPolygonGeomCollectionNon-instanciable classes based on these
OGC Hierarchy of Spatial Types
SQL Server 2008 and Spatial DataSQL Server supports two spatial data typesGEOMETRY - flat earth modelGEOGRAPHY - round earth modelBoth types support all of the instanciable OGC typesInstanceOf method can distinguish between themSupports two dimension dataX and Y or Lat and Long membersZ member - elevation (user-defined semantics)M member - measure (user-defined semantics)
GEOGRAPHY RequirementsGEOGRAPHY type has additional requirementsCoordinate order is Longitude/Latitude for WKT, WKBLatitude/Longitude for GMLExterior 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 Datademo
Properties and MethodsThe spatial data types are exposed as SQLCLR UDTsUse '.' syntax for propertiesUse '.' syntax for instance methodsUse '::' syntax for static methodsMethods and Properties are case-sensitiveEach type uses a set of properties and methods that correspond to OGC functionalityWith ExtensionsGeometry implements all OGC properties and methodsGeography implements most OGC properties and methods2-D vector only implemented
InputSpatial data is stored in a proprietary binary formatInstance of the type can be NULLCan be input asWell Known binary - ST[Type]FromWKBWell Known text - ST[Type]FromTextGeography Markup Language (GML) - GeomFromGmlCan also use SQLCLR functionsParsePoint - extension functionInput from SQLCLR Type - SqlGeometry, SqlGeographySpatial builder API – Populate, IGeometrySink/IGeographySink
OutputSpatial Data Can Be Output AsWell Known binary - STAsBinaryWell Known text - STAsTextGML - AsGmlText with Z and M values - AsTextZMSQLCLR standard methodToString - returns Well Known textAs SQLCLR object - SqlGeometry, SqlGeographyOther useful formats are GeoRSS, KMLNot Directly Supported
SRIDEach instance of a spatial type must have an SRIDSpatial Reference IdentifierSRID specifies the specification used to compute itSRID 4326 - GPS, default for GEOGRAPHYSRID 4269 - usually used by ESRISRID 0 - no special reference, default for GEOMETRYMethods that use multiple spatial types (e.g., STDistance) must have types with matching SRIDElse method returns NULLGeography instance must reference one of these SRID stored in sys.spatial_reference_systems
Useful Methods/PropertiesDescriptiveSTAreaSTLengthSTCentroidRelation between two instancesSTIntersectsSTDistanceManipulationSTUnionSTSymDifferenceCollectionsSTGeometryNSTPointN
Sample QueryWhich roads intersect Microsoft’s main campus?SELECT *FROM roads WHERE roads.geom.STIntersects(@ms)=1
Extension MethodsSQL Server 2008 extends OGC methodsMakeValid - Converts to OGC valid instanceBufferWithTolerence - similar to STBuffer, allows approximation and variationReduce - Simplify a complex geography or geometryNumRings, RingN - polygons with multiple ringsGML supportZ and M properties and AsTextZM methodFilter - provides a quick intersection set but with false positivesEnvelopeCenter,EnvelopeAngle for Geography types
Spatial IndexesSQL Server Spatial Indexes Based on B-TreesUses tessellation to tile 2D to linearDivides space into grid of cells(uses Hilbert algorithm)Meant as a first level of row eliminationCan produce false positivesNever false negativesYou specifyBounding box of top level grid - GEOMETRY index onlyCells per object - number of cells recorded for matchingGrids Four Grid LevelsThree Grid Densities Per Level - Low, Medium, High
Tessellation process
Spatial Analyticsdemo
ReviewSpatial data provides answers to location-based queriesSQL Server supports two spatial data typesGEOMETRY - flat earth modelGEOGRAPHY - round earth modelSpatial data hasUseful properties and functionsLibrary of spatial functionsThree standard input and output formatsSpatial indexes
ResourcesSQL Server Spatial Data Technology Center http://www.microsoft.com/sql/2008/technologies/spatial.mspxWhitepaper: Delivering Location Intelligence with Spatial Data  http://www.microsoft.com/sql/techinfo/whitepapers/spatialdata.mspxMSDN Webcast: Building Spatial Applications with SQL Server 2008, Event ID: 1032353123Whitepaper: What's New for XML in SQL Server 2008 http://www.microsoft.com/sql/techinfo/whitepapers/sql_2008_xml.mspxWhitepaper: Managing Unstructured Data with SQL Server 2008 http://www.microsoft.com/sql/techinfo/whitepapers/sql_2008_unstructured.mspx
© 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.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.

Spatial

  • 1.
  • 2.
    Relational and Non-RelationalDataRelational data uses simple data typesEach type has a single valueGeneric operations work well with the typesRelational storage/query may not be optimal forHierarchical dataSparse, variable, property bagsSome types benefit by using a custom libraryuse extended type system (complex types, inheritance)use custom storage and non-SQL APIsuse non-relational queries and indexing
  • 3.
    Spatial DataSpatial dataprovides answers to location-based queriesWhich roads intersect the Microsoft campus?Does my land claim overlap yours?List all of the Italian restaurants within 5 kilometersSpatial data is part of almost every databaseIf your database includes an address
  • 4.
    Spatial Data TypesTheOpen Geospatial Consortium defines a hierarchy of spatial data typesPointLinestringPolygonMultiPointMultiLinestringMultiPolygonGeomCollectionNon-instanciable classes based on these
  • 5.
    OGC Hierarchy ofSpatial Types
  • 6.
    SQL Server 2008and Spatial DataSQL Server supports two spatial data typesGEOMETRY - flat earth modelGEOGRAPHY - round earth modelBoth types support all of the instanciable OGC typesInstanceOf method can distinguish between themSupports two dimension dataX and Y or Lat and Long membersZ member - elevation (user-defined semantics)M member - measure (user-defined semantics)
  • 7.
    GEOGRAPHY RequirementsGEOGRAPHY typehas additional requirementsCoordinate order is Longitude/Latitude for WKT, WKBLatitude/Longitude for GMLExterior 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
  • 8.
  • 9.
    Properties and MethodsThespatial data types are exposed as SQLCLR UDTsUse '.' syntax for propertiesUse '.' syntax for instance methodsUse '::' syntax for static methodsMethods and Properties are case-sensitiveEach type uses a set of properties and methods that correspond to OGC functionalityWith ExtensionsGeometry implements all OGC properties and methodsGeography implements most OGC properties and methods2-D vector only implemented
  • 10.
    InputSpatial data isstored in a proprietary binary formatInstance of the type can be NULLCan be input asWell Known binary - ST[Type]FromWKBWell Known text - ST[Type]FromTextGeography Markup Language (GML) - GeomFromGmlCan also use SQLCLR functionsParsePoint - extension functionInput from SQLCLR Type - SqlGeometry, SqlGeographySpatial builder API – Populate, IGeometrySink/IGeographySink
  • 11.
    OutputSpatial Data CanBe Output AsWell Known binary - STAsBinaryWell Known text - STAsTextGML - AsGmlText with Z and M values - AsTextZMSQLCLR standard methodToString - returns Well Known textAs SQLCLR object - SqlGeometry, SqlGeographyOther useful formats are GeoRSS, KMLNot Directly Supported
  • 12.
    SRIDEach instance ofa spatial type must have an SRIDSpatial Reference IdentifierSRID specifies the specification used to compute itSRID 4326 - GPS, default for GEOGRAPHYSRID 4269 - usually used by ESRISRID 0 - no special reference, default for GEOMETRYMethods that use multiple spatial types (e.g., STDistance) must have types with matching SRIDElse method returns NULLGeography instance must reference one of these SRID stored in sys.spatial_reference_systems
  • 13.
    Useful Methods/PropertiesDescriptiveSTAreaSTLengthSTCentroidRelation betweentwo instancesSTIntersectsSTDistanceManipulationSTUnionSTSymDifferenceCollectionsSTGeometryNSTPointN
  • 14.
    Sample QueryWhich roadsintersect Microsoft’s main campus?SELECT *FROM roads WHERE roads.geom.STIntersects(@ms)=1
  • 15.
    Extension MethodsSQL Server2008 extends OGC methodsMakeValid - Converts to OGC valid instanceBufferWithTolerence - similar to STBuffer, allows approximation and variationReduce - Simplify a complex geography or geometryNumRings, RingN - polygons with multiple ringsGML supportZ and M properties and AsTextZM methodFilter - provides a quick intersection set but with false positivesEnvelopeCenter,EnvelopeAngle for Geography types
  • 16.
    Spatial IndexesSQL ServerSpatial Indexes Based on B-TreesUses tessellation to tile 2D to linearDivides space into grid of cells(uses Hilbert algorithm)Meant as a first level of row eliminationCan produce false positivesNever false negativesYou specifyBounding box of top level grid - GEOMETRY index onlyCells per object - number of cells recorded for matchingGrids Four Grid LevelsThree Grid Densities Per Level - Low, Medium, High
  • 17.
  • 18.
  • 19.
    ReviewSpatial data providesanswers to location-based queriesSQL Server supports two spatial data typesGEOMETRY - flat earth modelGEOGRAPHY - round earth modelSpatial data hasUseful properties and functionsLibrary of spatial functionsThree standard input and output formatsSpatial indexes
  • 20.
    ResourcesSQL Server SpatialData Technology Center http://www.microsoft.com/sql/2008/technologies/spatial.mspxWhitepaper: Delivering Location Intelligence with Spatial Data http://www.microsoft.com/sql/techinfo/whitepapers/spatialdata.mspxMSDN Webcast: Building Spatial Applications with SQL Server 2008, Event ID: 1032353123Whitepaper: What's New for XML in SQL Server 2008 http://www.microsoft.com/sql/techinfo/whitepapers/sql_2008_xml.mspxWhitepaper: Managing Unstructured Data with SQL Server 2008 http://www.microsoft.com/sql/techinfo/whitepapers/sql_2008_unstructured.mspx
  • 21.
    © 2009 MicrosoftCorporation. 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.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.