I'm a newbie on SQL Server. What is the most preferred way to import shapefile geometry into MS SQL Server 2016. Not sure how to make it right.
Adding to klewis's answer: I got shape2sql.exe to work by adding a Shape2Sql.exe.config file with the following contents:
<?xml version="1.0" encoding="utf-8"?> <configuration> <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <dependentAssembly> <assemblyIdentity name="Microsoft.SqlServer.Types" publicKeyToken="89845dcd8080cc91" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-220.127.116.11" newVersion="18.104.22.168" /> </dependentAssembly> </assemblyBinding> </runtime> </configuration>
You can change the 22.214.171.124 to whichever version of Microsoft.SqlServer.Types is applicable to your version of SQL Server.
I use a free tool, shape2sql.exe, by SharpGIS.net. Because the tool is unmaintained you may need to copy and rename a dll, SqlServerSpatial110.dll or SqlServerSpatial120.dll to SqlServerSpatial.dll in C:\windows\system32. Also, clear out field "ID Column Name" for the data to import, I'm on Win10 64 bit.
You can use ogr2ogr library to import shapefile to SQL server, check below example and reference:
ogr2ogr -f "MSSQLSpatial" "MSSQL:server=localhost\voledmort;database=myDB;trusted_connection=yes" "countries.shp" -a_srs "EPSG:2249"
here is a step-by-step guide to use the tool http://www.c-sharpcorner.com/UploadFile/898089/how-to-add-world-map-in-sql-server-2012/
We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.