ESRI Shapefiles are a popular file format for storing geospatial data. The format was created by ESRI, one of the largest GIS companies in the world and a Microsoft Partner. The shapefile format has been around for a while and as such there are a lot of datasets available online in this format. In addition, this is a binary file format which is much more efficient than XML file formats. This blog post will show some of the different ways that shapefiles can be overlaid on top of Bing Maps. Bing Maps offers high resolution aerial imagery globally and also has an excellent road map style which is designed to make your data stand out and is also designed for people with color blindness. Bing Maps makes the perfect canvas for any dataset.
If you have an ArcGIS license then you can already easily import shapefiles into your map. However getting a shapefile on a map wasn’t the complete purpose of this post; we want to overlay the data on Bing Maps. Well, that’s easily taken care of as Bing Maps is available through ESRI ArcGIS as documented here.
The ESRI shapefile format is an open standard. As such it is possible to write code that can read these files. Thankfully we don’t need to do this as there is already an excellent open source set of tools available on CodePlex called ESRI Shapefile Reader. This makes it easy to read shapefiles files directly from .NET code. I’ve found this library to be excellent when working with the Bing Maps WPF control as I can easily create an application to view shapefiles that are on my computer directly into the map. If you want to use this for web applications you could wrap this with a web service, note that this would mean you are reading the complete file before being able to process a query against it so this isn’t the best approach.
Option 3: Import into MS SQL Server
ESRI shapefiles are a great way to share complete data sets but as mentioned in Option 2 it’s not the most efficient format for making queries against. What can be done (and most often done) is you can easily import the data in Microsoft SQL Server 2008, 2012 or SQL Azure as these are all spatial databases. This is an approach I use pretty regularly as it offers excellent performance and a number of great spatial tools for manipulating the data. There are several tools for importing shapefiles into SQL Server. The most common one is a free tool called Shape2SQL. This tool has an easy to use user interface making it easy for just about anyone to import a shapefile into SQL Server. Another excellent free tool is called Geospatial Data Abstraction Library. Not only can this tool import your shapefile into SQL server but it can also re-project your data if needed and has several other useful geospatial tools. One of our Bing Maps MVP’s, Alastair Aitchison, has put together an excellent article explaining how to use this with SQL Server which you can find here. I use this tool quite often when I work with shapefiles that are in different projects. For instance there is some great free data available from the Ordnance Survey
Once you have your shapefile in SQL Server you can then connect this to your mapping application. In most cases you will want to create a web service to expose your data to your application. If you are a fan of the MVC pattern then I recommend checking out the AJAX Map Data Connector which is an open source CodePlex project that uses MVC to connect an SQL database to the Bing Maps V7 AJAX control. If using WPF I recommend taking a look at this article on Entity Framework 5 & Bing Maps WPF.
Option 4: Commercial Tools
There are many commercial tools available that can read and process ESRI shapefiles. One popular product is called Safe FME. This product is capable of understanding 275 different spatial and non-spatial data formats. This also provides a very robust set of tools for performing complete computations and transformations against this data. If you are working with several different data formats this is definitely worth taking a look at. This tool comes in two different flavours, a desktop version and a server version. In addition they have lots of excellent tutorials on how to use it with Bing Maps. Here are some of the ones I recommend checking out:
· Dynamic Tile-Layers with Windows Azure and SQL Azure
· Standalone data distribution demo: Bing Maps
· Creating HTML for use with Bing Maps using the VirtualEarthHTMLCreator
· Rasterization for Web Mapping Platforms
· Creating a Web Map Tile Cache in SQL Server