Never ending While   Cant figure out my error?

969
9
Jump to solution
03-11-2014 09:20 AM
AliciaMein
New Contributor III
for row in wtlndRow:                  if row.WtlndUnitID is None:             totalArea = 0             wtlndUnitID += 1             adjWtlnd = arcpy.MakeFeatureLayer_management(wtlnd4Units, "in_memory\\adjWtlnd")             arcpy.SelectLayerByLocation_management(adjWtlnd,"SHARE_A_LINE_SEGMENT_WITH",row.shape, "", "NEW_SELECTION")             numPolys = 1             count = 0              while numPolys != count:                 numPolys = arcpy.GetCount_management(adjWtlnd)                 arcpy.SelectLayerByLocation_management(adjWtlnd,"SHARE_A_LINE_SEGMENT_WITH", wtlnd4Units,"",  "ADD_TO_SELECTION")                 count = arcpy.GetCount_management(adjWtlnd)



Cant figure out why this wont evaluate to true.
Thanks!
Alicia
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ClintDow
Occasional Contributor
That line returns the number of rows in a feature class and ensures it is an integer. The getOutput() is because GetCount_management returns a results object, so this gets the value rather than the object.

View solution in original post

0 Kudos
9 Replies
JoshuaChisholm
Occasional Contributor III
Hello Alicia,

I don't think you can use arcpy.MakeFeatureLayer_management like that. I think you have to refer to the feature layer using "in_memory\\adjWtlnd".
Try changing:
adjWtlnd = arcpy.MakeFeatureLayer_management(wtlnd4Units, "in_memory\\adjWtlnd")

To:
arcpy.MakeFeatureLayer_management(wtlnd4Units, "in_memory\\adjWtlnd")
adjWtlnd = "in_memory\\adjWtlnd"
0 Kudos
AliciaMein
New Contributor III
#Create "in_memory" feture class for processing
#
    arcpy.MakeFeatureLayer_management("wtlnd4Anlys", "in_memory\\wtlnd4Units")
    wtlnd4Units = "in_memory\\wtlnd4Anlys"

#Loop through wetlands and select the adjacent polys populate WtlndUnitID and UnitArea
#
    wtlndRow = arcpy.SearchCursor("wtlnd4Anlys")
    wtlndUnitID = 0
    for row in wtlndRow:
        
        if row.WtlndUnitID is None:
            totalArea = 0
            wtlndUnitID += 1
            arcpy.MakeFeatureLayer_management("wtlnd4Anlys", "in_memory\\adjWtlnd")
            adjWtlnd = "in_memory\\adjWtlnd"
            arcpy.SelectLayerByLocation_management(adjWtlnd,"SHARE_A_LINE_SEGMENT_WITH",row.shape, "", "NEW_SELECTION")
            numPolys = 1
            count = 0

            while numPolys != count:
                numPolys = arcpy.GetCount_management(adjWtlnd)
                arcpy.SelectLayerByLocation_management(adjWtlnd,"SHARE_A_LINE_SEGMENT_WITH", wtlnd4Units,"",  "ADD_TO_SELECTION")
                count = arcpy.GetCount_management(adjWtlnd)
                


I made changes, but now I receive an error at :
  arcpy.SelectLayerByLocation_management(adjWtlnd,"SHARE_A_LINE_SEGMENT_WITH", wtlnd4Units,"",  "ADD_TO_SELECTION")


ERROR 000732: Selecting Features: Dataset in_memory\wtlnd4Anlys does not exist or is not supported

It seems it will take the in_memory: adjWtlnd but wont accept the second in_memory.  But Im not really sure.
Thanks for your help!
Alicia
0 Kudos
ClintDow
Occasional Contributor
That problem seems to be related to the first couple lines:

    arcpy.MakeFeatureLayer_management("wtlnd4Anlys", "in_memory\\wtlnd4Units")
    wtlnd4Units = "in_memory\\wtlnd4Anlys"


You output to "in_memory\\wtlnd4Units", but the wtlnd4Units string is "in_memory\\wtlnd4Anlys"
From what I can tell from your script those should be the same strings.
0 Kudos
DouglasSands
Occasional Contributor II
Hello Alicia,

I don't think you can use arcpy.MakeFeatureLayer_management like that. I think you have to refer to the feature layer using "in_memory\\adjWtlnd".
Try changing:
adjWtlnd = arcpy.MakeFeatureLayer_management(wtlnd4Units, "in_memory\\adjWtlnd")

To:
arcpy.MakeFeatureLayer_management(wtlnd4Units, "in_memory\\adjWtlnd")
adjWtlnd = "in_memory\\adjWtlnd"


Just to clarify, the code as written initially

adjWtlnd = arcpy.MakeFeatureLayer_management(wtlnd4Units, "in_memory\\adjWtlnd")


should be fine, unless in memory layers work differently for some reason. This is how I always create feature layers, as it saves a line of code and you don't have to worry so much about typos. MakeFeatureLayer_management returns a string, which is the name of the created layer.
0 Kudos
DouglasSands
Occasional Contributor II
for row in wtlndRow:
        
        if row.WtlndUnitID is None:
            totalArea = 0
            wtlndUnitID += 1
            adjWtlnd = arcpy.MakeFeatureLayer_management(wtlnd4Units, "in_memory\\adjWtlnd")
            arcpy.SelectLayerByLocation_management(adjWtlnd,"SHARE_A_LINE_SEGMENT_WITH",row.shape, "", "NEW_SELECTION")
            numPolys = 1
            count = 0

            while numPolys != count:
                numPolys = arcpy.GetCount_management(adjWtlnd)
                arcpy.SelectLayerByLocation_management(adjWtlnd,"SHARE_A_LINE_SEGMENT_WITH", wtlnd4Units,"",  "ADD_TO_SELECTION")
                count = arcpy.GetCount_management(adjWtlnd)



Cant figure out why this wont evaluate to true.
Thanks!
Alicia


Have you tried printing the values of numPolys and count to the screen? Could provide a hint...
0 Kudos
AliciaMein
New Contributor III
That problem seems to be related to the first couple lines:

    arcpy.MakeFeatureLayer_management("wtlnd4Anlys", "in_memory\\wtlnd4Units")
    wtlnd4Units = "in_memory\\wtlnd4Anlys"


You output to "in_memory\\wtlnd4Units", but the wtlnd4Units string is "in_memory\\wtlnd4Anlys"
From what I can tell from your script those should be the same strings.


Thanks let me try that as well!!!
I need a break from this code for a little while obviously. 
I did not see it!
Thanks
Alicia
0 Kudos
AliciaMein
New Contributor III
Can anyone break this line down?

int(arcpy.GetCount_management(tempLayer).getOutput(0))

I saw this used in a for loop, and wonder if I should go this direction, because I can not make this loop work as it is.
0 Kudos
ClintDow
Occasional Contributor
That line returns the number of rows in a feature class and ensures it is an integer. The getOutput() is because GetCount_management returns a results object, so this gets the value rather than the object.
0 Kudos
AliciaMein
New Contributor III
I am just now incorporating this.  I am all but positive this is the answer I was needing.  Thanks!

I did test and this does solve the endless loop, but I do not want to say that this code is perfect yet.  I am still working on the iterative selection which is not working as expected.

Thanks!!!
0 Kudos