import arcpy # Test for existence of various datasets, both in SDE and shapefile for pth in (r"Database Connections\GIS.sde", r"C:\Users\RMcCulley\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\GIS.sde", r"Database Connections\GIS.sde\gis.cvr.Basemap\gis.cvr.Townships", r"G:\Parcel GIS Files\Townships.shp"): if arcpy.Exists(pth): value = pth + " Exists" else: value = pth + " Doesn't Exist" arcpy.AddMessage(value) # Try FeatureClassToFeatureClass to export from Shapefile to Shapefile if arcpy.Exists(r"C:\Temp\Townships_From_SHP.shp"): arcpy.Delete_management(r"C:\Temp\Townships_From_SHP.shp") try: value = arcpy.FeatureClassToFeatureClass_conversion(in_features=r"G:\Parcel GIS Files\Townships.shp",out_path=r"C:\Temp",out_name="Townships_From_SHP.shp") except: value = "FeatureClassToFeatureClass Failed" arcpy.AddMessage(value) # Try FeatureClassToFeatureClass to export from SDE to Shapefile if arcpy.Exists(r"C:\Temp\Townships_From_SDE.shp"): arcpy.Delete_management(r"C:\Temp\Townships_From_SDE.shp") try: value = arcpy.FeatureClassToFeatureClass_conversion(in_features=r"Database Connections\GIS.sde\gis.cvr.Basemap\gis.cvr.Townships",out_path=r"C:\Temp",out_name="Townships_From_SDE.shp") except: value = "FeatureClassToFeatureClass Failed" arcpy.AddMessage(value)
Executing: arcpytesting Start Time: Wed Oct 16 13:12:03 2013 Running script arcpytesting... Database Connections\GIS.sde Exists C:\Users\RMcCulley\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\GIS.sde Exists Database Connections\GIS.sde\gis.cvr.Basemap\gis.cvr.Townships Exists G:\Parcel GIS Files\Townships.shp Exists C:\Temp\Townships_From_SHP.shp C:\Temp\Townships_From_SDE.shp Completed script arcpytesting... Succeeded at Wed Oct 16 13:12:04 2013 (Elapsed Time: 1.00 seconds)
Database Connections\GIS.sde Exists C:\Users\RMcCulley\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\GIS.sde Exists Database Connections\GIS.sde\gis.cvr.Basemap\gis.cvr.Townships Doesn't Exist G:\Parcel GIS Files\Townships.shp Exists C:\Temp\Townships_From_SHP.shp FeatureClassToFeatureClass Failed
arcgisscripting.ExecuteError: Failed to execute. Parameters are not valid. ERROR 000732: Input Features: Dataset Database Connections\GIS.sde\gis.cvr.Basemap\gis.cvr.Townships does not exist or is not supported Failed to execute (FeatureClassToFeatureClass).
Have you tried to use real sde connection file location instead of "Database Connections\\"?
The connection files are usually at "C:\Users\username\AppData\Roaming\ESRI\Desktop10.0\ArcCatalog"
If it creates an sde connection file and you can use it in ArcGIS, that should be all arcpy needs to connect to the database. And I may be mistaken, but even using direct connects I believe you need to have SDE installed for your database.
arcpy.CreateDatabaseConnection_management("C:\\Temp","GISTest","POSTGRESQL","<server>","DATABASE_AUTH","<user>","<password>","SAVE_USERNAME","gis")
username = >USERNAME< conn1 = "c:/Users/"+username+"/AppData/Roaming/ESRI/Desktop10.1/ArcCatalog/spatialdb_vectors_arcadmin.sde/" lyr = conn1 + "vectors.arcadmin.AIRPORTS" if arcpy.Exists(lyr): print "Feature Class Found!" else: print "FAILURE :("
if arcpy.Exists(conn1): print "DATABASE FOUND!" else: print "Failure"
Any resolution on this?
I am trying to automate the migration of data using geoprocessing tools. So I am starting with an XML Workspace Document that I exported using ArcCatalog. When I try to import this into a new geodatabase, I tried dragging the db connection into the geoprocessing tool (ImportXMLWorkspaceDocument) and it fails saying 'Cannot access local or remote database'.
This happens with multple tools, i.e., EnableAttachments_management, Append_management and ImportXMLWorkspaceDocuemnt)
Any thoughts?
I figured this one out a long time ago - and forgot to mention the resolution to this problem.
arcpy requires numpy, but doesn't seem to import it automatically. If I import numpy before importing arcpy, arcpy works perfectly.
So short answer - every script you're planning to run at the command line, or in an interpreter, should start with:
import numpy
import arcpy