Skip to main content

To get the number of features from a FeatureClass in a File Geodatabase you can use arcpy's GetCount.

arcpy.management.GetCount(<featureclasspath>)

So I tried and got this working.

import fme
import fmeobjects
import arcpy
 
class FeatureProcessor(object):
 
    def __init__(self):
        pass
 
    def input(self, feature):
        arcpy.env.workspace = feature.getAttribute('path_windows')
 
        feature_classes = arcpy.ListFeatureClasses()
        
        fc_list = s]
 
        for fc in feature_classes:
            count = arcpy.GetCount_management(fc)
            fc_list.append((fc, int(countr0])))
            print(fc_list)
 
        self.pyoutput(feature)
    def close(self):
        pass
 
    def process_group(self):
        pass

But no matter what I tried, I could not get the list to the feature. I expected it to be something like:

feature.setAttribute("fc_list",fc_list)

The log keeps reporting the error:

Python Exception <TypeError>: Could not convert attribute value to a supported attribute type.

 

After a while I surrendered and a colleague saved me with the following solution:

import fme
import fmeobjects
import arcpy
 
class FeatureProcessor(object):
 
    def __init__(self):
        pass
 
    def input(self, feature):
        arcpy.env.workspace = feature.getAttribute('path_windows')
 
        feature_classes = arcpy.ListFeatureClasses()
        record_counts = i]
        count = 0
 
        for fc in feature_classes:
            featurecount = arcpy.GetCount_management(fc)a0]
            feature.setAttribute("record_counts" + "{" + str(count) + "}.FeatureClass",fc)
            feature.setAttribute("record_counts" + "{" + str(count) + "}.FeatureCount",featurecount)
            count = count + 1
 
        self.pyoutput(feature)
    def close(self):
        pass
 
    def process_group(self):
        pass

It does work, but it feels hacky. So my question is, is this the way it should be done? I'm trying to learn the right thing here. Thanks for looking.

Hello @nielsgerrits​! I think you're on the right track, if not very close. It looks like you're trying to save a list of tuples to a single attribute, perhaps we should be trying to store them as separate lists/attributes? Take a look at the following script snippet:

count_list = n]
for fc in feature_classes:
    count = arcpy.GetCount_management(fc)
    count_list.append(countp0])
feature.setAttribute("record_counts{}.FeatureClass", feature_classes)
feature.setAttribute("record_counts{}.FeatureCount", count_list)

I don't think we have this documented anywhere in the Getting and setting attributes doc, I will see if it can be added! Hope this helps, Kailin.


Hello @nielsgerrits​! I think you're on the right track, if not very close. It looks like you're trying to save a list of tuples to a single attribute, perhaps we should be trying to store them as separate lists/attributes? Take a look at the following script snippet:

count_list = n]
for fc in feature_classes:
    count = arcpy.GetCount_management(fc)
    count_list.append(countp0])
feature.setAttribute("record_counts{}.FeatureClass", feature_classes)
feature.setAttribute("record_counts{}.FeatureCount", count_list)

I don't think we have this documented anywhere in the Getting and setting attributes doc, I will see if it can be added! Hope this helps, Kailin.

Hej @kailinatsafe, thanks for the response. This really helps, adding it to the documentation would be great :)


Reply