Select to view content in your preferred language

Get Feature Count

4884
5
02-18-2015 01:55 AM
khadijahnas
Occasional Contributor

Dear Arcgis user,

 

I have questions.

 

The situation is as bellow,

 

Database 1 : SDE database.Topo

Feature Class : 170

 

Database 2 : SDE database.AOI

Feature Class : 1

 

I want to get feature count of 170 feature classes base on selected AOI in SDE database.AOI.

How to get the total of the features?

 

Thank You

 

Khadijah.

0 Kudos
5 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Khadijah,

One way you can do this is by using python.  Below is an example on how to iterate through each feature class in the Topo database, perform a select by location using the AOI feature class, and then running the Get Count to retrieve how many features are selected.

import arcpy
from arcpy import env
env.overwriteOutput = 1

aoi = r"Database Connections\AOI.sde\AOI"
arcpy.MakeFeatureLayer_management(aoi, "aoiLyr")

env.workspace = r"Database Connections\Topo.sde"
for fc in arcpy.ListFeatureClasses():
    arcpy.MakeFeatureLayer_management(fc, "fcLyr")
    arcpy.SelectLayerByLocation_management("fcLyr", "INTERSECT", "aoiLyr", "NEW_SELECTION")
    arcpy.GetCount_management("fcLyr")
    print fc + ": " + str(arcpy.GetMessage(0))
khadijahnas
Occasional Contributor

Hi Jake,

Thank you very much with your help.

I have modified the script but return error.

What is wrong with this script?

FYI, all the feature class locate under one dataset call Topo and also under version, is that the problem?

import arcpy 

from arcpy import env

env.overwriteOutput = True

# Make a layer from the feature class

indexLyr = r"Database Connections\Connection to Metadata5K.sde\MY711T_5K" 

indexLyrSelect = "MY711T5 Selection"

kode = arcpy.GetParameterAsText(0)

arcpy.MakeFeatureLayer_management(indexLyr, indexLyrSelect, '"SHEET_NO" = \'' + kode +'\'')

# Select all feature class that overlap aoi

env.workspace = r"Database Connections\Topo.sde" 

for fc in arcpy.ListFeatureClasses(): 

arcpy.MakeFeatureLayer_management(fc, "fcLyr")

            arcpy.SelectLayerByLocation_management(fcLyr, "INTERSECT", indexLyrSelect)        

            arcpy.GetCount_management("fcLyr")

            result = int(arcpy.GetCount_management(fcLyr).getOutput(0))

            print result

0 Kudos
DanPatterson_Retired
MVP Emeritus

The error needs to be posted in order to assess a potential solution.

0 Kudos
khadijahnas
Occasional Contributor

script.jpg

0 Kudos
DanPatterson_Retired
MVP Emeritus

Well, given that Jake posted 18 lines of code and your error is on line 26 leads me to suggest as the error message does...you code isn't indented properly...python is particular about following indentation rules.

0 Kudos