<?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 Ability to identify a Query Layer in ArcPy &amp;amp; Modify them in ArcGIS Pro Ideas</title>
    <link>https://community.esri.com/t5/arcgis-pro-ideas/ability-to-identify-a-query-layer-in-arcpy-amp/idi-p/954226</link>
    <description>&lt;P&gt;ArcPy functionality using and detecting Query Layers is very limited.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Identification&lt;/STRONG&gt; - In the arcpy.mapping module there is no proper way to identify a query layer. There should be a method or property to identify the layer in question is a query layer.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Update Query&lt;/STRONG&gt; - In the arcpy.mapping module there is no ability to modify the query portion of the query layer.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;repathDataSource&lt;/STRONG&gt; - This method does not work properly for Query Layers especially if the database name has changed. Using SQL Server the database name is part of the query and this method does not update the database inside the query layer properties. This could be dealt with if updating the query was possible but currently it is not so repathing a map document using query layers with differing databases is not an easy task or nearly impossible.&lt;/LI&gt;&lt;/UL&gt;</description>
    <pubDate>Mon, 29 Jul 2024 14:07:24 GMT</pubDate>
    <dc:creator>RonnieRichards</dc:creator>
    <dc:date>2024-07-29T14:07:24Z</dc:date>
    <item>
      <title>Ability to identify a Query Layer in ArcPy &amp; Modify them</title>
      <link>https://community.esri.com/t5/arcgis-pro-ideas/ability-to-identify-a-query-layer-in-arcpy-amp/idi-p/954226</link>
      <description>&lt;P&gt;ArcPy functionality using and detecting Query Layers is very limited.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;Identification&lt;/STRONG&gt; - In the arcpy.mapping module there is no proper way to identify a query layer. There should be a method or property to identify the layer in question is a query layer.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;Update Query&lt;/STRONG&gt; - In the arcpy.mapping module there is no ability to modify the query portion of the query layer.&lt;/LI&gt;&lt;LI&gt;&lt;STRONG&gt;repathDataSource&lt;/STRONG&gt; - This method does not work properly for Query Layers especially if the database name has changed. Using SQL Server the database name is part of the query and this method does not update the database inside the query layer properties. This could be dealt with if updating the query was possible but currently it is not so repathing a map document using query layers with differing databases is not an easy task or nearly impossible.&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Mon, 29 Jul 2024 14:07:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-ideas/ability-to-identify-a-query-layer-in-arcpy-amp/idi-p/954226</guid>
      <dc:creator>RonnieRichards</dc:creator>
      <dc:date>2024-07-29T14:07:24Z</dc:date>
    </item>
    <item>
      <title>Re: Ability to identify a Query Layer in ArcPy &amp; Modify them</title>
      <link>https://community.esri.com/t5/arcgis-pro-ideas/ability-to-identify-a-query-layer-in-arcpy-amp/idc-p/1510840#M31256</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/7683"&gt;@RonnieRichards&lt;/a&gt;&amp;nbsp;this should be possible using &lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/python-cim-access.htm" target="_self"&gt;Python CIM Access&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Here is a code snippet that could be used to find if a layer is a query layer.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject('current')
m = aprx.listMaps()[0]
qlyr = m.listLayers('MyQueryLayer')[0]
cim_qlyr = qlyr.getDefinition("V3")
if type(cim_qlyr.featureTable.dataConnection).__name__ == 'CIMSqlQueryDataConnection':
    print('Ureka, its a query layer')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Next you could continue with modifying other CIM property, like the SQLQuery&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;l_cim.featureTable.dataConnection.sqlQuery = "select OBJECTID,Shape,STATE_NAME,STATE_FIPS,SUB_REGION,STATE_ABBR,POP1990,POP2000,POP90_SQMI from ARCPYMAPPING_01.APM_PRO_states WHERE SUB_REGION = 'Mtn'"
qlyr.setDefinition(cim_qlyr)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data connection info is also there. Does this work for you?&lt;/P&gt;&lt;P&gt;Jeff - Layout and arcpy.mp teams&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2024 19:53:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-ideas/ability-to-identify-a-query-layer-in-arcpy-amp/idc-p/1510840#M31256</guid>
      <dc:creator>JeffBarrette</dc:creator>
      <dc:date>2024-07-26T19:53:58Z</dc:date>
    </item>
  </channel>
</rss>

