shp2sqlserver – command line shapefile loader for sql server 2008
There are other tools, but in the process of working on something else, I put together a command line tool for loading shapefiles into Sql Server 2008. It is modeled after PostGIS’s shp2pgsql, except that it loads directly into the db instead of writing sql to stdout. Here is the usage:
- shp2sqlserver.exe -h
- Usage: shp2sqlserver.exe [OPTIONS]+ "connectionString" "path to shapefile"
- Loads a shapefile into Microsoft SQL Server 2008
- example: shp2sqlserver.exe "Data Source=.\SQLExpress2008;Initial Catalog=spatialtest;Integrated Security=true" myshape.shp
- Options:
- -s, --srid=VALUE The Spatial Reference ID (SRID). If not specified it defaults to -1.
- -g, --geometry_column=VALUE The name of the geometry column
- -t, --table_name=VALUE The table name to use
- -k, --key_column=VALUE The name of the identity column to create for a primary key
- -i, --index Create a spatial index
- -l, --latlong Add spatial data as geography type
- -a, --append Append data. If not specified, table will be created
- -h, --help show this message and exit
Here is a screenshot of some spatial results in management studio. Note the holes and exterior polygons:
Limitations:
- This is alpha level software. I have loaded some complex shapefiles up to 20MB with it, but it could bomb on yours.
- The Shapefile loader only supports Point, Polyline, and Polygon types. It will fail on everything else (including PolygonM, etc.)
Update: This has been bundled with cumberland 0.1. Get it here.

November 3rd, 2008 at 7:09 pm
FYI my Shape2Sql tool also has a commandline option. See the help page.
November 3rd, 2008 at 7:26 pm
thanks Morten. I actually didn’t know about anything but that one blog post I linked to.
November 4th, 2008 at 4:29 pm
[...] time now, which has both a command line and GUI interfaces. Scott Ellington has created a command line tool as well, but I haven’t had a chance to play with it [...]
December 6th, 2008 at 1:18 pm
it doesnt work for sql server 2005 ?!
December 6th, 2008 at 1:26 pm
spatial extensions are new in sql server 2008
December 30th, 2010 at 3:18 pm
Mort, your command line feature does not work, or at least I can’t get it to function and I have tried several times. Also, if you are not going to attempt to profit from the application, why not publish the source?
October 3rd, 2011 at 11:27 am
mafri.ws…
[...]Scott Ellington’s Blog » Blog Archive » shp2sqlserver – command line shapefile loader for sql server 2008[...]…