3

I am trying to Duplicate some polygons in the same layer with the same attributes, But it will duplicated them with Null Geometry, i have tried getValue() method, but i got error

import arcpy

polygons_shape="C:\\temp\\FinalLayers.gdb\\FinalLayers\\Polygons"
fields=['ID','Comment','owner']
Insert = arcpy.InsertCursor(polygons_shape)
ID= arcpy.da.SearchCursor(polygons_shape,'*')
for row in ID:
        if row[0]>1:
         dupCount=row[0]
         myShape = row.getValue(shapeName)
         insert_row.setValue('ID', row[0])
         insert_row.setValue('Comment', row[1])
         insert_row.setValue('owner', row[2])

         while dupCount>1:
                    Insert.insertRow(insert_row)
                    dupCount-=1

The Error:

myShape = row.getValue(shapeName)

AttributeError: 'tuple' object has no attribute 'getValue'

3

I have FOUND the ANSWER

infc = arcpy.GetParameterAsText(0)  
repnum = arcpy.GetParameterAsText(1)  

gRows = arcpy.da.SearchCursor(infc, "Shape@")  
for row in gRows:  
    origpoly = row  
del gRows  

aRows = arcpy.da.InsertCursor(infc, "Shape@")  

for x in xrange(0, int(repnum)):  
    aRows.insertRow(origpoly)  
del aRows  
1
  • yes, this was probably a problem with the combined use of two cursors together. But your code as it is presented would only duplicate the last row. I guess that you have more code but that you only show part of it.
    – radouxju
    Jul 16 '14 at 9:25
1

it would be easier to combine with arcpy.da.InsertCursor. Note that in your code the row[1] value is the shape field.

EDIT: as you found out, the main problem came from the use of 2 cursors together (and my first suggestion to use an edit session did not solve that).

polygons_shape="C:\\temp\\FinalLayers.gdb\\FinalLayers\\Polygons"

fields=('ID','SHAPE@','Comment','owner')

ID= arcpy.da.SearchCursor(polygons_shape,fields)
list_rows=[]
for row in ID:
    if row[0]>1:
        list_rows.append(row)
del ID

Insertc = arcpy.da.InsertCursor(polygons_shape, fields)
for newrow in list_rows:
    for i in range(newrow[0]):
           Insertc.insertRow(newrow)
del Insertc
3
  • @mahmoudhageer As indicated in this answer getValue/setValue are methods used with old style (arcpy) cursors and are not available with new style (arcpy.da). I too think you should standardize on using arcpy.da.
    – PolyGeo
    Jul 16 '14 at 7:46
  • It duplicate the rows in GDB, But still with Null Geometry for Polygons. Jul 16 '14 at 8:28
  • strange. And are the other fields updated ?
    – radouxju
    Jul 16 '14 at 8:40
0

The reason that you are getting this error message:

AttributeError: 'tuple' object has no attribute 'getValue'

is because you are using a syntax that is appropriate for arcpy.SearchCursor() with an arcpy.da.SearchCursor().

With arcpy.SearchCursor() the opening of a cursor makes any field in the feature class available as a property or method of its row objects, either by using the field names (e.g. row.fieldX) or the getValue and setValue methods (e.g. row.getValue).

These are NOT available to arcpy.da.SearchCursor() where instead you need to use shape tokens to get at the geometry field and an index on the row object to access its field values e.g. row[0] for first declared field, etc.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.