AnsweredAssumed Answered

Use list as input parameter to query FC

Question asked by jay.kapalczynski on May 5, 2017
Latest reply on May 5, 2017 by jay.kapalczynski
  1. I have a LIST containing SiteNames (this is a LIST i created named "mynewlist")
  2. I have a FC that has a SiteName field

 

I want to create a LIST / ARRAY of the data that is in the FC, where the List (mynewlist) and FC (Field "SiteName") are the same.

 

For instance...

I have 5 Sitenames in the LIST (# 1 above)

I have 200 Sitenames in the FC (#2 above)

 

I want a resulting LIST that is comprised of fields 1-9 from the FC where the LIST values are the same as the FC SiteName field.

 

Think I have everything in order just need help with the actual query???

 

 I don't even know if I can create a Query from a LIST and a FC....do I need to convert the list to something else first?

 

 

arcpy.env.workspace = "C:\\Users\\xxxx\\AppData\\Roaming\ESRI\\Desktop10.4\\ArcCatalog\\xx@xx.sde"
myFCLayer = "BoatRampsWGS"

#Set variables for the FC above
var_SITENAME,var_WATERBODY,var_ACCESSAREA,var_BODYOFWATE = 'SITENAME' ,'WATERBODY','ACCESSAREA','BODYOFWATE'
var_TYPE,var_NO_OFRAMPS,var_COUNTY,var_REGION = 'TYPE','NO_OFRAMPS','COUNTY','REGION'
var_Lat,var_Long = 'Lat','Long'

QueryBoatRamps = [var_SITENAME,var_COUNTY,var_REGION,var_WATERBODY,var_BODYOFWATE,var_ACCESSAREA,var_TYPE,var_NO_OFRAMPS,var_Lat,var_Long]


# Build a query that will grab the records from the FC where the two SiteName fields are the same from the FC (BoatRampsWGS) and the LIST (myBoatRampList)

RampQry=  #Grab all the records from FC (BoatRampsWGS) where th4e Sitename is the same as the sitename in the LIST (myBoatRampList)



# write these records to a new list
BoatRampList=[]
with arcpy.da.SearchCursor(myFCLayer, QueryBoatRamps, RampQry) as cursor:
    for row in cursor:
        varBoatRampsList = str('{0},{1},{2},{3},{4},{5},{6},{7},{8},{9}'.format(row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8],row[9]))
        BoatRampList.append(varBoatRampsList)

Outcomes