I have executed a stored procedure and want to export this layer to a shapefile. I feel like this should be an easy solution. I tried using arcpy.CopyFeatures_management and it threw an error. I am not sure if CopyFeature is meant for sql server tables.
I am running ArcGIS 10.1. I am using SQL server 2012 with geography data type. The table is not registered with the geodatabase. The error is below:
RuntimeError: Object: Error in executing tool
<<< Process finished. (Exit code 1)
Below is my code:
import pyodbc
import arcpy
sqlserver = pyodbc.connect('DRIVER={SQL Server};SERVER=sqlserver;DATABASE=AndrewSandbox;Integrated Security=True')
cursor = sqlserver.cursor()
table = cursor.execute("SELECT * FROM TEMPLINE")
arcpy.CopyFeatures_management(table, "D:\Python\WaterSage\Viability\TestExport.shp")
-
2Please give more information. What error did it throw? CopyFeatures_management should work fine for SQL Server.nickpeihl– nickpeihl2014年11月06日 23:22:32 +00:00Commented Nov 6, 2014 at 23:22
-
1Please update the question to include the version of ArcGIS in use, the geometry storage type, the SQL-Server version, whether the table is registered with the geodatabase, and the exact error message.Vince– Vince2014年11月06日 23:32:08 +00:00Commented Nov 6, 2014 at 23:32
1 Answer 1
I do not have an SQL Server table available to test this, but I was surprised to see you using pyodbc
in this workflow.
I recommend that you try to use a Query Layer:
A query layer is a layer or stand-alone table that is defined by a SQL query.
...
You can persist a query layer by exporting it to a feature class.
Explore related questions
See similar questions with these tags.