Select to view content in your preferred language

Get the field values from a feature class

643
3
05-01-2023 10:54 PM
kumarprince8071
New Contributor III

By following the given criteria need to get the field values of Assettype and Assetgroup from a feature class.

  1. Check if the feature class have subtypes (Assetgroup assigned as subtype field) and also check if the feature class have both the field names(Assetype and Assetgroup).

  2. If it is true then get the values of both field , the field values are domain coded

     

    I'm using this script but not getting the output

    1. subdict = arcpy.da.ListSubtypes(class_feature)
      if len(subdict) > 1:
      for stcode in subdict:
      if subdict[stcode]['SubtypeField'] != "":
      tsubtypefield = subdict[stcode]["SubtypeField"]
      subtypenames.append(subdict[stcode]['Name'])
      field_name = ["ASSETTYPE", "ASSETGROUP"]
      field = [f for f in desc.fields if f.name == field_name][0]
      domain = arcpy.da.ListDomains(desc.path)[field.domain]

      with arcpy.da.SearchCursor(class_feature, field_name) as cursor:
      for row in cursor:
      print(row[0],row[1])
Tags (3)
0 Kudos
3 Replies
BlakeTerhune
MVP Regular Contributor

This looks an awful lot like a school assignment.

kumarprince8071
New Contributor III

Can you please give me any suggestions how will i achieve the results as specified? 

0 Kudos
BlakeTerhune
MVP Regular Contributor

I'm intentionally being vague so as not to deprive you of a learning opportunity. The Esri documentation for arcpy is pretty good. Take a look at the ListSubtypes, ListFields, and ListDomains functions.

0 Kudos