• Blog posts

    Bio

    By David Crowther 

    112.png

    Question:

    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?

    Answer:

    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.

    https://www.cadlinecommunity.co.uk/hc/en-us/articles/360000275789-QGIS-How-do-you-load-and-then-access-SQL-Server-Spatial-data-within-QGIS-

    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.