[gdal-dev] Error while importing shapefiles to Sql Server

Jukka Rahkonen jukka.rahkonen at mmmtike.fi
Tue Mar 18 03:28:31 PDT 2014


Giampaolo <giampaolo.rebuzzi <at> i-sti.net> writes:

> 
> Hi, I wrote this batch file to import all the shapefiles in a folder to Sql
> Server:
> 
>  <at> ECHO OFF
> setlocal EnableDelayedExpansion
> echo Importing...
> for %%f in (*.shp) do (
> set filename=%%~nf
> set filenametrunc=!filename:~3!
> ogr2ogr -append -update -f MSSQLSpatial
> "MSSQL:server=.\SQLEXPRESS;database=ShapeFiles;trusted_connection=yes;"
> "%%f" -nln !filenametrunc!
> 
> echo !filename!
> )
> echo Completed
> PAUSE
> 
> Shapefiles are named like this:
> 001boundary.shp
> 001grid.shp
> 002boundary.shp
> 002grid.shp
> ...
> 
> It works fine while importing 001boundary.shp and 001grid.shp and creating
> 'boundary' table and 'grid' table, but, when it tries to import
> 002boundary.shp and 002grid.shp, it gives me this error:
> 
> ERROR 1: Layer boundary already exists, CreateLayer failed.
> Use the layer creation option OVERWRITE=YES to replace it.
> ERROR 1: Terminating translation prematurely after failed
> translation of layer 001boundary (use -skipfailures to skip errors)
> 
> I think it's because the tables already exists, so, how can I make it append
> the new values to existing tables?

Hi,

The trouble may come from the -nln parameter. I had a try with Spatialite
and it did accept -nln also when appending but I am remembering that I have
experienced perhaps with Oracle that -nln was accepted only when the table
was really created. You may have success by removing -nln beginning from the
second file but I do not know what is the right syntax for giving the
existing table name for GDAL MSSQL driver.

Myself I thing I would not bother to think too much but just convert
everything into one Spatialite table and then send it into MSSQL with a
single ogr2ogr command.

-Jukka Rahkonen-

> 
> Thank you,
> Giampaolo
> 
> --
> View this message in context:
http://osgeo-org.1560.x6.nabble.com/gdal-dev-Error-while-importing-shapefiles-to-Sql-Server-tp5129482.html
> Sent from the GDAL - Dev mailing list archive at Nabble.com.
> 






More information about the gdal-dev mailing list