Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Sql server 2008 r2 spatial data whitepaper


Published on

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Sql server 2008 r2 spatial data whitepaper

  1. 1. Delivering Location Intelligencewith Spatial Data<br />White Paper<br />Published: August 2007<br />Summary: The growing ability of businesses and consumers to quickly absorb large volumes of data, together with the increased availability of digital maps and spatially-enabled applications has created an unprecedented opportunity to incorporate geographic factors into decision making processes and analysis. The new spatial support in Microsoft SQL Server™ 2008 R2 can help you to make better decisions through visual analysis of location data that can be stored and manipulated in a SQL Server database...<br />Contents<br /> TOC o "1-2" Introduction PAGEREF _Toc205575287 h 1<br />Comprehensive Spatial Support PAGEREF _Toc205575288 h 2<br />Spatial Models PAGEREF _Toc205575289 h 2<br />SQL Server 2008 Spatial Data Types PAGEREF _Toc205575290 h 4<br />Spatial Data Type Methods PAGEREF _Toc205575291 h 4<br />High Performance Spatial Data Capabilities PAGEREF _Toc205575292 h 6<br />Built-in Spatial Views PAGEREF _Toc205575293 h 7<br />Location-Aware Application Extensibility PAGEREF _Toc205575294 h 8<br />Importing Spatial Data PAGEREF _Toc205575295 h 8<br />Using Spatial Data PAGEREF _Toc205575296 h 9<br />Conclusion PAGEREF _Toc205575297 h 10<br />Introduction<br />Today’s information workers and consumers deal with massive amounts of information of different kinds, from traditional tables of business data in spreadsheets and databases, to online media-based data such as video, photographs, and music. The recent trend towards mash up solutions in which information and content from multiple sources is combined to create versatile online applications is indicative of the way that computer users use highly integrated solutions to make sense of the vast amount of information that is available to them.<br />At the same time, advances in technology have led to the proliferation of geographical services and devices, including online mapping solutions such as Microsoft® Virtual Earth™, and inexpensive global positioning system (GPS) solutions. Technology that was once the preserve of geographic information system (GIS) specialists is now widely available to everyone.<br />These two factors bring new expectations and opportunities for software applications. The ubiquity of geographical services, and the increasing sophistication with which users consume data means that spatial information is just another component to be incorporated into a solution and used as a basis for making better decisions and providing higher value services.<br />Spatial data can be used in many ways, as the following list of examples demonstrates:<br />A retailer Web site can display the locations of all stores as pins on a map, and find the nearest store to a given zip code<br />A sales manager can define geographic sales regions, and use them to match customers to sales representatives and perform analysis of sales performance.<br />An architect can create plans for a new building, and overlay those plans onto a map of the proposed site.<br />A driver can find the distance between two locations, and plan a route.<br />A real estate agent can quickly identify properties that match a client’s requirements, such as houses over 20,000 square feet in size that are on the shore of Lake Washington.<br />A mobile application can find all gas stations within 10 miles of a given location.<br />These examples represent only a few of the possibilities created by the integration of spatial data into software applications.<br />SQL Server 2008 R2 provides support for geographical data through the inclusion of new spatial data types, which you can use to store and manipulate location-based information. The spatial support in SQL Server 2008 R2 can help users to make better decisions through analysis of location data in scenarios such as:<br />Consumer-focused location-based information<br />Customer-base management and development<br />Environmental-related data impact, analysis, and planning<br />Financial and economic analysis in communities<br />Government-based planning and development analysis<br />Market segmentation and analysis<br />Scientific research study design and analysis<br />Real-estate development and analysis<br />This whitepaper provides a high-level introduction to the comprehensive spatial data support in SQL Server 2008 R2, and describes its high-performance spatial capabilities and location-aware application extensibility.<br />Comprehensive Spatial Support<br />SQL Server 2008 R2 provides comprehensive spatial support through new data types. To understand how you can use these data types to store location-based data, you first need to understand a little of how spatial data, and in particular geospatial data, works.<br />Spatial Models<br />Spatial data is used to represent points, lines, and areas on a surface. Most commonly, these elements relate to actual physical locations on Earth, so can be described a geospatial data. Most of us are familiar with this concept through the use of globes and maps, which generally show multiple geographic features and their relative locations.<br />Geodetic Spatial Models<br />The problem with describing a location on a planetary surface is that planets are not flat. Earth is a very complex object that can be reasonably approximated by an oblate spheroid, a (slightly) flattened sphere. An accurate representation of the Earth is usually manifested as a globe, in which locations on the surface of the planet are described in terms of their latitude and longitude, which is measured in degrees from the equator and the international date-line respectively. <br />This approach to modeling geographic locations is called a geodetic model, and provides an accurate way to define locations and objects on a globe as shown in Figure 1. There are a number of different geodetic models in use throughout the world, including the Airy 1830 ellipsoid used in the United Kingdom’s Ordnance Survey geographic system, and the WGS84 ellipsoid used by the world’s GPS solutions.<br />Figure 1: A geodetic model<br />Planar Spatial Models<br />While a geodetic model provides the most accurate way to represent geographic features, working with an ellipsoid and taking planetary curvature into account when calculating distances was extremely difficult before computing when people had to work with flat maps. Historically, it has been much easier to work with two-dimensional surfaces, or planes, so it is common to find location-based data represented in various flat (planar) models. To work with geospatial data on a flat two dimensional surface, a projection is created to flatten the geographical objects on the spheroid. As with geodetic models, there are many mathematical models used to project the geographical features of Earth onto a flat surface, including the Mercator projection, the Peters projection, and the Lambert Conformal Conic projection. Figure 2 shows a planar model of the Earth based on the Mercator projection.<br />Figure 2: A planar model<br />Regardless of which projection is used, converting geographical data from a spheroid to a flat surface always results in some distortion of the shape, size, or position (or all three) of the geographic features in the resulting map, which is why in the projection shown in Figure 2, Greenland is shown as being almost the same size as the United States of America, even though in reality its land mass is much smaller. Generally, the larger the surface area being projected, the more distortion occurs – with the features at the furthest edges of the map exhibiting more distortion than those at the center. For this reason, planar models work best for small geographical areas such as individual countries, states, and towns, or for non-projected spatial surfaces such as interior floor plans.<br />SQL Server 2008 R2 Spatial Data Types<br />SQL Server 2008 R2 provides the geography data type for geodetic spatial data, and the geometry data type for planar spatial data. Both are implemented as Microsoft .NET Framework Common Language Runtime (CLR) types, and can be used to store different kinds of geographical elements such as points, lines, and polygons. Both data types provide properties and methods that you can use to perform spatial operations such as calculating distances between locations and finding geographical features that intersect one another (such as a river that flows through a town.)<br />The geography Data Type<br />The geography data type provides a storage structure for spatial data that is defined by latitude and longitude coordinates. Typical uses of this kind of data include defining roads, buildings, or geographical features as vector data that can be overlaid onto a raster-based map that takes into account the curvature of the Earth, or for calculating true great circle distances and trajectories for air transport where the distortion inherent in a planar model would cause unacceptable levels of inaccuracy.<br />The geometry Data Type<br />The geometry data type provides a storage structure for spatial data that is defined by coordinates on an arbitrary plane. This kind of data is commonly used in regional mapping systems, such as the state plane system defined by the United States government, or for maps and interior floor plans where the curvature of the Earth does not need to be taken into account.<br />The geometry data type provides properties and methods that are aligned with the Open Geospatial Consortium (OGC) Simple Features Specification for SQL and enable you to perform operations on geometric data that produce industry-standard behavior.<br />Spatial Data Type Methods<br />Both spatial data types in SQL Server 2008 R2 provide a comprehensive set of instance and static methods that you can use to perform queries and operations on spatial data. For example, the following code sample creates two tables for a city mapping application; one contains geometry values for the districts in the city, and the other contains geometry values for the streets in the city. A query then retrieves the city streets and the districts that they intersect.<br />CREATE TABLE Districts <br /> (DistrictId int IDENTITY (1,1),<br />DistrictName nvarchar(20),<br /> DistrictGeo geometry);<br />GO<br />CREATE TABLE Streets <br /> (StreetId int IDENTITY (1,1),<br />StreetName nvarchar(20),<br /> StreetGeo geometry);<br />GO<br />INSERT INTO Districts (DistrictName, DistrictGeo)<br />VALUES ('Downtown',<br />geometry::STGeomFromText<br />('POLYGON ((0 0, 150 0, 150 150, 0 150, 0 0))', 0));<br />INSERT INTO Districts (DistrictName, DistrictGeo)<br />VALUES ('Green Park',<br />geometry::STGeomFromText<br />('POLYGON ((300 0, 150 0, 150 150, 300 150, 300 0))', 0));<br />INSERT INTO Districts (DistrictName, DistrictGeo)<br />VALUES ('Harborside',<br />geometry::STGeomFromText<br />('POLYGON ((150 0, 300 0, 300 300, 150 300, 150 0))', 0));<br />INSERT INTO Streets (StreetName, StreetGeo)<br />VALUES ('First Avenue',<br />geometry::STGeomFromText<br />('LINESTRING (100 100, 20 180, 180 180)', 0))<br />GO<br />INSERT INTO Streets (StreetName, StreetGeo)<br />VALUES ('Mercator Street', <br />geometry::STGeomFromText<br />('LINESTRING (300 300, 300 150, 50 50)', 0))<br />GO<br />SELECT StreetName, DistrictName<br />FROM Districts d, Streets s<br />WHERE s.StreetGeo.STIntersects(DistrictGeo) = 1<br />ORDER BY StreetName<br />The results from this query are shown in the following table.<br />Query Results<br />StreetNameDistrictNameFirst AvenueDowntownFirst AvenueHarborsideMercator StreetDowntownMercator StreetGreen ParkMercator StreetHarborside<br />High Performance Spatial Data Capabilities<br />The spatial data types in SQL Server 2008 R2 are implemented as CLR system types. SQL Server 2008 R2 increases the maximum size for CLR types in the database from the 8000 bytes limit that was imposed in SQL Server 2005 to 2GB, which makes it possible to store extremely complex spatial data elements, such as polygons, which are defined by a large number of points.<br />By storing spatial data in relational tables, SQL Server 2008 R2 makes it possible to combine spatial data with any other kind of business data; this removes the need to maintain a separate, dedicated spatial data store and enables high performance queries that do not need to combine data from multiple external sources.<br />Performance of queries against spatial data is further enhanced by the inclusion of spatial index support in SQL Server 2008 R2. You can index spatial data with an adaptive multi-level grid index that is integrated into the SQL Server database engine. Spatial indexes consist of a grid-based hierarchy in which each level of the index subdivides the grid sector that is defined in the level above. A conceptual model of a spatial index is shown in Figure 3.<br />Figure 3: A spatial index<br />The SQL Server query optimizer makes cost-based decisions on which indexes to use for a given query, and because spatial indexes are an integral part of the database engine, SQL Server can make cost-based decisions about whether or not to use a particular spatial index, just like any other index.<br />Built-in Spatial Views<br />Use the new spatial results tab to easily view spatial query results directly from within SQL Server Management Studio. This tab offers simple projection and zoom/pan capabilities for quick investigation.<br />Figure 4: A spatial views tab within Management Studio<br />Location-Aware Application Extensibility<br />The geography and geometry data types are supported in the various SQL Server 2008 R2 editions that scale from single-user desktop applications to enterprise-level data stores and enable you to build geospatial solutions of any scale. This broad support brings spatial data capabilities to all kinds of applications without the need for expensive proprietary geospatial solutions.<br />Importing Spatial Data<br />The geography and geometry data types include methods for importing and exporting data in the Well Known Text (WKT) and Well Known Binary (WKB) formats for geographic data that are defined by the OGC, as well as the commonly used Geographic Markup Language (GML) format, which makes it easy to import geographic data from source that supports these standards. Geographical data is readily available from a number of government and commercial sources, and can be exported relatively easily from many existing GIS applications and GPS systems. Microsoft maintains close relationships with a number of third-party GIS vendors and geospatial data solution providers, which helps to ensure strong compatibility between SQL Server 2008 R2 and a wide range of industry-proven tools and utilities for importing, exporting, and manipulating spatial data.<br />Using Spatial Data<br />As already demonstrated in this whitepaper, the geography and geometry data types provide methods that you can use to perform spatial operations on your data. Because these data types are implemented as .NET CLR types, you can easily create client applications that consume spatial data from SQL Server through Microsoft data programmability technologies and use client-side managed code to call methods on instances of the spatial types. This enables you to build powerful applications to work with your spatial data and integrate it with other location-aware applications and services such as Virtual Earth.<br />For example, Figure 4 shows an application in which spatial data from SQL Server 2008 R2 is integrated with Virtual Earth. The application shows the census blocks in a ZIP Code region with the number of restaurants computed. The number of restaurants in each block, relative to the size of the block yields a density value, which appears in the display as a region shaded from white (low density) to red (highest density).<br />Figure 5: Spatial data integrated with Virtual Earth<br />Conclusion<br />As the integration of geospatial information into applications becomes more prevalent, application developers will increasingly require database systems that can store and manipulate spatial data. With the introduction of the geography and geometry data types, SQL Server 2008 R2 provides a comprehensive, high-performance, and extensible data storage solution for spatial data, and enables organizations of any scale to integrate geospatial features into their applications and services.<br />For more information:<br />Microsoft SQL Server 2008<br />Please give us your feedback:<br />Did this paper help you? Tell us on a scale of 1 (poor) to 5 (excellent), how would you rate this paper and why have you given it this rating? For example:<br />Are you giving it a high rating because it has good examples, excellent screenshots, clear writing, or another reason? <br />Are you giving it a low rating because it has poor examples, fuzzy screenshots, unclear writing?<br />This feedback will help us improve the quality of white papers we release. Send feedback.<br />