• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Spatial Data in SQL Server
 

Spatial Data in SQL Server

on

  • 3,332 views

fIn this presentation we review the Spatial Data Capabilities in SQL Server.

fIn this presentation we review the Spatial Data Capabilities in SQL Server.

Regards,

Dr. Eduardo Castro Martinez, Microsoft SQL Server MVP

Statistics

Views

Total Views
3,332
Views on SlideShare
3,332
Embed Views
0

Actions

Likes
0
Downloads
0
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • Simple types only store one value, and work with generic methods like adding, subtracting, assignment. Relational storage isn’t optimal for storing and querying hierarchies, location based data, or coping with sparse data where the data required per row differs.Some data types benefit from having complex logic for parsing and processing, and the benefit from other programming features such as inheritance. What's more the storage requirements and indexing requirements require special processing as the storage is not byte ordered.
  • Reference: http://www.sqlskills.com/BLOGS/BOBB/post/Spatial-Data-a-niche-or-a-tool-for-the-masses.aspxSpatial data allows you to answer questions in 2 dimensions, often related to location based information. Almost every database contains location information, i.e.. Addresses, however they don’t know where those addresses are. They don’t know that 4th street is next to 3rd street and that 1st avenue intersects both of them.
  • The spatial implementation in SQL Server 2008 is based on the OGC standards.There is a hierarchy of Spatial data instances starting with a point then a line and finally a polygon. This relates to their dimensionality, a point has 0 dimensions, a line has 1 and a polygon has 2. You also have MULTI instances which contain more than one of the other types and then the collection type which can contain any of the other types
  • This is the hierarchy.Not the terms curve and surface, this implies 3 dimensions which SQL Server spatial data doesn’t support, it only supports 2 dimensions. More on that later.
  • Unlike other providers SQL splits planar and non planar data into two separate types. Geometry and geography.Non planar data is all about projections. If you think about maps of the world they have to use some form of projection to convert the elliptical surface of the earth into a flat map. In other providers they store the data in a planar projection and then perform the projection to workout the geographic calculations.We mentioned earlier that the spatial data is only in 2 dimensions. Whilst you can hold two other values Z and M for points they are not used in any of the spatial methods.
  • The geometry type covers a planar surface which is infinite your x and y can go on for ever. With the Geography type that's not the case. Latitude goes from -90 degrees to 90degrees. Longitude goes from 0 to 360.The order of how these will be parsed in the WKB (Well-Known Binary) and WKT (Well-Known Text) formats will be switched before RTM to fit in with the other products on the market.A geography shape must be contained with a single hemisphere. This doesn’t have to the north or south hemisphere but half of the earth essentially the maximum angle mad at the centre by lines to the edges cannot be greater than 180.Because the earth is a finite shape, you have to define your points in a certain order to ensure that you include the area within your shape and not the area outside of the shape. If you find you shapes are violating the hemisphere rule you might have your points going in the wrong order.
  • This demo will show how to use the SQL Server spatial data types with data from the Mondial database, which contains latitude and longitude fields for three of the tables: City, Mountain, and Island. We will use this information to construct a new column of type Geography, and then use the spatial methods of the Geography data type to perform SQL spatial queries on this data.The material for this demo can be found at the Source folder of the Spatial demo. Make sure to read the demo document to get started with this demo.
  • Reference: http://www.sqlskills.com/blogs/bobb/2007/06/24/SQLServerSystemDataTypesImplementedInNET.aspx Some new SQL Server 2008 data types are implemented/exposed as .NET UDTs. These include the spatial data types Geometry and Geography, and also HierarchyID, mentioned later in this slideset.The Date/Time series of data type ARE NOT implemented as UDT, and therefore are referred to as "new T-SQL data types".Spatial data types are implemented as CLR User defined types. YOU DO NOT HAVE TO ENABLE CLR ON THE SERVER TO USE SPATIAL DATA TYPES.You get some benefits because of this. You can call methods on the types directly. You can also call static methods on the base type by using ::. It is the later that can be used to create instances of the types.Note: You are calling methods on the types directly and so the methods and properties are case sensitive.The OGC spec defines a set of methods that should be supported, the Geometry type supports all of them. The Geography type doesn’t. It will support more by RTM but not all of them.
  • Spatial data is created from a defined format, that is either a text base format, a binary format or an XML format.WKT is the text representationWKB is the binary formGML is the XML structure.Only WKT support passing in Z and M values.WKT is more readable but as its text it doesn’t perform as well as the binary format. It is stored in the database in a proprietary binary format. If you have that format you can also create an instance from that, if you are passing data from a client application using this format is the best to use. You create an instance by assigning a string to a type, using parse, or one of the STFROM... Methods.Much of the data in the industry is in shape file format. This is a format define by ESRI and for which you will need an application to convert to a format usable by SQL ServerFor more information on the spatial builder API and an example, see http://blogs.msdn.com/isaac/archive/2008/05/30/our-upcoming-builder-api.aspx
  • You can output any of the formats that are used to create an instance.Other formats used by applications such as Google maps an virtual earth are not supported directly. You have to create these yourself more on that later.
  • SRID defines the unitof measure datum (shape of the ellipsoid) and projection. Each piece of geography data requires a spatial reference.You cannot combine data of different SRIDs, as this is like comparing apples and pears.You need to make sure you use the correct reference to ensure you calculations are correct. Lengths and areas will differ under different spatial references when dealing with geography data.There is no mechanism for translating between spatial references in SQL Server. You will need a 3rd party application to achieve that.
  • One of the killer features of spatial types is the methods they bring. You have methods that provide information about shapes.Methods that show the relationship between shapesMethods used to combine and manipulate shapes. If you’ve done set theory and venn diagrams these methods will make sense.Finally methods that provide information about the structure of the shape. Because of the limitations of SQLCLR these are not collections put rather methods that take an index to return the relevant value.
  • SQL Server extends the spatial types beyond what is in the spec. The following are the methods and there are more coming. EnveloperCentre and EnvelopeAngle provide the information used to determine the bounds of the geography type and whether it fits in a hemisphere.
  • Index is an internal table. One row represents a hierarchy of intersections of cells with in the gridEach cell that a shape intersects is recorded in the index.4 levels of grid used to provide greater accuracy. Each cell in grid is split into x more cells in the next level grid.Number of cells in each grid is defined when you create the index.
  • Top three show the level 1, Level 2 and then Level 3 and 4 intersections.If we stored all of these intersections we would have 85 matches. What we do find is that some of the cells are complete matches these don’t need to be broken down to the lower level cells. Like in Figure 4.However we still have a large number of matches, depending on the cells per object setting on the index the tessellation process will stop once it hits the limit as we have in Figure 5.This shows how imprecise the index is. It is only meant as a filter to avoid doing a very expensive calculation on all the data.
  • This demo is aimed to show the spatial capabilities of SQL Server 2008 integrated with ASP.NET. The demo relies on SQL Server to store and perform calculations on the new Geography data types; and on Virtual Earth to consume the spatial data and render it on a map.The material for this demo can be found at the Source folder of the Spatial demo. Make sure to read the demo document to get started with this demo.

Spatial Data in SQL Server Spatial Data in SQL Server Presentation Transcript