Ogr2Ogr – How can I extract a table and create a Shapefile from SQL Server

Marketing
Marketing

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.

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.