<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Stacia Misner : Spatial Data</title><link>http://sqlblog.com/blogs/stacia_misner/archive/tags/Spatial+Data/default.aspx</link><description>Tags: Spatial Data</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>Multi-State Maps in Reporting Services</title><link>http://sqlblog.com/blogs/stacia_misner/archive/2011/03/24/34379.aspx</link><pubDate>Thu, 24 Mar 2011 13:33:17 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:34379</guid><dc:creator>smisner</dc:creator><slash:comments>2</slash:comments><comments>http://sqlblog.com/blogs/stacia_misner/comments/34379.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/stacia_misner/commentrss.aspx?PostID=34379</wfw:commentRss><description>&lt;p&gt;In SQL Server 2008 R2 Reporting Services, you can now create maps for reports using the built-in map gallery of the United States or individual states, ESRI shapefiles, or a spatial query. In a &lt;a title="SQL Server 2008 R2 Reporting Services – The World is But a Stage (T-SQL Tuesday #006)" href="http://blog.datainspirations.com/2010/05/11/sql-server-2008-r2-reporting-services-the-word-is-but-a-stage-t-sql-tuesday-006/" target="_blank"&gt;previous post&lt;/a&gt;, I explained how to obtain an ESRI shapefile for another country and convert it into spatial data so that you can have other maps available in the map gallery. In this post, I'll show you how to create one map from multiple ESRI shapefiles. Whether you add it to the map gallery or not is up to you!&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Obtaining State Shapefiles&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;To start, the process is similar to the one I described in my previous post on working with spatial data. This time my goal is to create a map of two states - Nevada and California. The best place to download free shapefiles for US states is the &lt;a href="http://www.census.gov/geo/www/tiger/tgrshp2010/tgrshp2010.html" target="_blank"&gt;U.S. Census Bureau&lt;/a&gt; where I used the link to download by state. I found the Nevada directory and then used the topmost directory 32 where there many files to download. I chose tl_2010_32_state00.zip. Similarly in the California directory, I used the topmost directory to find and download tl_2010_06_state00.zip.&amp;#160; Then I extracted each zip file to its own directory on my computer. They each contain a variety of files, including SHP and DBF files that I could use for a map using the ESRI shapefile data source option if I want to create a separate map for each state. But I want to combine these maps, so my mission is not yet complete.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Converting Shapefiles to SQL Spatial Data&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;My next step is to use a tool called &lt;a href="http://www.sharpgis.net/page/SQL-Server-2008-Spatial-Tools.aspx" target="_blank"&gt;Shape2SQL&lt;/a&gt; to extract the spatial data from the shapefile into a SQL Server table. Pinal Dave (&lt;a href="http://blog.sqlauthority.com/" target="_blank"&gt;blog&lt;/a&gt;|&lt;a href="http://twitter.com/PinalDave" target="_blank"&gt;twitter&lt;/a&gt;) has a &lt;a title="SQL SERVER – World Shapefile Download and Upload to Database – Spatial Database" href="http://blog.sqlauthority.com/2010/03/30/sql-server-world-shapefile-download-and-upload-to-database-spatial-database/" target="_blank"&gt;tutorial &lt;/a&gt;explaining how to do that. I had the same experience that I described in my last post - I had to clear the Create Spatial Index checkbox to get the table to load properly for the first state. When I loaded the second state, I had to clear the Replace Existing Table checkbox. Now I have both states in a table called State, as shown below, with a geom column having the SQL Geometry data type.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.datainspirations.com/wp-content/uploads/2011/03/StateTable.jpg"&gt;&lt;img class="alignnone size-full wp-image-390" title="StateTable" alt="" src="http://blog.datainspirations.com/wp-content/uploads/2011/03/StateTable.jpg" width="623" height="27" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;Creating the Multi-State Map&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;Now that I have my spatial data in a table, I'm ready to create the map. In Business Intelligence Development Studio, I added the map to my report which launched the Map Wizard and then I used the following steps:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;On the &lt;strong&gt;Choose a source of spatial data&lt;/strong&gt; page of the wizard, select &lt;strong&gt;SQL Server spatial query&lt;/strong&gt;, and click &lt;strong&gt;Next&lt;/strong&gt;. &lt;/li&gt;    &lt;li&gt;On the &lt;strong&gt;Choose a dataset with SQL Server spatial data&lt;/strong&gt; page, select &lt;strong&gt;Add a new dataset with SQL Server spatial data&lt;/strong&gt;. &lt;/li&gt;    &lt;li&gt;On the &lt;strong&gt;Choose a connection to a SQL Server spatial data source&lt;/strong&gt; page, select &lt;strong&gt;New&lt;/strong&gt;. &lt;/li&gt;    &lt;li&gt;In the &lt;strong&gt;Data Source Properties&lt;/strong&gt; dialog box, on the &lt;strong&gt;General&lt;/strong&gt; page, add a connecton string like this (changing your server name if necessary):       &lt;br /&gt;&lt;code&gt;Data Source=(local);Initial Catalog=SpatialData&lt;/code&gt; &lt;/li&gt;    &lt;li&gt;Click &lt;strong&gt;OK&lt;/strong&gt; and then click &lt;strong&gt;Next&lt;/strong&gt;. &lt;/li&gt;    &lt;li&gt;On the &lt;strong&gt;Design a query&lt;/strong&gt; page, add a query for the country shape, like this:       &lt;br /&gt;&lt;code&gt;SELECT&amp;#160; NAME00, geom FROM State&lt;/code&gt; &lt;/li&gt;    &lt;li&gt;Click &lt;strong&gt;Next&lt;/strong&gt;. The map wizard reads the spatial data and renders it for you on the &lt;strong&gt;Choose spatial data and map view options&lt;/strong&gt; page, as shown below. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;&lt;a href="http://blog.datainspirations.com/wp-content/uploads/2011/03/NevadaCalifornia.jpg"&gt;&lt;img class="alignnone size-full wp-image-391" title="NevadaCalifornia" alt="" src="http://blog.datainspirations.com/wp-content/uploads/2011/03/NevadaCalifornia.jpg" width="594" height="338" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Of course, you can use these technique with any shapefiles that you can locate. It's not limited to the United States. For example, if you want to create a map of multiple European countries or a combination of states in India, you could use a similar process by downloading shapefiles from either the &lt;a href="http://www.gadm.org/country" target="_blank"&gt;Global Administrative Areas spatial database&lt;/a&gt; or the &lt;a href="http://www.naturalearthdata.com/downloads/" target="_blank"&gt;Natural Earth database&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=34379" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/stacia_misner/archive/tags/SSRS/default.aspx">SSRS</category><category domain="http://sqlblog.com/blogs/stacia_misner/archive/tags/Spatial+Data/default.aspx">Spatial Data</category></item><item><title>SQL Server 2008 R2 Reporting Services - The World is But a Stage (T-SQL Tuesday #006)</title><link>http://sqlblog.com/blogs/stacia_misner/archive/2010/05/11/25042.aspx</link><pubDate>Tue, 11 May 2010 19:30:00 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:25042</guid><dc:creator>smisner</dc:creator><slash:comments>0</slash:comments><comments>http://sqlblog.com/blogs/stacia_misner/comments/25042.aspx</comments><wfw:commentRss>http://sqlblog.com/blogs/stacia_misner/commentrss.aspx?PostID=25042</wfw:commentRss><description>&lt;p&gt;Host Michael Coles (&lt;a target="_blank" title="Michael Cole's blog" href="http://sqlblog.com/blogs/michael_coles/default.aspx"&gt;blog&lt;/a&gt;|&lt;a target="_blank" title="@Sergeant_SQL" href="http://twitter.com/Sergeant_SQL"&gt;twitter&lt;/a&gt;) has selected &lt;a target="_blank" title="MSDN: Working with Large Value Types" href="http://msdn.microsoft.com/en-us/library/a1904w6t(VS.80).aspx"&gt;LOB data&lt;/a&gt; as the topic for this month's &lt;a target="_blank" title="What About Blob?" href="http://sqlblog.com/blogs/michael_coles/archive/2010/05/03/t-sql-tuesday-006-what-about-blob.aspx"&gt;T-SQL Tuesday&lt;/a&gt;, so I'll take this opportunity to post an overview of reporting with spatial data types. As part of my work with &lt;a target="_blank" title="MSDN: What's New (Reporting Services)" href="http://msdn.microsoft.com/en-us/library/ms170438(v=SQL.105).aspx"&gt;SQL Server 2008 R2 Reporting Services&lt;/a&gt;, I've been exploring the use of spatial data types in the new &lt;a target="_blank" title="MSDN: Working with Map Report Items" href="http://msdn.microsoft.com/en-us/library/ee210581(v=SQL.105).aspx"&gt;map data region&lt;/a&gt;. You can create a map using any of the following data sources:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Map Gallery - a set of Shapefiles for the United States only that ships with Reporting Services&lt;/li&gt;&lt;li&gt;ESRI Shapefile - a .shp file conforming to the &lt;a target="_blank" title="ESRI: Getting Started for Developers" href="http://www.esri.com/getting-started/developers/index.html"&gt;Environmental Systems Research Institute, Inc. (ESRI)&lt;/a&gt; shapefile spatial data format&lt;/li&gt;&lt;li&gt;&lt;a target="_blank" title="MSDN: Types of Spatial Data" href="http://msdn.microsoft.com/en-us/library/bb964711(v=SQL.105).aspx"&gt;SQL Server spatial data&lt;/a&gt; - a query that includes SQLGeography or SQLGeometry data types&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Rob Farley (&lt;a target="_blank" title="Rob Farley's Blog" href="http://sqlblog.com/blogs/rob_farley/default.aspx"&gt;blog&lt;/a&gt;|&lt;a target="_blank" title="@rob_farley" href="http://twitter.com/rob_farley"&gt;twitter&lt;/a&gt;) points out today in &lt;a target="_blank" title="Spatial data from shapefiles (for T-SQL Tuesday #006)" href="http://sqlblog.com/blogs/rob_farley/archive/2010/05/11/spatial-data-from-shapefiles-for-t-sql-tuesday-006.aspx"&gt;his T-SQL Tuesday post&lt;/a&gt; that using the SQL geography field is a preferable alternative to ESRI shapefiles for storing spatial data in SQL Server. So how do you get spatial data? If you don't already have a GIS application in-house, you can find a variety of sources. Here are a few to get you started:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;US Census Bureau Website, &lt;a href="http://www.census.gov/geo/www/tiger/"&gt;http://www.census.gov/geo/www/tiger/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Global Administrative Areas Spatial Database, &lt;a href="http://biogeo.berkeley.edu/gadm/"&gt;http://biogeo.berkeley.edu/gadm/&lt;/a&gt;&lt;/li&gt;&lt;li&gt;Digital Chart of the World Data Server, &lt;a href="http://www.maproom.psu.edu/dcw/"&gt;http://www.maproom.psu.edu/dcw/&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;In a recent &lt;a target="_blank" title="SQL SERVER – World Shapefile Download and Upload to Database – Spatial Database" href="http://blog.sqlauthority.com/2010/03/30/sql-server-world-shapefile-download-and-upload-to-database-spatial-database/"&gt;post&lt;/a&gt; by Pinal Dave (&lt;a target="_blank" title="Journey to SQL Authority with Pinal Dave" href="http://blog.sqlauthority.com/"&gt;blog&lt;/a&gt;|&lt;a title="@pinaldave" href="http://twitter.com/pinaldave"&gt;twitter&lt;/a&gt;), you can find a link to free shapefiles for download and a tutorial for using &lt;a title="Shape2SQL" href="http://www.sharpgis.net/page/SQL-Server-2008-Spatial-Tools.aspx"&gt;Shape2SQL&lt;/a&gt;, a free tool to convert shapefiles into SQL Server data.&lt;/p&gt;&lt;p&gt;In my post today, I'll show you how to use combine spatial data that describes boundaries with spatial data in AdventureWorks2008R2 that identifies stores locations to embed a map in a report.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Preparing the spatial data&lt;/b&gt;&lt;/p&gt;&lt;p&gt;First, I downloaded Shapefile data for the &lt;a target="_blank" title="Spatial Data Download - France - Administrative Areas from DIVA-GIS" href="http://www.diva-gis.org/data/adm/FRA_adm.zip"&gt;administrative boundaries in France&lt;/a&gt; and unzipped the data to a local folder. Then I used Shape2SQL to upload the data into a SQL Server database called Spatial. I'm not sure of the reason why, but I had to uncheck the option to create a spatial index to upload the data. Otherwise, the upload appeared to run successfully, but no table appeared in my database.&lt;/p&gt;&lt;p&gt;The zip file that I downloaded contained three files, but I didn't know what was in them until I used Shape2SQL to upload the data into tables. Then I found that FRA_adm0 contains spatial data for the country of France, FRA_adm1 contains spatial data for each region, and FRA_adm2 contains spatial data for each department (a subdivision of region).&lt;/p&gt;&lt;p&gt;Next I prepared my SQL query containing sales data for fictional stores selling Adventure Works products in France. The Person.Address table in the AdventureWorks2008R2 database (which you can &lt;a target="_blank" title="AdventureWorks 2008 R2 databases" href="http://msftdbprodsamples.codeplex.com/releases/view/24854"&gt;download from Codeplex&lt;/a&gt;) contains a SpatialLocation column which I joined - along with several other tables - to the Sales.Customer and Sales.Store tables. I'll be able to superimpose this data on a map to see where these stores are located. I included the SQL script for this query (as well as the spatial data for France) in the &lt;a target="_blank" title="Spatial Data in SSRS project" href="http://datainspirations.com/uploads/SpatialDataInSSRS.zip"&gt;downloadable project&lt;/a&gt; that I created for this post.&lt;/p&gt;&lt;p&gt;&lt;b&gt;Step 1: Using the Map Wizard to Create a Map of France&lt;/b&gt;&lt;/p&gt;&lt;p&gt;You can build a map without using the wizard, but I find it's rather useful in this case. Whether you use Business Intelligence Development Studio (BIDS) or Report Builder 3.0, the map wizard is the same. I used BIDS so that I could create a project that includes all the files related to this post. To get started, I added an empty report template to the project and named it France Stores. Then I opened the Toolbox window and dragged the Map item to the report body which starts the wizard. Here are the steps to perform to create a map of France:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;On the &lt;b&gt;Choose a source of spatial data&lt;/b&gt; page of the wizard, select &lt;b&gt;SQL Server spatial query&lt;/b&gt;, and click &lt;b&gt;Next&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;On the &lt;b&gt;Choose a dataset with SQL Server spatial data&lt;/b&gt; page, select &lt;b&gt;Add a new dataset with SQL Server spatial data&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;On the &lt;b&gt;Choose a connection to a SQL Server spatial data source&lt;/b&gt; page, select &lt;b&gt;New&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;In the &lt;b&gt;Data Source Properties&lt;/b&gt; dialog box, on the &lt;b&gt;General&lt;/b&gt; page, add a connecton string like this (changing your server name if necessary):&lt;br&gt;&lt;code&gt;Data Source=(local);Initial Catalog=Spatial&lt;/code&gt;&lt;/li&gt;&lt;li&gt;Click &lt;b&gt;OK&lt;/b&gt; and then click &lt;b&gt;Next&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;On the &lt;b&gt;Design a query&lt;/b&gt; page, add a query for the country shape, like this:&lt;br&gt;select * from fra_adm1&lt;/li&gt;&lt;li&gt;Click &lt;b&gt;Next&lt;/b&gt;. The map wizard reads the spatial data and renders it for you on the &lt;b&gt;Choose spatial data and map view options&lt;/b&gt; page, as shown below.&lt;br&gt;&lt;img style="WIDTH:526px;DISPLAY:inline;HEIGHT:431px;" height="622" alt="Map Wizard with France regional boundaries" width="849" src="http://sqlblog.com/blogs/stacia_misner/1_France_MapWizard.png"&gt;&lt;br&gt;You have the option to add a Bing Maps layer which shows surrounding countries. Depending on the type of Bing Maps layer that you choose to add (from Road, Aerial, or Hybrid) and the zoom percentage you select, you can view city names and roads and various boundaries. To keep from cluttering my map, I'm going to omit the Bing Maps layer in this example, but I do recommend that you experiment with this feature. It's a nice integration feature.&lt;/li&gt;&lt;li&gt;Use the + or - button to rexize the map as needed. (I used the + button to increase the size of the map until its edges were just inside the boundaries of the visible map area (which is called the viewport). You can eliminate the color scale and distance scale boxes that appear in the map area later.&lt;/li&gt;&lt;li&gt;Select the &lt;b&gt;Embed map data in this report&lt;/b&gt; for faster rendering. The spatial data won't be changing, so there's no need to leave it in the database. However, it does increase the size of the RDL. Click &lt;b&gt;Next&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;On the &lt;b&gt;Choose map visualization&lt;/b&gt; page, select &lt;b&gt;Basic Map&lt;/b&gt;. We'll add data for visualization later. For now, we have just the outline of France to serve as the foundation layer for our map. Click &lt;b&gt;Next&lt;/b&gt;, and then click &lt;b&gt;Finish&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Now click the color scale box in the lower left corner of the map, and press the Delete key to remove it. Then repeat to remove the distance scale box in the lower right corner of the map.&lt;/li&gt;&lt;/ol&gt;&lt;p&gt;&lt;b&gt;Step 2: Add a Map Layer to an Existing Map&lt;/b&gt;&lt;/p&gt;&lt;p&gt;The map data region allows you to add multiple layers. Each layer is associated with a different data set. Thus far, we have the spatial data that defines the regional boundaries in the first map layer. Now I'll add in another layer for the store locations by following these steps:&lt;/p&gt;&lt;ol&gt;&lt;li&gt;If the Map Layers windows is not visible, click the report body, and then click twice anywhere on the map data region to display it.&lt;/li&gt;&lt;li&gt;Click on the New Layer Wizard button in the Map layers window.&lt;br&gt;&lt;img style="WIDTH:104px;HEIGHT:338px;" height="400" alt="2_NewLayerWizard.png" width="159" src="http://sqlblog.com/blogs/stacia_misner/2_NewLayerWizard.png"&gt;&lt;br&gt;And then we start over again with the process by choosing a spatial data source.&lt;/li&gt;&lt;li&gt;Select &lt;b&gt;SQL Server spatial query&lt;/b&gt;, and click &lt;b&gt;Next&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Select &lt;b&gt;Add a new dataset with SQL Server spatial data&lt;/b&gt;, and click &lt;b&gt;Next&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Click &lt;b&gt;New&lt;/b&gt;, add a connection string to the AdventureWorks2008R2 database, and click &lt;b&gt;Next&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;Add a query with spatial data (like the one I included in the &lt;a target="_blank" title="Spatial Data In SSRS project" href="http://datainspirations.com/uploads/SpatialDataInSSRS.zip"&gt;downloadable project&lt;/a&gt;), and click &lt;b&gt;Next&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;The location data now appears as another layer on top of the regional map created earlier. Use the + button to resize the map again to fill as much of the viewport as possible without cutting off edges of the map. You might need to drag the map within the viewport to center it properly.&lt;/li&gt;&lt;li&gt;Select &lt;b&gt;Embed map data in this report&lt;/b&gt;, and click &lt;b&gt;Next&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;On the &lt;b&gt;Choose map visualization&lt;/b&gt; page, select &lt;b&gt;Basic Marker Map&lt;/b&gt;, and click &lt;b&gt;Next&lt;/b&gt;.&lt;/li&gt;&lt;li&gt;On the &lt;b&gt;Choose color theme and data visualization&lt;/b&gt; page, in the &lt;b&gt;Marker&lt;/b&gt; drop-down list, change the marker to diamond. There's no particular reason for a diamond; I think it stands out a little better than a circle on this map. Clear the &lt;b&gt;Single color map&lt;/b&gt; checkbox as another way to distinguish the markers from the map.&lt;br&gt;You can of course create an analytical map instead, which would change the size and/or color of the markers according to criteria that you specify, such as sales volume of each store, but I'll save that exploration for another post on another day.&lt;br&gt;&lt;/li&gt;&lt;li&gt;Click &lt;b&gt;Finish&lt;/b&gt; and then click &lt;b&gt;Preview&lt;/b&gt; to see the rendered report. Et voilà...c'est fini.&lt;br&gt;&lt;img style="WIDTH:501px;HEIGHT:313px;" height="369" alt="3_FinalMap.png" width="584" src="http://sqlblog.com/blogs/stacia_misner/3_FinalMap.png"&gt;&lt;br&gt;Yes, it's a very simple map at this point, but there are many other things you can do to enhance the map. I'll create a series of posts to explore the possibilities.&lt;/li&gt;&lt;/ol&gt;&lt;img src="http://sqlblog.com/aggbug.aspx?PostID=25042" width="1" height="1"&gt;</description><category domain="http://sqlblog.com/blogs/stacia_misner/archive/tags/SSRS/default.aspx">SSRS</category><category domain="http://sqlblog.com/blogs/stacia_misner/archive/tags/SQL+Server+2008+R2/default.aspx">SQL Server 2008 R2</category><category domain="http://sqlblog.com/blogs/stacia_misner/archive/tags/Spatial+Data/default.aspx">Spatial Data</category></item></channel></rss>