Need help with uploading shapefile with srid 102008 to SQL server 2012. I ran the ogr2ogr script in the ogr shell and it uploaded the shapefile within seconds but when I try using python subprocess to call ogr, I get an empty spatial_ref_sys and geometry column table added to SQL server 2012 database. I should add that I have read write access to the database .

Here's my script-

import os
import sys
import subprocess

# Set OGR2OGR environment
gdal = r'C:\Program Files (x86)\GDAL'
gdalData = r'C:\Program Files (x86)\GDAL\gdal-data'
os.environ['PATH'] = gdal + ';' + os.environ['PATH']
os.environ['GDAL_DATA'] = gdalData

indriver = "MSSQL:server=<server>;database=<database>;trusted_connection=yes"
ogr2ogr = r'C:\Program Files (x86)\GDAL\ogr2ogr.exe'
cmd = '-f MSSQLSpatial'
proj_cmd = '-a_srs'
proj = "EPSG:102008"
reName_cmd = '-nln'
reName = 'NewName'
shp = path = r'H:\NA\20151226_LNAD83.shp'
translateFile_tx =' '.join([ogr2ogr, cmd, indriver, shp])
print 'Done'
  • Are you missing several parameters in the .join statement? – klewis Dec 28 '15 at 21:22
  • i added the other parameters (-a_srs and -nln) to the .join statement and does not work. I was able to successfully upload the shapefile to SQL server 2008 with and without the other parameters but no success with SQL server 2012. – Rita A. Dec 29 '15 at 1:36
  • Is the 2012 spatial reference the same as 2008? If you can upload data from the command line to 2012, you must have incorrect parameter in the Python script. – klewis Dec 29 '15 at 18:51
  • spatial reference is exactly the same as the shapefile i imported to 2008. as for the python script, All I changed was the server to one that sits on Native client 10 (2008) and worked great. Imported and included the srid 102008. 2012 uses on native client 11. I tested arcpy and pyodbc to import the same shapefile and it uploaded but the srid was missing. I am wondering if there's another parameter i have to add. I tested the same shapefile using shp2sql and worked great. As for right now, i think the issue is with the srid. – Rita A. Dec 29 '15 at 19:18
  • Hope this helps someone else. I couldn't figure out why ogr and python subprocess could not upload to SQL server 2012. However, I successfully uploaded my shapefile to SQL server using pyodbc and arcpy. I uploaded the points as WKT and updated the WKT to WBT with the srid I needed. Works great. – Rita A. Dec 30 '15 at 19:55