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:

  1. shp2sqlserver.exe -h
  2. Usage: shp2sqlserver.exe [OPTIONS]+ "connectionString" "path to shapefile"
  3. Loads a shapefile into Microsoft SQL Server 2008
  4.  
  5. example: shp2sqlserver.exe "Data Source=.\SQLExpress2008;Initial Catalog=spatialtest;Integrated Security=true" myshape.shp
  6.  
  7. Options:
  8.   -s, --srid=VALUE           The Spatial Reference ID (SRID).  If not specified it defaults to -1.
  9.   -g, --geometry_column=VALUE       The name of the geometry column
  10.   -t, --table_name=VALUE     The table name to use
  11.   -k, --key_column=VALUE     The name of the identity column to create for a primary key
  12.   -i, --index                Create a spatial index
  13.   -l, --latlong              Add spatial data as geography type
  14.   -a, --append               Append data.  If not specified, table will be created
  15.   -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.

7 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. Waylen Edge Says:

    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?

  7. MAFRI Says:

    mafri.ws…

    […]Scott Ellington’s Blog » Blog Archive » shp2sqlserver – command line shapefile loader for sql server 2008[…]…

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>