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?
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))
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?
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.SelectLayerByLocation_management(fcLyr, "INTERSECT", indexLyrSelect)
result = int(arcpy.GetCount_management(fcLyr).getOutput(0))
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.