Move SHP to gdb and ArcView license (newbie frustration)!!!

3140
54
04-11-2012 07:58 AM
LucaMoiana
New Contributor
Hi there,
What I need to do is move all the files into an mxd to a newly created gdb, chechking prj, and update mxd reference.

I have ArcGIS 10 SP4, license ArcView

I studied a bit of Python and get familiar with basic, then I copied some written code and pasted all together, attached is the code.

My frustration is that i can???t even move my shp files to a created gdb, is that because of my ArcView license?

PLEASE PLEASE PLEASE HELP

# Import system modules
import arcpy
from arcpy import env
import os
 
# Set environment settings
env.workspace = "C:/Users/a391665/Documents/AAAAPERSONALE/rugareto"

# Execute CreateFileGDB
arcpy.CreateFileGDB_management("C:/park", "test4")
 
# Set local variables
outWorkspace = "c:/park/test4.gdb"


# Use ListFeatureClasses to generate a list of shapefiles in the
#  workspace shown above.
fcList = arcpy.ListFeatureClasses()
 
# Execute CopyFeatures for each input shapefile
for shapefile in fcList:
    # Determine the new output feature class path and name
    outFeatureClass = os.path.join(outWorkspace, shapefile.strip(".shp"))
    arcpy.CopyFeatures_management(shapefile, outFeatureClass)
Tags (2)
0 Kudos
54 Replies
LucaMoiana
New Contributor
it work in PythonWin, but in the Python Window I get this:


env.workspace completed successfully
CreateFileGDB completed successfully
outWorkspace completed successfully
fcList completed successfully
Runtime error <class 'arcgisscripting.ExecuteError'>: Failed to execute. Parameters are not valid. ERROR 000732: Input Features: Dataset Percorsi.shp does not exist or is not supported Failed to execute (CopyFeatures).

I do have Percorsi.shp but it doesn't seem to work.
0 Kudos
ScottBlankenbeckler
Occasional Contributor
What kind of data is stored in Percorsi.shp? Point? Line? Poly? other? Have you checked to see if the shapefile is corrupt? Also make sure the file is not in use elsewhere.
0 Kudos
MichaelVolz
Esteemed Contributor
Luca:

Can you add a print statement for each feature class that you loop through in the specified directory?  This might be a clue of a problem with the shapefile name.
0 Kudos
LucaMoiana
New Contributor
Percorsi.shp is a polyline shape, I can get it into gdb running the script from PythonWin but from the Python window I get this:

env.workspace completed successfully
CreateFileGDB completed successfully
outWorkspace completed successfully
fcList completed successfully
Runtime error <class 'arcgisscripting.ExecuteError'>: Failed to execute. Parameters are not valid. ERROR 000732: Input Features: Dataset Percorsi.shp does not exist or is not supported Failed to execute (CopyFeatures).

Luca:

Can you add a print statement for each feature class that you loop through in the specified directory?  This might be a clue of a problem with the shapefile name.
0 Kudos
DaphneEdison
New Contributor
What does the error say (if any)?
0 Kudos
LucaMoiana
New Contributor
What does the error say (if any)?


env.workspace completed successfully
CreateFileGDB completed successfully
outWorkspace completed successfully
fcList completed successfully
Runtime error <class 'arcgisscripting.ExecuteError'>: Failed to execute. Parameters are not valid. ERROR 000732: Input Features: Dataset Percorsi.shp does not exist or is not supported Failed to execute (CopyFeatures).
0 Kudos
LucaMoiana
New Contributor
here is what I was able to accomplish (thank to your help obviously):

# Import system modules
import arcpy
from arcpy import env
import os

    
# Set environment settings
env.workspace = "C:\\Users\\a391665\\Documents\\AAAAPERSONALE\\rugareto\\GIS"
print("env.workspace completed successfully")

#check GDB exist
if os.path.exists("c:\\park\\test4.gdb"):
    arcpy.Delete_management("c:\\park\\test4.gdb")

# Execute CreateFileGDB
arcpy.CreateFileGDB_management("C:\\park", "test4")
print("CreateFileGDB completed successfully")

# Set local variables
outWorkspace = "c:\\park\\test4.gdb"
print("outWorkspace completed successfully")

# Iterate
def fcs_in_workspace(workspace):
    arcpy.env.workspace = workspace
    for fc in arcpy.ListFeatureClasses():
        print os.path.join(workspace, fc)
        arcpy.FeatureClassToGeodatabase_conversion(fc, outWorkspace)     
        #arcpy.CopyFeatures_management(fc, "c:\\park\\test4.gdb")
        print os.path.join(workspace, fc, "TO GDB")
    for ws in arcpy.ListWorkspaces():
        fcs_in_workspace(os.path.join(workspace, ws))

fcs_in_workspace("C:\\Users\\a391665\\Documents\\AAAAPERSONALE\\rugareto\\GIS")


I dunno why, but in the first try I was able to use "arcpy.CopyFeatures_management" but in this script looping through the subfolders I only can get it working with "arcpy.FeatureClassToGeodatabase_conversion"
0 Kudos
MichaelVolz
Esteemed Contributor
Luca:

Can you add the print statement for the feature classes in fcList earlier on in the loop before python hits the error?

Here is where I would put additional print statements for debugging purposes:
# Execute CopyFeatures for each input shapefile
for shapefile in fcList:
# Determine the new output feature class path and name
print("The feature class " + shapefile + " now has the focus")
outFeatureClass = os.path.join(outWorkspace, shapefile.strip(".shp"))
print("The path to the feature class that has the focus is " + outFeatureClass)
arcpy.CopyFeatures_management(shapefile, outFeatureClass)

You might need to change shapefile and outFeatureClass variables to strings if python says they are not in the correct format to be printed out. I think this might provide some additional clues to the problem of python seeing the shapefile that you want copied into the file geodatabase.
0 Kudos
LucaMoiana
New Contributor
I don't get it, if I add your code I have an error in line 1.
Take a look at the last code posted, that works except "arcpy.CopyFeatures_management"


Luca: 

Can you add the print statement for the feature classes in fcList earlier on in the loop before python hits the error? 

Here is where I would put additional print statements for debugging purposes: 
# Execute CopyFeatures for each input shapefile 
for shapefile in fcList: 
# Determine the new output feature class path and name 
   print("The feature class " + shapefile + " now has the focus")  
outFeatureClass = os.path.join(outWorkspace, shapefile.strip(".shp")) 
   print("The path to the feature class that has the focus is " + outFeatureClass)  
arcpy.CopyFeatures_management(shapefile, outFeatureClass) 

You might need to change shapefile and outFeatureClass variables to strings if python says they are not in the correct format to be printed out. I think this might provide some additional clues to the problem of python seeing the shapefile that you want copied into the file geodatabase.
0 Kudos
MichaelVolz
Esteemed Contributor
Can you provide a screenshot of the error message you get, as well as the latest version of the code that you are running?
0 Kudos