AnsweredAssumed Answered

SWITCH_SELECTION in SelectLayerByLocation_management

Question asked by dexconor on Oct 27, 2015
Latest reply on Oct 30, 2015 by curtvprice
import arcpy,sys
sdeConn = r"Database Connections\\Test.sde"
muniLoc = "Municipalities"
luLoc = "Land_Use"
tempLoc = "tempMuniLuRatio"
lu_lyr = "lu_lyr"

arcpy.env.workspace = sdeConn


try:
  print "MakeFeatureLayer_management lu_lyr"
  arcpy.MakeFeatureLayer_management(luLoc, lu_lyr) 
  prematchcount = int(arcpy.GetCount_management(lu_lyr).getOutput(0)) 
  print "MakeFeatureLayer_management muni_lyr"
  #arcpy.MakeFeatureLayer_management(muniLoc, "muni_lyr") 
  #print "SelectLayerByLocation_management NEW_SELECTION"
  #arcpy.SelectLayerByLocation_management(lu_lyr, "COMPLETELY_CONTAINS",muniLoc,"","NEW_SELECTION")
  print "SelectLayerByLocation_management SWITCH_SELECTION"
  arcpy.SelectLayerByLocation_management(lu_lyr, "COMPLETELY_CONTAINS",muniLoc,"","SWITCH_SELECTION")
  postmatchcount = int(arcpy.GetCount_management(lu_lyr).getOutput(0)) 
  if prematchcount == postmatchcount:
  print "SelectLayerByLocation_management DID NOT WORK"
  else:
  print "SelectLayerByLocation_management LOOKS GOOD"
  if arcpy.Exists(tempLoc):
  print "Delete_management "
  arcpy.Delete_management(tempLoc)
  print "CopyFeatures_management "
  arcpy.CopyFeatures_management(lu_lyr,tempLoc)
except Exception:
  e = sys.exc_info()[1]
  print(e.args[0])

 

Result is just same as lu_lyr even after SWICH_SELECTION option.

Where should I take a look to make this work?

 

Thanks,

Jack    

Outcomes