Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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'

share|improve this question

2 Answers 2

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  
share|improve this answer
    
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 at 9:25

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
share|improve this answer
    
@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 at 7:46
    
It duplicate the rows in GDB, But still with Null Geometry for Polygons. –  mahmoud hageer Jul 16 at 8:28
    
strange. And are the other fields updated ? –  radouxju Jul 16 at 8:40

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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