Select to view content in your preferred language

What means: TypeError: 'Row' object does not support indexing ???

16088
11
01-27-2015 11:57 PM
JohannesBierer
Frequent Contributor
rows1 = arcpy.SearchCursor(fc, ["SHAPE@"])
extents = []
for row1 in rows1:
    
    ext = row1[0].extent
    extents.append(row1[0].extent)
    print(extents)
0 Kudos
11 Replies
DanPatterson_Retired
MVP Emeritus

Examine this

import arcpy
input_shp = 'c:/folder/you_file_here.shp'
arr = arcpy.Array()
with arcpy.da.SearchCursor(input_shp,['FID','SHAPE@']) as cur:
  extents = [] 
  for row in cur:
    ext = row[1].extent
    p0 = ext.lowerLeft; p1 = ext.upperRight
    print('Extent of shape... {}: '.format(row[0]))
    print(' X min/max  {}, {}'.format(ext.XMin,ext.XMax))
    print(' Y min/max  {}, {}'.format(ext.YMin,ext.YMax))
    arr.add(p0)
    arr.add(p1)
mp = arcpy.Multipoint(arr)
print('Extent of all {}'.format(mp.extent))
JohannesBierer
Frequent Contributor

Thank you

0 Kudos
JohannesBierer
Frequent Contributor

Thats what I have so far with the help of dan and xander:

The goal is to create an oldschool image catalog as dbf, because we use a software which can't read the new ones.

import arcpy, os, math
from arcpy import env
Fgdb = r"R:\Karto\Bierer2014\Datenabgabe\20150113_Brandt\raster\RasterCatalog.gdb"
arcpy.env.workspace = r"R:\Karto\Bierer2014\Datenabgabe\20150113_Brandt\raster\RasterCatalog.gdb"
# Ausgabepfad = (r"R:\Karto\Bierer2014\Datenabgabe\20150113_Brandt\raster").strip()
Ausgabepfad = r"R:\Karto\Bierer2014\Datenabgabe\20150113_Brandt\raster"
ext = ".jpg"
arcpy.AddField_management(Ausgabepfad + "\Orthos_Nummern.shp", "IMAGE", "TEXT", 100) # , "", "", "refcode", "NULLABLE", "REQUIRED")

ext = ".jpg"  
fc = os.path.join(Ausgabepfad, "Orthos_Nummern.shp")  
fld_oid = "OBJECT_ID" # or: arcpy.Describe(fc).OIDFieldName  
fld_out = "IMAGE" # should exist in shapefile
fld_xmin = "XMIN"
arcpy.AddField_management(fc, "XMIN", "LONG", 7) # , "", "", "refcode", "NULLABLE", "REQUIRED")
arcpy.AddField_management(fc, "XMAX", "LONG", 7) # , "", "", "refcode", "NULLABLE", "REQUIRED")
arcpy.AddField_management(fc, "YMIN", "LONG", 7) # , "", "", "refcode", "NULLABLE", "REQUIRED")
arcpy.AddField_management(fc, "YMAX", "LONG", 7) # , "", "", "refcode", "NULLABLE", "REQUIRED")

input_shp = fc
arr = arcpy.Array()  
with arcpy.da.UpdateCursor(input_shp,['FID','SHAPE@']) as cur:  
  extents = []  
  for row in cur:  
    ext = row[1].extent  
    p0 = ext.lowerLeft; p1 = ext.upperRight  
    print('Extent of shape... {}: '.format(row[0]))  
    print(' X min/max  {}, {}'.format(ext.XMin,ext.XMax))
    Xmin = round((ext.XMin), 0)
    print (Xmin)
    print_attributes(row)
    row.setValue(fld_xmin, Xmin)
    print ( ' X min, {}'.format(ext.XMin))
    curs.updateRow(row)
    print(' Y min/max  {}, {}'.format(ext.YMin,ext.YMax))  
    arr.add(p0)  
    arr.add(p1)  
mp = arcpy.Multipoint(arr)  
print('Extent of all {}'.format(mp.extent)) 
rows = arcpy.UpdateCursor(fc)  
for row in rows:
    fld_oid1 = int(row.getValue(fld_oid))
    int_fld_oid1 = str(fld_oid1)
    # path = os.path.join(Ausgabepfad, "{0}{1}".format(row.getValue(fld_oid), ext))
    path = os.path.join(Ausgabepfad, int_fld_oid1 + ext)
    print (path)
    path1 = str("" + path + "")
    row.setValue(fld_out, path)
    rows.updateRow(row)
0 Kudos
JohannesBierer
Frequent Contributor

Error message:

File "R:\Karto\zGIS\Python\exportrastercatalog.py", line 49, in <module>

    row.setValue(fld_xmin, Xmin)

AttributeError: 'list' object has no attribute 'setValue'

0 Kudos
DanPatterson_Retired
MVP Emeritus

Your line numbers are off...any way

    curs.updateRow(row)  should be

    cur.updateRow(row)    there is no curs in the script you have shown

print_attributes(row)  this function is define elsewhere?

you seem to be missing old cursors with new cursors, ie using setValue...you should be using updateRow as in the example here ie access the field by offset number for the row you are working with

0 Kudos
JohannesBierer
Frequent Contributor

