Select to view content in your preferred language

eading geometry through Search Cursor ... runtime error says it cannot open file!

952
5
Jump to solution
01-24-2023 12:13 PM
Seyed-MahdySadraddini
Regular Contributor

Hi

I am trying to read and use the geometries of a polygon layer, row by row, using Search Cursor. I am getting a very strange runtime error, but I cannot figure out the source of this error! My first time getting this runtime error!

Traceback (most recent call last):
File "C:\Documents\ArcGIS\Projects\Census\Redistribute_Home.py", line 75, in <module>
with arcpy.da.SearchCursor(from_shape, ['SHAPE@', 'FIRST_city', 'FIRST_ccid', 'FIRST_NUMBER_OF_DIVISIONS']) as search:
RuntimeError: cannot open 'ON1996_DissolveOnName'

First time seeing this runtime error. It says it cannot open the layer, but there isn't anything striking me to be wrong in my code!

 

# this is the workspace
arcpy.env.workspace = os.path.join(directory, gdb + '/' + fds) # gdb and fds are text strings

# the layer to create divisions from
from_shape = layer # 'ON1996_DissolveOnName' is the value of the layer

 

Again, here is the part of the code that runs into error

with arcpy.da.SearchCursor(from_shape, ['SHAPE@', 'FIRST_city', 'FIRST_ccid', 'FIRST_NUMBER_OF_DIVISIONS']) as search:

Another question is whether using SHAPE@ token to read the geometry for each of the

0 Kudos
1 Solution

Accepted Solutions
Seyed-MahdySadraddini
Regular Contributor

Actually there was an error in the path... hard to see!

View solution in original post

0 Kudos
5 Replies
JohannesLindner
MVP Alum

The error is telling you that it can't open ON1996_DissolveOnName, probably because it can't find it.

So:

  • are you running this in the Python window, a toolbox or as standalone script?
  • ArcGIS Pro  or ArcMap?
  • If you're running this in the Python Window, does the current map actually have a layer called "ON1996_DissolveOnName"?
  • How do you declare the variable layer? The full script could be helpful.

 

To post code:

JohannesLindner_0-1674589814049.pngJohannesLindner_1-1674589827880.png


Have a great day!
Johannes
Seyed-MahdySadraddini
Regular Contributor

Hmmm... the path to the file is correct, and the file is there! This is what makes it very strange...!!

0 Kudos
Seyed-MahdySadraddini
Regular Contributor

Actually there was an error in the path... hard to see!

0 Kudos
JohannesLindner
MVP Alum

Oh, also, your second question got cut short:

Another question is whether using SHAPE@ token to read the geometry for each of the


Have a great day!
Johannes
0 Kudos
Seyed-MahdySadraddini
Regular Contributor

Sorry, it is perhaps an irrelevant question now.

0 Kudos