I have some troubles to understand the behaviour of my code below. Obviously, GetCount_Management doesn't match the rows in my layer selection.
This code is part of a long for loop. I have hidden the rest for clarity purposes.
#...
# tmpThi is a in_memory output of CreateThiessenPolygons_analysis
# evtSts is a pandas Serie containing the name of rainfall stations of interest
arcpy.MakeFeatureLayer_management(tmpThi, "thLyr") # creating a layer
evtStsNames = [name for name in evtSts] # creating a list of station of interest
# select the Thiessen polygons where station name 'Nom' is in the list
arcpy.SelectLayerByAttribute_management("thLyr", "NEW_SELECTION", ' "Nom" IN (\'' + '\',\''.join(evtStsNames) + '\')' )
rows = arcpy.SearchCursor("thLyr") # Counting selected features with Cursor
rowCount = 0
for row in rows:
rowCount += 1
print len(evtStsNames), arcpy.GetCount_management("thLyr").getOutput(0), rowCount # This should print the same result
This print a lower GetCount_management as follow:
3 2 3
4 3 4
7 5 7
1 1 1
3 1 3
4 2 4
1 1 1
6 2 6
14 6 14
...
This is quite confusing to me.
It seems that if I store the Thiessen polygons not in "in_memory" getCount match rowCount. I am still trying to understand what really happens
thLyr
to the map can you verify thatarcpy.SelectLayerByAttribute_management()
is indeed selecting features?arcpy.CopyFeatures_management("thLyr", "\\tmp\\thSel_{0}".format(i))
, the number of feature saved is the one given by GetCount_management. I expect it to be rather the rowCount.