<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>idea In Arcpy, add a way to detect query layers and their query definition in aprx files in Python Ideas</title>
    <link>https://community.esri.com/t5/python-ideas/in-arcpy-add-a-way-to-detect-query-layers-and/idi-p/1219624</link>
    <description>&lt;P&gt;We have several aprx files in our organization, and I'm trying to iterate over them and determine the data sources for each layer in them.&amp;nbsp; We have some query layers that are commonly used throughout our organization for viewing certains datasets in our enterprise geodatabases.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently when I use Arcpy.Describe on these query layers, the dataset type returned is 'FeatureLayer, which isn't accurate.&amp;nbsp; Through the Pro UI, this same layer shows a type of "Query Feature Layer" when I inspect it's properties.&amp;nbsp; The propertie window also shows the actual database query used by the layer, a property that is unique to query layers.&amp;nbsp; It would be great if query layers returned a unique dataType when being described so I know to process them a little differently. Then it would also be nice if the describe object returned also included a "Query" property that contains the text of the SQL query.&amp;nbsp; This way I can parse that text and determine what table (or multiple tables) are referenced by this map layer.&lt;/P&gt;</description>
    <pubDate>Thu, 06 Oct 2022 21:35:15 GMT</pubDate>
    <dc:creator>AndrewRudin1</dc:creator>
    <dc:date>2022-10-06T21:35:15Z</dc:date>
    <item>
      <title>In Arcpy, add a way to detect query layers and their query definition in aprx files</title>
      <link>https://community.esri.com/t5/python-ideas/in-arcpy-add-a-way-to-detect-query-layers-and/idi-p/1219624</link>
      <description>&lt;P&gt;We have several aprx files in our organization, and I'm trying to iterate over them and determine the data sources for each layer in them.&amp;nbsp; We have some query layers that are commonly used throughout our organization for viewing certains datasets in our enterprise geodatabases.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Currently when I use Arcpy.Describe on these query layers, the dataset type returned is 'FeatureLayer, which isn't accurate.&amp;nbsp; Through the Pro UI, this same layer shows a type of "Query Feature Layer" when I inspect it's properties.&amp;nbsp; The propertie window also shows the actual database query used by the layer, a property that is unique to query layers.&amp;nbsp; It would be great if query layers returned a unique dataType when being described so I know to process them a little differently. Then it would also be nice if the describe object returned also included a "Query" property that contains the text of the SQL query.&amp;nbsp; This way I can parse that text and determine what table (or multiple tables) are referenced by this map layer.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 21:35:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-ideas/in-arcpy-add-a-way-to-detect-query-layers-and/idi-p/1219624</guid>
      <dc:creator>AndrewRudin1</dc:creator>
      <dc:date>2022-10-06T21:35:15Z</dc:date>
    </item>
    <item>
      <title>Re: In Arcpy, add a way to detect query layers and their query definition in aprx files</title>
      <link>https://community.esri.com/t5/python-ideas/in-arcpy-add-a-way-to-detect-query-layers-and/idc-p/1219629#M150</link>
      <description>&lt;P&gt;I'd also add that query layers that are not spatial should be included as well.&amp;nbsp; Not sure if those kinds of views will appear as "Standalone Tables" instead of Feature Layers, but I think they should be included as well, so their data source can be parsed in python as well.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2022 21:45:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-ideas/in-arcpy-add-a-way-to-detect-query-layers-and/idc-p/1219629#M150</guid>
      <dc:creator>AndrewRudin1</dc:creator>
      <dc:date>2022-10-06T21:45:36Z</dc:date>
    </item>
    <item>
      <title>Re: In Arcpy, add a way to detect query layers and their query definition in aprx files</title>
      <link>https://community.esri.com/t5/python-ideas/in-arcpy-add-a-way-to-detect-query-layers-and/idc-p/1221333#M155</link>
      <description>&lt;P&gt;&lt;SPAN&gt;This is a very janky solution, but maybe it will work for you.&amp;nbsp; Documentation is poor/nonexistent for layers' CIM properties, but I tend to find what I need if I dig around in there long enough using dir() and IDE autofill.&amp;nbsp; Here's an example that might be useful:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# the "sqlQuery" property only exists for query layers, far as I can tell
def get_query(layer):
    cim = layer.getDefinition("V3")
    f_table = cim.featureTable
    data_conn = f_table.dataConnection
    
    if hasattr(data_conn, "sqlQuery"):
        return data_conn.sqlQuery
    return None

def main():
    aprx = arcpy.mp.ArcGISProject("current")
    active_map = APRX.activeMap
    layer = active_map.listLayers("my layer")[0]

    query = get_query(layer)
    if query:
        print(f"{layer.name} is a query layer: {query}")
    else:
        print(f"{layer.name} is not a query layer")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2022 23:06:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-ideas/in-arcpy-add-a-way-to-detect-query-layers-and/idc-p/1221333#M155</guid>
      <dc:creator>SamSzotkowski</dc:creator>
      <dc:date>2022-10-12T23:06:08Z</dc:date>
    </item>
    <item>
      <title>Re: In Arcpy, add a way to detect query layers and their query definition in aprx files</title>
      <link>https://community.esri.com/t5/python-ideas/in-arcpy-add-a-way-to-detect-query-layers-and/idc-p/1294534#M213</link>
      <description>&lt;P&gt;unfortunately the cim is not properly documented, but I suggest you open aprx with ctrl+PgDn, find a specific example of what you want to query properties about (e.g. TableViews) and see what tags are in the json.&lt;/P&gt;&lt;P&gt;If you know what you can get from "cim", you can user cim_object.tag_group.tag_subgroup.property... to get a value what you interested:&lt;/P&gt;&lt;P&gt;for example:&lt;/P&gt;&lt;P&gt;aprx = arcpy.mp.ArcGISProject("current")&lt;BR /&gt;maps = aprx.listMaps()&lt;BR /&gt;for map in maps:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; lyrs = map.listTables()&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for lyr in lyrs:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; desc = arcpy.Describe(lyr)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; cim = lyr.getDefinition("V3")&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print (map.name + "||" + lyr.name + "||" + cim.dataConnection.sqlQuery)&lt;/P&gt;&lt;P&gt;EVERYTHING that the map can store, you will find in the map's json file as text.&lt;BR /&gt;If the json schema gets too cluttered, export a map as a mapx file, which is essentially a json directly, and you will certainly find everything there&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 May 2023 15:33:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-ideas/in-arcpy-add-a-way-to-detect-query-layers-and/idc-p/1294534#M213</guid>
      <dc:creator>TóthRóbert</dc:creator>
      <dc:date>2023-05-31T15:33:11Z</dc:date>
    </item>
  </channel>
</rss>

