Greetings,
I am using the ArcGIS API for Python and I am struggling with passing parameters to the gis.content.search function.
try:
query_list = ['Boundaries', 'ConservationEasements', 'Geographic Names', 'Hydrography', 'LandCover', 'Mapping Control', 'MontanaMask', 'Montana Managed Areas', 'Montana NAIP', 'NAIP', 'Parcel', 'PLSSS', 'PublicLands', 'Roads', 'Structures', 'Watershed', 'Wetlands']
item_type_list = list()st = 'item_type =' + '"' + 'Feature Layer' + '"'
item_type_list.append(st)
st = 'item_type =' + '"' + 'Imagery Layer'# + '"'
item_type_list.append(st)
st = 'item_type =' + '"' + 'Map Image Layer'# + '"'
item_type_list.append(st)for q in query_list:st = 'query=' + '"' + q + ' AND owner:MontanaStateLibrary' + '"' #+ ', '
temp_list = gis.content.search(st)
Am I missing something obvious?
arcgis-api-python
Solved! Go to Solution.
I see what Dan is getting at above, what about:
st = q + ' AND owner:MontanaStateLibrary' temp_list = gis.content.search(query=st)
arcgis.gis module — arcgis 1.4.2 documentation
query= is a parameter designator and shouldn't be in quotes or part or your quoted string I suspect
Yes, this is where I had decided I was going astray.
I am struggling with how to pass the string, st, to the parameter designator . Basic Python stuff I think.
This does not work either:
st = '"' + 'Boundaries AND owner:MontanaStateLibrary' + '"'
gis.content.search(query=st)
>>> st = '"' + 'Boundaries AND owner:MontanaStateLibrary' + '"'
>>> print(st)
"Boundaries AND owner:MontanaStateLibrary"
>>> gis.content.search(query=st)
[]
If I type in command parameters and run the snippet temp_list = gis.content.search(query="Boundaries AND owner:MontanaStateLibrary)
Is that just missing the final " in your quote that you used? because it is a string already if you put one in (ie st = "Boundaries AND owner:MontanaStateLibrary" )
In the previous message I missed the final quote on the string when copying and pasting to this editor.
from the interactive window:
>>> templist = gis.content.search(query="Boundaries AND owner:MontanaStateLibrary")
>>> print(len(templist))
10
>>> st = '"' + 'Boundaries AND owner:MontanaStateLibrary' + '"'
>>> print(st)
"Boundaries AND owner:MontanaStateLibrary"
>>> templist = gis.content.search(query=st)
>>> print(len(templist))
0
>>> st = 'query =' + '"' + 'Boundaries AND owner:MontanaStateLibrary' + '"'
>>> print(st)
query ="Boundaries AND owner:MontanaStateLibrary"
>>> templist = gis.content.search(st)
>>> print(len(templist))
0
Robert... getting lost... you seem to want to quote an already quoted string... maybe Josh knows, but I don't see
st = "Boundaries AND owner:MontanaStateLibrary"
query = st
if that already worked... (their help really needs some concrete examples for sure
Dan,
Sorry for the confusion.
I am not attempting to quote an already quoted string. What I am attempting to do is to determine the proper way to pass parameters to the gis.content.search() function.
ha, on "their help really needs some concrete examples." I couldn't agree more, the ArcGIS API for Python documentation has a lllooonnnggg way to go.
What is you change your last two lines of code:
st = '"' + q + ' AND owner:MontanaStateLibrary' + '"' #+ ', '
temp_list = gis.content.search(query=st)
You can't pass named arguments the way you are trying to pass them in your current code.
Yes, I had assumed that I was passing the parameters incorrectly. Do you have a suggestion as to how to pass parameters?
Thanks for any insight.