1

I want to query a feature class on attribute 'state' == 'new', and if so, add that feature class record to a list (I will process this list later).

I have:

cursor = arcpy.da.SearchCursor(points, 'state')
for row in cursor:
 if row[0] == 'new':
 new_point_list.append(row)

('points' is the feature class, 'state' is the attribute within the feature class) but that just makes a list of tuples, not feature class records!

I ultimately want a list of records in that feature class with a status of 'new', so that I can loop through them and perform other functions.

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked Jan 6, 2019 at 18:20
3
  • SearchCursor accepts a where_clause parameter, so you don't even need to test the row[0] value. You'll still have the issue of only saving the field with "new" in it. Commented Jan 6, 2019 at 18:29
  • What is your next processing step? Commented Jan 6, 2019 at 18:35
  • I need to take this list of new points, find a way to relate them to each other (no keys, can only use timestamp or spatial distance apart and user that created them), then relate them to the nearest linear feature and snap them to that feature. Basically, the points are breadcrumb points along a line and I need to snap to that line and segment that line, then mark that section of the line as 'inspected'-I know, a lot of work! Commented Jan 6, 2019 at 19:54

1 Answer 1

2

new_point_list.append(row[0]). But im guessing you want to append objectids (or some other unique identifier) instead, if you want to do more processing later.

If so you can try something like this:

oids = []
with arcpy.da.SearchCursor(points, ['state','OID@']) as cursor:
 for row in cursor:
 if row[0] == 'new':
 oids.append(row[1])
answered Jan 6, 2019 at 18:28
4
  • 1
    Best done within a with or using a del, no? Commented Jan 6, 2019 at 18:33
  • If the source is file geodatabase, there won't be a huge time difference with where_clause="state = 'new'" but if RDBMS or lots of rows, it could. Commented Jan 6, 2019 at 18:56
  • But this only gets me a list of ints, not actual records. Is there not a way to just build a table or records, and work with the records directly (instead of re-querying on OID to perform additional steps, for which I have to compare various other attributes and gets complicated)? Commented Jan 6, 2019 at 19:51
  • 1
    Use Select tool, or make feature layer tool. No need for cursor Commented Jan 6, 2019 at 19:53

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.