Hi,
using ArcMap 10.5.
look i want to simply load the data from one gdb to other gdb... but on my first attempt the geometry of polygons and lines was not uploaded. I read in the forums that i needed to include the "SHAPE@". I tried as such, but the result is bad... i cannot understand how to fix it. The error message is: AttributeError: 'unicode' object has no attribute editable.
can someone suggest me something?
cheers
P
env.workspace = datasets[0]
fcs = arcpy.ListFeatureClasses()
for fc in fcs:
#print '\t', fc
count=count_records(fc) # counts the features within each FC
if count<>"0":
listfields = arcpy.ListFields(fc)
for l in range(len(listfields)):
## listfields = listfields.name
## print listfields
listfields = [f.name for f in listfields if f.editable and f.type != "Geometry"] + ["SHAPE@"]
with arcpy.da.SearchCursor(fc,listfields) as cur:
with arcpy.da.InsertCursor(GDBDwgs + "\\" + fc, l) as icur:
for row in cur:
print '\t', fc
icur.insertRow(row)
del icur
del cur
Solved! Go to Solution.
There is no need to do things through a cursor.
If you have a need to copy featureclasses from one gdb to another and you want to do it with some changes in the output name perhaps, look at existing tools and their code examples.
Do recognize that many tools can be 'batched' without coding.
Copy—Data Management toolbox | Documentation
Feature Class to Feature Class—Conversion toolbox | Documentation
Examine the existing tools within the Tools structure, particular those in the Conversion and Data Management toolsets.
Anatomy of a tool reference page—ArcGIS Help | Documentation
Code examples ... if needed at all ... are contained within
Hi Dan,
thanks for the feedback. But the links are all for arcgisPro, it's not my case. Plus, I have already a destination GDB with feature classes inside. my goal in the end is that i run the script for several gdbs that will feed a single gdb (existing one not creating a new one).
I tried the append... but it gave this error:
Traceback (most recent call last):
File "\\eusc.europa.eu\ATLAS\Home\psoares\Documents\python\filesupporttools\CopyfGDBtGDB_append_version.py", line 63, in <module>
arcpy.Append_management(fcs,GDBDwgs,"NO_TEST","","" )
File "C:\Program Files (x86)\ArcGIS\Desktop10.5\ArcPy\arcpy\management.py", line 4271, in Append
raise e
ExecuteError: Failed to execute. Parameters are not valid.
ERROR 000840: The value is not a Table View.
ERROR 000840: The value is not a Raster Layer.
Failed to execute (Append).
fcs = arcpy.ListFeatureClasses()
for fc in fcs:
print '\t', fc
count=count_records(fc) # counts the features within each FC
if count<>"0":
arcpy.Append_management(fcs,GDBDwgs,"NO_TEST","","" )
this is really hard
What is your GDBDwgs set to?
You may want to first try executing the Append tool in ArcMap. Then go to the Results window > right-click on the result > Copy As Python Snippet. This will copy the python syntax to your clipboard that you can then paste into your script.
Sorry... it worked, i forgot to point it the table. now it's like this and it worked... well i just test one time i am doing now test with real data.
for fc in fcs:
print '\t', fc
count=count_records(fc) # counts the features within each FC
targetfc = GDBDwgs + "\\" + fc
if count<>"0":
arcpy.Append_management(fc,targetfc,"NO_TEST","","" )
the equivalent tools exist in arcmap
Your code is hard for me to read but I had a similar issue and I solved it by placing the 'Shape@' field in my list of fields for the insert cursor, as well as in my list of fields for the search cursor.
new_fields = [field.name if field.name != 'Shape' else 'Shape@' for field in arcpy.ListFields(new_path)]
old_fields = [field.name if field.name != 'Shape' else 'Shape@' for field in arcpy.ListFields(old_path)]