5

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.

  • This very much depends on what software you have available. – Vince Dec 14 '16 at 16:04
  • see also alastaira.wordpress.com/2011/06/18/… – Kirk Kuykendall Dec 14 '16 at 17:19
  • what type of geometry - point, line, polygon or all? Do you have access to ArcGIS? – DPSSpatial Jan 3 '17 at 16:37
  • THANK YOU VERY MUCH for your Shape2Sql.exe.config file. It took from me much time while i saw your approach. And it run. This way worked. – Тимур Т. Jun 8 '18 at 9:56
9

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-14.0.0.0" newVersion="14.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

You can change the 14.0.0.0 to whichever version of Microsoft.SqlServer.Types is applicable to your version of SQL Server.

  • Not sure when this became a requirement, as this was working without this .config file early last year. Copy and pasting the above worked fine for me – Morvael Apr 10 '18 at 9:59
2

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.

2

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"

Reference:
https://alastaira.wordpress.com/ogr2ogr-patterns-for-sql-server/

0

You may be interested in "GISquirrel" https://www.gisquirrel.com which includes a tool for importing any vector layer into your SQL Server database, working in ArcMap (It's an extension for ArcGIS Desktop). There's a free trial that works for 20 minutes per session and works with up to 10,000 features in a layer.

-1

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/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.