By David Crowther
I would like to extract and create a Shapefile from a Table stored in a SQL Server Database, what are the best steps to do this?
In the blog below, I have outlined how to use Ogr2Ogr to load a Shapefile into a SQL Database. This is a good starting point for learning how to use OgrOgr.
Using this updated Ogr2Ogr script below, you can also extract an existing SQL Table and create a new Shapefile from your chosen SQL Database:
ogr2ogr -f "ESRI Shapefile" "D:\Temp\shp\schools.shp" "MSSQL:server= SERVERNAME;database= SQLDBNAME;tables=SQLTABLENAME;trusted_connection=yes;" -sql "SELECT * FROM sqltablename"
The above script when ran within your OsGeo4W shell will extract the chosen SQL Table and create a new Shapefile called Schools.shp.