I'm trying to automate a mapping product that uses query layers within ArcGIS Pro. There are multiple maps, each with about 70 query layers.
I don't believe that altering the definition query of a layer is sufficient for my use case. The query layers use spatial queries. It's best to push that work to the database end instead of pulling everything and then trying to filter using a definition query.
I want to actually edit the query layer's query itself. This is straightforward enough to do within the ArcGIS Pro GUI. Right click on the layer, go to properties, revise the query. I'm having a heck of a time trying to figure out how I can accomplish this goal using python.
As a work around, I have tried to iterate through the layers in a map, pull in new query layer, apply the layer symbology from the old layer to the new layer, and delete the old layer. However, I'm running into a problem where the query layer appears to be added to the wrong map. As I mentioned earlier, I have several maps in my project. When I try to apply the layer symbology, I get an index out of range error. When I run the script in the Python Window in ArcGIS Pro, the query layer simply gets added to the active Map, not the map which contains the layers that I am currently iterating. There also does not appear to be a way to specify which map you would like the query layer to be added to with python, which is further intensifying my headache.
Can anyone offer any guidance or advice? Thank you.