If you've installed Visual Studio 2008 R2, you might have tried to create a map or two. If you tried to create a map of Europe or Asia, you soon discovered that Microsoft only included US maps. Rumor has it that Microsoft didn't include other countries because it didn't want to offend any countries that were disputing borders with their neighbors. Given the state of the world and how well we all get along, I can see this being a real issue. However, some people still need to use maps of countries from all over the globe.
To make matters worse, the Help links imply that you can pull in international maps from other sites, but unfortunately the URLs provided don't provide sources for non-US maps. So, I spent a lot of time digging around the web and found a few sites that offer maps for countries, counties, and cities all over the planet. I'll show you where to find these maps as well as how to incorporate them into SQL Server 2008 R2's Business Intelligence Development Studio (BIDS) so that you can easily leverage them in reports. But first I need to tell you about the data format of the maps you'll be using.
Understanding the Data Format
There's seemingly no limit to the number of different map data files available on the web, but BIDS can most easily consume Environmental Systems Research Institute (ESRI) shapefiles. These files have the .shp extension and contain binary (not XML) points that describe the two-dimensional shapes (polygons) that make up the maps. For example, each map would have a polygon that lays out the country's outer border and might include individual polygons for each subregion (e.g., state, county, city, neighborhood, postal code). The .shp file might also contain attributes that include names or other information for each polygon that can be shown (or hidden) when you render the map.
The .shp file comes with companion files, which must be included. This means that when you point BIDS to a .shp file, you're really pointing to a folder that contains at least three files and perhaps up to five others. The basic files are:
- The .shp file, which contains the polygon shapes that make up the map
- The .shx file, which contains the positional index of the map shapes
- The .dbf file, which contains a dBase database that contains the shapes' attributes
Note that not all .shp files are the same. Some can be used with Bing Map layers and some cannot. Bing Map layers can really make your maps far more interesting, as the .shp files are simply a set of featureless polygons. By setting the map background color to "no color," the Bing Map with all of its detail can be seen through the top-layer map. With or without Bing Map, you can create custom maps by adding or removing polygons (to show a custom set of states or counties, for example) and saving the edited map as an .rdl file.
Finding Suitable Maps
As I mentioned previously, I had to look high and low for international (non-US) map data files. I discovered that if I searched for ".shp map download" I got a lot more useful hits. I've also found that the availability of maps varies from time to time. However, now that you know what files to look for, you should be able to ferret out the wheat from the chaff and find a number of viable free sources.
When searching for maps, you need to keep in mind that many maps aren't in the public domain and therefore must be licensed for use in any commercial application. I don't encourage or endorse the use of unlicensed maps or other content. Note that if you're running a non-profit corporation (which is different than a company that never seems to make any money), you might be eligible to use some of these maps for free.
In my map quest, I found many sources for maps, including:
- This site has a wealth of freely downloadable .zip files that contain .shp files. MapCruzin.com has been providing free and open-source maps since 1996.
- The Centers for Disease Control and Prevention (CDC) Shapefiles site seems to be one of the most comprehensive. It contains maps (albeit dated) of all countries on all continents worldwide (at least those that existed in 1998). On the website, though, you'll find this caveat: "These boundary files are not in the public domain and are intended for use with Epi Info™ and Epi Map only." However, the EPI application is a public domain application and the shapefile downloads are free. I would check with the CDC before building a commercial application with these shapefiles, though.
- The United Kingdom is well covered by Ordnance Survey, which is Great Britain's national mapping agency. This site has a wealth of free highly detailed maps that include voting precincts and other subgroups.
Creating a Custom Map .rdl File
In the example that follows, I'm using a map of India. If you'd like to follow along using that map, you can download its files from the CDC. Choose ASIA from the Continent drop-down list, select India from Country drop-down list, and click Download. This downloads an .exe file, which is really a .zip file that can unpack the map files to a folder of your choosing.
After you've downloaded the map files to a folder, start a new Report Server Project in SQL Server 2008 R2 BIDS. Using the Add New Item option, add a map to the empty report. (Don't use the Report wizard.) Name the report to match the name or description of the map you're building.
Next, drag a Map control into the report, as Figure 1 shows. This will launch the New Map Layer wizard. In the wizard's Choose a source of spatial data page, click the ESRI shapefile option and browse to the folder in which you downloaded your map files. Choose the .shp file from this folder. Once selected, the .shp file is opened and rendered in the wizard, as shown in Figure 2.
Click Next to go to the Choose spatial data and map view options page in the New Map Layer wizard. At this point, you can customize the map as needed, including adding a Bing Map layer, which can add a great deal of visual functionality and detail to the map. For this example, though, just click Next.
In the Choose map visualization page, select Basic Map because you don't have data associated with the map yet. You'll add that data later when you incorporate the map into a report. Click Next.
In the Choose color theme and data visualization page, select your own color theme or simply click Next to accept the generic theme. Click Finish to add the customized report template to your project. Click Save to commit these changes to an .rdl file.
You now have an .rdl file that you can add to the Map Gallery. This gallery lists the maps you've installed.
Customizing the Map Gallery
Before adding the map to the Map Gallery, it helps to locate the Visual Studio 2008 R2 (9.0) MapGallery folder using your favorite file explorer. It's installed at C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\PrivateAssemblies\MapGallery, except on 32-bit systems in which you'd leave off the (x86) part of the path.
To add your customized .rdl file to the Map Gallery, simply use the Save As option and save it to the aforementioned MapGallery folder. If you plan to have a lot of maps, it helps to put their .rdl files in folders that identify them by location, as Figure 3 shows.
Figure 4 shows what the Map Gallery looks like in the Choose a source of spatial data page. This page will appear whenever you use the New Map Layer wizard to add a new map to a report or add a new map layer to an existing map. To incorporate one of these maps into your report, you simply click the blue globe icon next to the named map. It's that easy.
Explore New Worlds
Clearly, the planet is shrinking but the information you can acquire about it is unfathomable. Imagine how easy it would be to explore new worlds with these maps. All Leif Ericson would have needed was a broadband connection and the BIDS tools. I hope those of you trying to build maps of other countries can find ways to help us all know each other a bit better.