<?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>topic Re: Updating the data source of a feature class in a feature dataset using Python in ArcGIS Pro in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/updating-the-data-source-of-a-feature-class-in-a/m-p/1116155#M62964</link>
    <description>&lt;P&gt;&lt;EM&gt;Using the&amp;nbsp;connectionProperties&amp;nbsp;dictionary&lt;/EM&gt; in&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/updatingandfixingdatasources.htm" target="_blank"&gt;Updating and fixing data sources—ArcGIS Pro | Documentation&lt;/A&gt;&amp;nbsp;and&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Updating data sources via the CIM&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;featuredatasets are mentioned in the latter section.&lt;/P&gt;&lt;P&gt;At least you can examine your existing structure to determine what the appropriate approach would be&lt;/P&gt;</description>
    <pubDate>Thu, 11 Nov 2021 23:37:52 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2021-11-11T23:37:52Z</dc:date>
    <item>
      <title>Updating the data source of a feature class in a feature dataset using Python in ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/updating-the-data-source-of-a-feature-class-in-a/m-p/1115949#M62956</link>
      <description>&lt;P&gt;I have an ArcGIS Pro document with a number of layers in and have created three scripts to; copy the layers to a new FGDB, create a datasource lookup table where the user can then enter a new target name if the copied feature class was renamed, and update the data sources using the csv lookup table.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Everything works great apart from feature classes found in feature datasets, which aren't repathed. I'm using the dictionary approach and layer.updateConnectionProperties(). Should the feature dataset name be part of the workspace ('database:') or possibly in with the feature class name ('dataset:')?&lt;/P&gt;&lt;P&gt;e.g. r"C:\GIS\Test.gdb\Fields\Oil"&lt;/P&gt;&lt;P&gt;Should the find dictionary database be&amp;nbsp;r"C:\GIS\Test.gdb\Fields" and the dataset "Oil" or..&lt;/P&gt;&lt;P&gt;the find dictionary database be r"C:\GIS\Test.gdb" and the dataset "Fields\Oil" ?&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# if the layer datasource matches the datasource in the LU table (row[6])
# row[4] is the source workspace path (FGDB)
# row[5] is the feature class name
# row[7] is the target workspace path (FGDB)
# row[8] is the target feature class name
if layer.dataSource == row[6]:
    find_dict = {'connection_info': {'database': row[4]},
                 'dataset': row[5],
                 'workspace_factory': 'File Geodatabase'}
    replace_dict = {'connection_info': {'database': row[7]},
                    'dataset': row[8],
                    'workspace_factory': 'File Geodatabase'}
    layer.updateConnectionProperties(find_dict, replace_dict)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Nov 2021 07:57:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updating-the-data-source-of-a-feature-class-in-a/m-p/1115949#M62956</guid>
      <dc:creator>MattHowe</dc:creator>
      <dc:date>2021-11-11T07:57:27Z</dc:date>
    </item>
    <item>
      <title>Re: Updating the data source of a feature class in a feature dataset using Python in ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/updating-the-data-source-of-a-feature-class-in-a/m-p/1116155#M62964</link>
      <description>&lt;P&gt;&lt;EM&gt;Using the&amp;nbsp;connectionProperties&amp;nbsp;dictionary&lt;/EM&gt; in&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/updatingandfixingdatasources.htm" target="_blank"&gt;Updating and fixing data sources—ArcGIS Pro | Documentation&lt;/A&gt;&amp;nbsp;and&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Updating data sources via the CIM&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;featuredatasets are mentioned in the latter section.&lt;/P&gt;&lt;P&gt;At least you can examine your existing structure to determine what the appropriate approach would be&lt;/P&gt;</description>
      <pubDate>Thu, 11 Nov 2021 23:37:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updating-the-data-source-of-a-feature-class-in-a/m-p/1116155#M62964</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-11-11T23:37:52Z</dc:date>
    </item>
    <item>
      <title>Re: Updating the data source of a feature class in a feature dataset using Python in ArcGIS Pro</title>
      <link>https://community.esri.com/t5/python-questions/updating-the-data-source-of-a-feature-class-in-a/m-p/1116245#M62967</link>
      <description>&lt;P&gt;Thanks Dan. I completely overlooked the CIM part assuming it wasn't relevant. I need new glasses.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;else:
    if not ".gdb" in layer.dataSource.split(os.path.sep)[-2]:
        arcpy.AddMessage(layer.dataSource)
        with arcpy.da.SearchCursor(input_csv, csv_headers) as cursor:
            for row in cursor:
                if layer.dataSource == row[6]:
                    lyr_cim = layer.getDefinition('V2')
                    dc = arcpy.cim.CreateCIMObjectFromClassName('CIMStandardDataConnection', 'V2')
                    dc.workspaceConnectionString = f"DATABASE={row[7]}"
                    dc.workspaceFactory = "FileGDB"
                    dc.dataset = row[8]
                    lyr_cim.featureTable.dataConnection = dc
                    layer.setDefinition(lyr_cim)&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 12 Nov 2021 09:52:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/updating-the-data-source-of-a-feature-class-in-a/m-p/1116245#M62967</guid>
      <dc:creator>MattHowe</dc:creator>
      <dc:date>2021-11-12T09:52:16Z</dc:date>
    </item>
  </channel>
</rss>

