I am ArcGIS 10 user and I want to create ArcPy script for simple concatenate row values like this tool Concatenate Row Value that works with ArcGIS 10.
I have three fields in my shapefile id,field1,field2
.
Here the image from my shapefile .dbf
after sort by id.
If you see the image you can see the id not have unique values.
I want to create the layer with unique id values but I don't want to loose some values from field2 (is text). For field2 I need to use for next conditions.
In Excel if I use some condition like this:
=IF(AND(A3=A2;C3=C2);D2;IF(AND(A3=A2;C3<>C2);D2;IF(AND(A3=A2;C3<>C2);D2&","&C3;C3)))
Then I take new field to like this:
That works in Excel, I want to do with Python or ArcPy or some tool from ArcGIS.
In QGIS, it is easy for me to do with this plugin that does dissolve with stats
.
I try to follow this code:
updateFields = ["id", "field2", "field3"]
with arcpy.UpdateCursor("featurelayer", updateFields) as cursor:
for row in cursor:
if row[0]+1 == row[0] and row[2]+1==row[2]:
row[3] = row[2]
elif row[0]+1 == row[0] and row[2]+1!=row[2]:
row[3] = row[2]
elif row[0]+1 == row[0] and row[2]+1!=row[2]:
row[3] = row[2]+','+row[2]+1
cursor.updateRow(row)
That looks correct but any time to try to run it I take this error:
Cursor AttributeError: __exit__
How do I fix the problem?
if
conditions will ever be true. This has the same problem as the previous post, in that you are trying to use DA cursor syntax with an old-style cursor.None
and retain the previous row contents before invokingnext
. Then you'll have a chance at making code which can be tested. As @Midavalo wrote,There is no way for us to explain how to fix your code unless you explain what you think it should be doing.