How to: Use SharpGIS Shape2Sql Tool to import Shape files

Shape files are a common format for storing geospatial data, originally developed by ESRI (Technical Description (PDF)). This page describes how to import Shape files into SQL Server 2008 for viewing using Geoquery 2008.

cntry00 and admin00 Shape file datasets viewed in Geoquery 2008

There are a number of different tools that can import Shape files into SQL Server 2008, but Morten's Shape File (SHP) Uploader has been the primary tool used during the build & testing of Geoquery 2008.

The screenshots below show the import of country borders and country 'administrative zone' (state/province) borders into SQL Server 2008 using SqlSpatialTools v1.2.0

Step 0 - Download

Download and extract SqlSpatialTools, cntry00.zip and admin00.zip.
Execute Shape2Sql.exe.

Step 1 - Connect to your SQL Server 2008 database

The first time you run the tool, you will be prompted to select a database.

Configuring ShapeFileUploader

Step 2 - Import Country Borders

Select the cntry00.shp Shape file using the [...] button. It should be in a directory with other files from the downloaded zip including cntry00.dbf and cntry00.shx.

The tool will populate the list of 'data columns' at the bottom right with identifiers from the Shape file - uncheck any that you do not wish to import. You may also choose whether to import as geometry or geography (and what SRID to use). Press Upload to database when you are happy with the settings.

Importing Country Borders from cntry00.shp

As the data is being imported the progress will be displayed in the window (see next screenshot).

Step 3 - Import Administrative Zones

Importing the admin00.shp file from here follows the same steps.

Importing States and Province Borders from admin00.shp

A few errors may occur when loading these two files. They appear as a dialog like this:

Of 252 entries in cntry00.shp, four errors occur (Germany, Azerbaijan, Antartica and Italy).
Of 2606 entries in admin00.shp, four errors occur (Germany: Schleswig-Holstein, Switzerland: Bern, South Korea: Kyonggi-do and Antarctica)

Step 4 - Query using Geoquery 2008

SELECT geog, 'yellow' AS [COLOR] FROM cntry00
SELECT geog FROM admin00

Notice the different 'relative size' of Greenland on the different "projections".

Data Sources

These other Shape file tools have not been tested with Geoquery 2008, but they are often linked-to/discussed:

Other tools

These other Shape file tools have not been tested with Geoquery 2008, but they are often linked-to/discussed