UpdateCursor not working on feature class anymore

683
4
Jump to solution
08-23-2022 10:19 AM
MKF62
by
Occasional Contributor III

I've been going through and updating some old scripts from Python 2 to Python 3. These are typically very very minor changes, such as updating dictionary methods from old stuff like "viewitems" and "iteritems" to "items." I haven't changed anything in this script at all except now when I run it, when it hits lines with an UpdateCursor (hereforth, UC), it says the "in_table" is not a table or feature class. I have run Describe on feature class that I am passing to the UC to ensure that it is a feature class and it is. It is not participating in any joins, topologies, networks, network datasets or anything like that. It is coming from a file geodatabase. The documentation mentions something about "some" feature classes not working with class extensions and I wonder if that's my problem? This feature class does use domains, but I'm uncertain if the class extensions they're referring to in the documentation are custom class extensions and not the "out of the box" stuff. The last time this script worked, I was using ArcMap and Enterprise 10.7 I believe. I can alter my code to make a feature layer and give that to the UC and it works, but I don't understand why...

The code is really long, so I've tried to boil it down.

 

svyPtFC = os.path.join(uploadedGDB, "{0}_Patch_Template".format(stateID))

try:
    #Check the projection of the input feature class.
    prjInfo = inputDesc.spatialReference
    if prjInfo.PCSCode != 102003:
        #Project the feature class to match the Patches FC in the SDE database
        spatialRef = arcpy.SpatialReference(102003) #USA Contiguous Albers Equal Area Conic EPSG code
        svyPtFC = arcpy.Project_management(svyPtFC, os.path.join(scratchGDB, "projection"),
                                           spatialRef)
except:
    # do stuff

#Split multipart polygons to single part. Each polygon has to be evaluated separately. Multipart features would not work
#well when evaluating appropriate access or adjacency.
multipartFL = arcpy.MakeFeatureLayer_management(svyPtFC, 'multipartFL')
svyPtFC = arcpy.MultipartToSinglepart_management(multipartFL, os.path.join(scratchGDB, 'singlepart'))

#Find any gaps between polygons 1 meter wide or less and fix the polygon edges so they are coincident with each other.
svyPtFC = arcpy.Integrate_management(svyPtFC, '1 Meter')

##### FAILS HERE ######
# Check float fields for decimals. If there is a decimal, multiply by 100 to make it a whole number.
with arcpy.da.UpdateCursor(svyPtFC, ['CropResidue', 'CnpyOver12', 'CnpyDecid', 'CnpyConif', 'ShrubCover',
                                     'ShbHiStemsDens','GrassCover', 'ForbCover', 'FrbAsProtect', 'BareGround']) as uCursor:
    for row in uCursor:
        for position, item in enumerate(row):
            if item < 1 and item != 0 and item != None:
                item = item * 100
                row[position] = item
        uCursor.updateRow(row)

 

0 Kudos
1 Solution

Accepted Solutions
by Anonymous User
Not applicable

The Integrate management docs mention if you want to use the output for another process, you need to set it as a precondition in the next tool, which looks like it is only in modelbuilder.

'The output data element of this tool is a derived multivalue output. To use this tool's output with another tool, use its input directly and set its output as a precondition of the other tool.'

I don't think the result from the method is getting set to the variable as it once was. Maybe try dropping the assignment and keep svyPtFC assigned to the MultipartToSinglepart method's output. .. Or create a new variable pointing to the FC in the db before passing to cursor.

 

svyPtFC = arcpy.MultipartToSinglepart_management(multipartFL, os.path.join(scratchGDB, 'singlepart'))

#Find any gaps between polygons 1 meter wide or less and fix the polygon edges so they are coincident with each other.
arcpy.Integrate_management(svyPtFC, '1 Meter')

 

 

View solution in original post

4 Replies
JoshuaBixby
MVP Esteemed Contributor

Although you state the system specifications when you think it last worked, you haven't told us which products and versions you are trying to work with now.  Also, providing the exact error traceback is helpful too, even if the line numbers don't line up quite perfectly to sample code.  Or better yet, run the sample code on your system and provide the traceback.

0 Kudos
MKF62
by
Occasional Contributor III

I'm just trying to run it locally right now. I have ArcGIS Pro 3.0 and I am using Visual Studio as my IDE with the arcgispro-py3 interpreter. Full traceback:

Traceback (most recent call last):
File "C:\Users\NBCI\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "C:\Users\NBCI\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "c:\program files (x86)\microsoft visual studio\2019\enterprise\common7\ide\extensions\microsoft\python\core\debugpy\__main__.py", line 45, in <module>
cli.main()
File "c:\program files (x86)\microsoft visual studio\2019\enterprise\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 430, in main
run()
File "c:\program files (x86)\microsoft visual studio\2019\enterprise\common7\ide\extensions\microsoft\python\core\debugpy/..\debugpy\server\cli.py", line 267, in run_file
runpy.run_path(options.target, run_name=compat.force_str("__main__"))
File "C:\Users\NBCI\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\runpy.py", line 268, in run_path
return _run_module_code(code, init_globals, run_name,
File "C:\Users\NBCI\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\runpy.py", line 97, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "C:\Users\NBCI\AppData\Local\Programs\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "E:\NET_Projects\HabitatMapGPServices\HabitatClassificationGPService\HabitatClassification.py", line 592, in <module>
with arcpy.da.UpdateCursor(svyPtFC, ['CropResidue', 'CnpyOver12', 'CnpyDecid', 'CnpyConif', 'ShrubCover',
RuntimeError: 'in_table' is not a table or a featureclass

0 Kudos
by Anonymous User
Not applicable

The Integrate management docs mention if you want to use the output for another process, you need to set it as a precondition in the next tool, which looks like it is only in modelbuilder.

'The output data element of this tool is a derived multivalue output. To use this tool's output with another tool, use its input directly and set its output as a precondition of the other tool.'

I don't think the result from the method is getting set to the variable as it once was. Maybe try dropping the assignment and keep svyPtFC assigned to the MultipartToSinglepart method's output. .. Or create a new variable pointing to the FC in the db before passing to cursor.

 

svyPtFC = arcpy.MultipartToSinglepart_management(multipartFL, os.path.join(scratchGDB, 'singlepart'))

#Find any gaps between polygons 1 meter wide or less and fix the polygon edges so they are coincident with each other.
arcpy.Integrate_management(svyPtFC, '1 Meter')

 

 

MKF62
by
Occasional Contributor III

That worked and never would have occurred to me, thank you!!

0 Kudos