cur.updateRow(row) doesn't work as well ?

# -*- coding: cp1252 -*-
# Export zu rastercatalog.dbf
# Autor Xander Bakker, Dan Patterson - vermurkst JB
import arcpy, os, math
from arcpy import env
Fgdb = r"R:\Karto\Bierer2014\Datenabgabe\20150113_Brandt\raster\RasterCatalog.gdb"
arcpy.env.workspace = r"R:\Karto\Bierer2014\Datenabgabe\20150113_Brandt\raster\RasterCatalog.gdb"
# Ausgabepfad = (r"R:\Karto\Bierer2014\Datenabgabe\20150113_Brandt\raster").strip()
Ausgabepfad = r"R:\Karto\Bierer2014\Datenabgabe\20150113_Brandt\raster"
ext = ".jpg"
## arcpy.AddField_management(Ausgabepfad + "\Orthos_Nummern.shp", "IMAGE", "TEXT", 100) # , "", "", "refcode", "NULLABLE", "REQUIRED")
ext = ".jpg"  
fc = os.path.join(Ausgabepfad, "Orthos_Nummern.shp")  
fld_oid = "OBJECT_ID" # or: arcpy.Describe(fc).OIDFieldName  
fld_out = "IMAGE" # should exist in shapefile
fld_xmin = "XMIN"
arcpy.AddField_management(fc, "XMIN", "LONG", 7) # , "", "", "refcode", "NULLABLE", "REQUIRED")
arcpy.AddField_management(fc, "XMAX", "LONG", 7) # , "", "", "refcode", "NULLABLE", "REQUIRED")
arcpy.AddField_management(fc, "YMIN", "LONG", 7) # , "", "", "refcode", "NULLABLE", "REQUIRED")
arcpy.AddField_management(fc, "YMAX", "LONG", 7) # , "", "", "refcode", "NULLABLE", "REQUIRED")
def print_attributes(obj):
    for attr in arr.__dict__:
        print attr, getattr(arr, attr)
input_shp = fc
arr = arcpy.Array()  
with arcpy.da.UpdateCursor(input_shp,['FID','SHAPE@']) as cur:  
  extents = []   
  for row in cur:  
    ext = row[1].extent  
    p0 = ext.lowerLeft; p1 = ext.upperRight  
    print('Extent of shape... {}: '.format(row[0]))  
    print(' X min/max  {}, {}'.format(ext.XMin,ext.XMax))
    Xmin = round((ext.XMin), 0)
    print (Xmin)
    print_attributes(row)
    row.setValue(fld_xmin, Xmin)
    print ( ' X min, {}'.format(ext.XMin))
    cur.updateRow(row)
    print(' Y min/max  {}, {}'.format(ext.YMin,ext.YMax))  
    arr.add(p0)  
    arr.add(p1)  
mp = arcpy.Multipoint(arr)  
print('Extent of all {}'.format(mp.extent))  
##rows = arcpy.UpdateCursor(fc)  
##for row in rows:
##    fld_oid1 = int(row.getValue(fld_oid))
##    int_fld_oid1 = str(fld_oid1)
##    # path = os.path.join(Ausgabepfad, "{0}{1}".format(row.getValue(fld_oid), ext))
##    path = os.path.join(Ausgabepfad, int_fld_oid1 + ext)
##    print (path)
##    path1 = str("" + path + "")
##    row.setValue(fld_out, path)
##    rows.updateRow(row)

Error:

Extent of shape... 0:
X min/max  3510999.9998, 3511999.9998
3511000.0
_arc_object <geoprocessing array object object at 0x02B88368>

Traceback (most recent call last):
  File "R:\Karto\zGIS\Python\exportrastercatalog.py", line 43, in <module>
    row.setValue(fld_xmin, Xmin)
AttributeError: 'list' object has no attribute 'setValue'

Thought I wold get some information through def print attributes?

0 Kudos
DanPatterson_Retired
MVP Emeritus

setValue is replaced by updateRow, I can't find reference to setValue in the new data access cursors...I rarely use them but the error says that you are trying to use a setValue method on a list object, suggesting that row is a list ... you need to define the rows to use in this line

with arcpy.da.UpdateCursor(input_shp,['FID','SHAPE@'])

which you haven't, and then reference the column by an offset number ie row[0] would be the FID field and row[1] the SHAPE@ field as in the example I sent you.
Maybe someone who uses 'cursors' will weigh in...I have pretty well switched over to numpy arrays should I have the rare need to work with attributes.

0 Kudos
JohannesBierer
Frequent Contributor

In numpy what's wrong about that? How to define the field to write in?

And how to write XMIN, XMAX, YMIN, YMAX in one array and then in the right fields?

npa = numpy.array(Xmin)

arcpy.da.NumPyArrayToTable(npa, fc, fld_xmin)

TypeError: narray.fields require

0 Kudos
JohannesBierer
Frequent Contributor

Unfortunately don't get it:

dts = {(fld_xmin,fld_xmax),numpy.int}
    print (dts)
    npa = numpy.array(dts)
       arcpy.da.NumPyArrayToTable(npa, fcout)

What is the sense of the error message:

TypeError: narray.fields require

0 Kudos