Presentation is loading. Please wait.

Presentation is loading. Please wait.

Module 19 Working with SQL Server® 2008 R2 Spatial Data.

Similar presentations


Presentation on theme: "Module 19 Working with SQL Server® 2008 R2 Spatial Data."— Presentation transcript:

1 Module 19 Working with SQL Server® 2008 R2 Spatial Data

2 Module Overview Introduction to Spatial Data Working with SQL Server Spatial Data Types Using Spatial Data in Applications

3 Lesson 1: Introduction to Spatial Data Target Applications Types of Spatial Data Planar vs. Geodetic OGC Object Hierarchy Spatial Reference Identifiers Demonstration 1A: Spatial Reference Systems

4 Target Applications There is a perception that spatial applications are quite separate to mainstream business applications Almost every business application can benefit from spatial data and functions  Locations of customers, stores, offices  All addresses  Intersections and distances Business Intelligence applications particularly benefit from spatial visualizations

5 Types of Spatial Data Vector vs. Raster Data  Vector – series of line segments  Raster – pixels or dots 2D, 3D, 4D

6 Planar vs. Geodetic Planar systems = Flat Earth Geodetic systems (e.g. GPS) = Round Earth

7 OGC Object Hierarchy Open Geospatial Consortium is the relevant industry body  OGC defined an object tree SQL Server data types are based on the Geometry hierarchy

8 Spatial Reference Identifiers Each spatial instance has a spatial reference identifier (SRID) SRID corresponds to a spatial reference system that is a way of performing measurements SRID 4326 is the WGS84 system (commonly implemented as the GPS system) SRID 0 is used when no system is needed (flat earth) When two spatial instances are used in a calculation, their SRIDs must match EPSG standard is used to define available SRIDs

9 Demonstration 1A: Spatial Reference Systems In this demonstration, you will see: The available Spatial Reference Identifiers The available units of measurement

10 Lesson 2: Working with SQL Server Spatial Data Types SQL Server Spatial Data System vs. User SQL CLR Types geometry Data Type geography Data Type Spatial Data Formats OGC Methods and Properties Microsoft Extensions Demonstration 2A: Spatial Data Types

11 SQL Server Spatial Data Data Types  geometry data type (flat Earth - planar)  geography data type (round Earth - geodetic) Bing Maps SDK updated SQL Server Reporting Services map control Microsoft.SqlServer.Types assembly OGC and Microsoft extension methods  ST prefix on OGC defined methods  No prefix on Microsoft extension methods

12 System vs. User SQL CLR Types System types are enabled regardless of ‘clr enabled’ setting geometry, geography, hierarchyid use large CLR object support Call properties and methods on CLR objects via: Calling MethodExample Instance.PropertyNewYork.STArea Instance.Method()Border.MakeValid() Type::StaticMethod()geometry::STGeomFromText() SELECT name, assembly_id, permission_set_desc, is_user_defined FROM sys.assemblies; SELECT name, assembly_id, permission_set_desc, is_user_defined FROM sys.assemblies;

13 geometry Data Type geometry; = geometry::STGeomFromText( 'POLYGON ((10 10, 10 30, 40 40, 20 10, 10 10))',0); geometry; = geometry::STGeomFromText( 'POLYGON ((10 10, 10 30, 40 40, 20 10, 10 10))',0); 2D data type STX and STY properties SRID is not relevant – defaults to zero Comprehensive OGC coverage

14 geography Data Type SELECT Border FROM dbo.Countries WHERE CountryName = 'Italy'; SELECT Border FROM dbo.Countries WHERE CountryName = 'Italy'; 2D data type Long and Lat properties Order is important for polygons Single value cannot span more than a single hemisphere

15 Spatial Data Formats Internal binary format of the spatial types not normally used directly Need to be able to input/output as strings Parsing  WKT – Well known text  WKB – Well known binary  GML – Geography markup language (XML variant)  Parse() assumes WKT Output  Options to output above formats including Z and M values  ToString() provides WKT

16 OGC Methods and Properties Common methods Common Collection Properties MethodDescription STDistanceThe distance between two shapes STIntersectsThe shape formed by the intersection of two shapes STAreaThe area of a shape STLengthThe length of a shape (for a polygon, the sum of the lengths of all sides) STUnionThe shape formed by uniting two shapes STBufferThe shape formed by providing a buffer region around a shape PropertiesDescription STPointNReturns a specific point in a collection of points STGeometryNReturns a specific geometric shape from a collection of geometries

17 Microsoft Extensions Microsoft has provided a number of extensions to the OGC defined methods and properties Common extensions: MethodDescription MakeValidReturns a valid shape from a potentially invalid shape ReduceReduces the complexity of a shape without changing its basic shape IsNullReturns if an object is NULL AsGmlReturns the object coded as GML (Geographic Markup Language) BufferWithToleranceReturns a buffer around an object but uses a tolerance value to allow for rounding errors

