How to import a shape file into SQL Server?

Viewed 11442

In the past I have used shape2sql to import shape files into SQL Server.

I tried that route again on a newer Windows 10 box, and nothing seems to happen when trying to use that application.

Any suggestions for either getting shape2sql to work, or alternative ways to upload shape files into SQL Server?

2 Answers

So, it turns out that ogr2ogr has the ability to import directly into a SQL Server database now. I created a temporary database and did the following:

ogr2ogr -overwrite -f MSSQLSpatial -lco “GEOM_TYPE=geography” -a_srs "EPSG:4326" "MSSQL:server=.;database=temp_import;trusted_connection=yes" "[path to shape file]"

I've managed to import successfully on remote server. Here goes procedure

  1. Install QGIS Desktop 3.10.5..or whatever version is actual.
  2. How to find out what goes to parameter -a_srs, in my casa that is : -a_srs "EPSG:3765":

Open QGIS Desktop 3.10.5, open new project and drag-drop your shape file to Layers left sidebar. Right click on that layer and go to Properties. There you will be able to read your -a_srs information.

enter image description here

  1. Run command in CMD:

    C:\Program Files\QGIS 3.10\bin>ogr2ogr -progress -f "MSSQLSpatial" "MSSQL:server=xxx.xxx.xxx.xxx,yyyy;database=yourDB;UID=yourUse;PWD=yourPassword" "C:\Users\Username\Desktop\ShapeFiles\Name_of_shape_file.shp" -a_srs "EPSG:3765" -lco PRECISION=NO

Where xxx.xxx.xxx.xxx - IP address of your server yyyy - port number of your server if you are running SQL Server on different port than standard (I think you can omit that in case you are)

Output: 0...10...20...30...40...50...Warning 1: Ring Self-intersection at or near point 664451.64629999956 5053409.8562000087 60...70...80...90...100 - done.

Related