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:

spatial results in management studio

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.

6 Responses to “shp2sqlserver – command line shapefile loader for sql server 2008”

  1. Morten Says:

    FYI my Shape2Sql tool also has a commandline option. See the help page.

  2. Scott Says:

    thanks Morten. I actually didn’t know about anything but that one blog post I linked to.

  3. Isaac @ MSDN : Frequently Asked Question: How do I load shapefiles? Says:

    [...] 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 [...]

  4. ledaker Says:

    it doesnt work for sql server 2005 ?!

  5. Scott Says:

    spatial extensions are new in sql server 2008

  6. Tessa Says:

    Love the advice. Thank you.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>