18 Demonstration 2A: Spatial Data Types In this demonstration, you will see how to work with SQL Server spatial data types

19 Lesson 3: Using Spatial Data in Applications Performance Issues in Spatial Queries Tessellation Process Spatial Indexes Implementing Spatial Indexes geometry Methods Supported by Spatial Indexes geography Methods Supported by Spatial Indexes Extending SQL Server Spatial Demonstration 3A: Spatial Data in Applications

20 Performance Issues in Spatial Queries Spatial queries can involve a large number of data points Imagine trying to locate streets that intersect your suburb or region Executing methods like STIntersects for a large number of points is slow How could you simplify the problem? Spatial indexes are designed to help avoid these unnecessary calculations

21 Tessellation Process Spatial indexes allow us to break large problems into ever smaller problems as we move through relevant levels SQL Server uses a four-level grid Tessellation rules are applied to eliminate areas not touched by the shape

22 Spatial Indexes Spatial indexes in SQL Server work in a two-phase method Primary filter  Finds all possible candidates  False positives are ok at this stage  No false negatives Secondary filter  Removes false positives  Applies the spatial method (that is, STIntersects) from the original predicate in your WHERE clause Filter method shows effectiveness of the Primary filter

23 Implementing Spatial Indexes CREATE SPATIAL INDEX IX_ObjectOutline_Shape ON dbo.ObjectOutline (Shape) WITH (BOUNDING_BOX=(0,0,512,512), GRIDS =(LOW,LOW,LOW,LOW)); CREATE SPATIAL INDEX IX_ObjectOutline_Shape ON dbo.ObjectOutline (Shape) WITH (BOUNDING_BOX=(0,0,512,512), GRIDS =(LOW,LOW,LOW,LOW)); Use the CREATE SPATIAL INDEX statement  geometry has a BOUNDING_BOX  ONLINE builds are not supported Can be useful to index one column more than once with different tessellation levels Table must have a clustered primary key

24 geometry Methods Supported by Spatial Indexes Not all methods benefit from spatial indexes Not all predicate forms benefit from spatial indexes Supported forms: geometry1.STContains(geometry2) = 1 geometry1.STDistance(geometry2) < number geometry1.STDistance(geometry2) <= number geometry1.STEquals(geometry2)= 1 geometry1.STIntersects(geometry2)= 1 geometry1.STOverlaps(geometry2) = 1 geometry1.STTouches(geometry2) = 1 geometry1.STWithin(geometry2)= 1

25 geography Methods Supported by Spatial Indexes Not all methods benefit from spatial indexes Not all predicate forms benefit from spatial indexes Supported forms: geography1.STIntersects(geography2)= 1 geography1.STEquals(geography2)= 1 geography1.STDistance(geography2) < number geography1.STDistance(geography2) <= number

26 Extending SQL Server Spatial Functions from CodePlex  IsValidGeographyFromGeometry, IsValidGeographyFromText, MakeValidGeographyFromGeography, MakeValidGeographyFromText, ConvexHullGeography, ConvexHullGeographyFromText, DensifyGeography, InterpolateBetweenGeog, InterpolateBetwenGeom, LocateAlongGeog, LocateAlongGeom, ShiftGeometry, VacuousGeographyToGeometry, VacuousGeometryToGeography Types from CodePlex  SqlProjection (Abers Equal Area, Equirectangular, Lambert Conformal Conic, Mercator, Oblique Mercator, Transverse Mercator, Gnomonic)  AffineTransform Aggregates from CodePlex  GeographyUnionAggregate, GeometryEnvelopeAggregate

27 Demonstration 3A: Spatial Data in Applications In this demonstration you will see how to use SQL Server spatial data to solve some business questions

28 Lab 19: Working with SQL Server Spatial Data Exercise 1: Familiarity With Geometry Data Type Exercise 2: Adding Spatial Data to an Existing Table Challenge Exercise 3: Business Application of Spatial Data (Only if time permits) Logon information Estimated time: 45 minutes

29 Lab Scenario Your organization has only recently begun to acquire spatial data within its databases. The new Marketing database was initially designed prior to the company beginning to implement spatial data. One of the developers has provided a table of the locations where prospects live. It is called Marketing.ProspectLocation. A second developer has added columns to it for Latitude and Longitude and geocoded the addresses. You will make some changes to the system to help support the need for spatial data.

30 Lab Review Where would you imagine you might use spatial data in your own business applications?

31 Module Review and Takeaways Review Questions Best Practices


Download ppt "Module 19 Working with SQL Server® 2008 R2 Spatial Data."

Similar presentations


Ads by Google