Question

I have a shapefile that I would like to upload to a spatial SQL Server 2008. I have tried using this tool: SQL Server 2008 Spatial Tools. But without luck.

Does anyone know any other (free) tools for doing this?

Was it helpful?

Solution

You can use ogr2ogr to convert from shapefile to GML (or many other formats) and then use SQL Server's GeomFromGML to import. You will need to call GeomFromGML for each feature in your shapefile, but that's a relatively easy program to write.

OTHER TIPS

I have written code in arcbjects for do this task. If you have license arcview or engine you can create a console application in c# and use this code: see https://gis.stackexchange.com/questions/33917/how-to-import-shapefiles-into-ms-sql-2008-and-then-view-that-data-using-qgis?lq=1

UPDATE: I decided I would just point people to the official Github repo instead: https://github.com/zer0infinity/OGR2GUI

This [ogr2ogr fork] tool will attempt to parse the content of the input file (in my case, it was a shapefile) and output it as a bunch of different formats (in my case, I needed it as a CSV, but you can even export your file as a SQLite file). Unfortunately it doens't do straight up SQL, but you can do a dump from a SQLite viewer such as SQLite Browser and import it onto MS SQL. I did notice some inefficiencies when converting to SQLite (I lost some attributes/tables). I also tried MobileMapper Office (MMO) (with better luck) to export to CSV and it did preserve a lot of the data, but you'd then need to write a script to import the data to SQL. If you are going that route, let me know, I'm currently writing a VBA script to deal with the exported data from MMO.

If you're hoping to build this into your application (a script of some sort), you may have some luck trying with ogr2ogr, but you never know what the data is going to look like. documentation is found here http://www.gdal.org/ogr2ogr.html

Original answer: Save yourself sometime and just use this amazing tool: http://ogr2gui.ca/

It's based off ogr2ogr, but with a nice GUI.

I've made an app for importing shapefiles into SQL Server. It's made primarily to suit my needs but i had some spare time so i made an installer for you.

Some nice things you can do with it:

  1. choose encoding of input shapefile
  2. rename/remap destination table column names
  3. choose the destination table name
  4. set the primary key for the destination table

It has a user interface and you can download it for free.

More details can be found on my blog, here's the link: Import shapefiles into SQL Server

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top