AnsweredAssumed Answered

Python - SDE Get Feature Count

Question asked by NEOMAPPER on Sep 18, 2019
Latest reply on Sep 18, 2019 by NEOMAPPER

I am trying to figure out how to get a count on each feature class in our SDE database and later record it to a text file but I am having trouble figuring out how to setup the "Get Count" portion of the script. I haven't had any success incorporating the  "Get Count"  example. 

 

When "My Script" runs it prints the fc name (.e.g. jmillePCReplica.DBO.Wayne_Parcels) but when I plug that variable / fc name in place to the  "Get Count"  example it fails. 

 

Any ideas?

 

 

My Script

# Import system modules
import arcpy, os
from arcpy import env

# Set workspace
sdeConnection = r"Database Connections\STR-DT-JMILLE.sde"

feature_classes = []

walk = arcpy.da.Walk(sdeConnection, datatype="FeatureClass", type="All")
print("Starting..")
for dirpath, dirnames, filenames in walk:
    for filename in filenames:
     feature_classes.append(os.path.join(dirpath, filename))
     print(filename)

 

Get Count Example

result = arcpy.GetCount_management(filename)
print('{} has {} records'.format(filename, result[0]))

 

 

My Script results

Starting..
jmillePCReplica.DBO.P_AbandonedDevice
jmillePCReplica.DBO.P_AbandonedPipe
jmillePCReplica.DBO.P_AbandonedService
jmillePCReplica.DBO.P_AlignmentSheet
jmillePCReplica.DBO.P_CapitalProject
jmillePCReplica.DBO.P_Coupon
jmillePCReplica.DBO.P_CPArea
jmillePCReplica.DBO.P_DrinkingWater
jmillePCReplica.DBO.P_EcologicalArea
jmillePCReplica.DBO.P_ExcavationDamage
jmillePCReplica.DBO.P_ExposedPipeInspect
jmillePCReplica.DBO.P_GasLeak

Outcomes