Select to view content in your preferred language

Select features by subtype

1007
5
11-29-2010 02:15 AM
LeeMusto
Emerging Contributor
I have numerous geodatabase feature classes, each of which contains several subtypes, so in total there are approx 150 different subtypes. I need to create new separate feature classes for each of those subtypes, containing all of the features of that particular subtype (so that I can output them to a text file). I am quite new to scripting, but believe I could achieve this if I created a list of all those subtypes. However, I assume I should be able to do this without the need to create the list. I understand loops, but it's how to group the features according to subtype that I am struggling with - any tips would be much appreciated.
Tags (2)
0 Kudos
5 Replies
ChrisMathers
Deactivated User
Well you can

iterate over the feature classes,
  use a cursor to get a set of the values in the subtype field
  iterate over the values in the set
    select by the value
    featureclasstofeatureclass the selection.
0 Kudos
LeeMusto
Emerging Contributor
Chris,

Thanks for your reply. I understand how to do it for one subtype using the method you describe, but it's how to iterate over each subtype, without knowing what those subtypes are e.g  if I have 10 feature classes, each with 10 subtypes, I want to automatically create 100 new feature classes - some subtypes may have features in them, some may be empty, but I still need it to produce the feature classes. In the meantime, I have created simple tables which contain the subtypes and written a script which iterates through each subtype - which works fine for this set of data, but it would be useful to know so that if I have a new set of data in the future I did not have to manually create the tables.
0 Kudos
ChrisMathers
Deactivated User
Ah ok. Well you need only to know which field holds the subtype values.

for FC in listofFC:
    s_cursor=arcpy.SearchCursor(FC)
    subtypes=[]
    for row in s_cursor:
        subtypes.append(row.getValue(subtypefield))
    subtypes=set(subtypes)
    for i in subtypes:
        do the stuff you need to for each subtype


Getting the list of values and then making them a set will take [a,a,a,b,c,v,v,c,b] and make it [a,b,c,v].
0 Kudos
LeeMusto
Emerging Contributor
Chris,

I understand how your script works - I would never have known about the 'Set' function without your reply. I'll give it a try in the near future.

Many thanks for your help.
0 Kudos
IanMusto
Emerging Contributor
Lee,

Nothing to do with this particular Python posting, it's just very interesting to find someone with the Musto surname.

If you would like to chat - ian.musto@csiro.au.

Cheers

Ian

PS Sorry to disturb the rest of the thread
0 Kudos