Select to view content in your preferred language

gis.content.search() parameter substitution

7546
14
Jump to solution
08-09-2018 09:09 AM
RobertHolliday
Occasional Contributor

Greetings,

I am using the ArcGIS API for Python and I am struggling with passing parameters to the gis.content.search function.

  1. If I type in command parameters  and run the snippet temp_list  =  gis.content.search(query="Boundaries AND owner:MontanaStateLibrary) a list of content is returned. 
  2. However if I build a string, st = 'query=' + '"' + 'Boundaries AND owner:MontanaStateLibrary' + '"',  and do something like this: temp_list  =  gis.content.search(st) an empty list is returned.
    1. In troubleshooting I have copied the printed string, st,  from the interactive window and pasted the text into the gis.content.search()  command which results in a list of content.
  3. As of right now the following code is just a brain dump.  I am using 2 lists to build the parameter string.

    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‌

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

I see what Dan is getting at above, what about:

st = q + ' AND owner:MontanaStateLibrary'
temp_list = gis.content.search(query=st)

View solution in original post

14 Replies
DanPatterson_Retired
MVP Emeritus

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

0 Kudos
RobertHolliday
Occasional Contributor

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)
[]

0 Kudos
DanPatterson_Retired
MVP Emeritus

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" )

0 Kudos
RobertHolliday
Occasional Contributor

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

0 Kudos
DanPatterson_Retired
MVP Emeritus

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

RobertHolliday
Occasional Contributor

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.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

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.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

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.

0 Kudos
RobertHolliday
Occasional Contributor

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.

0 Kudos