<?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: Copying GDB Features to existing SDE Features in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/copying-gdb-features-to-existing-sde-features/m-p/1201691#M65277</link>
    <description>&lt;P&gt;1. please insert you code as a code sample rather then a screenshot&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="forestknutsen1_0-1660177454159.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/48364iEEF059E4CF07D2D0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="forestknutsen1_0-1660177454159.png" alt="forestknutsen1_0-1660177454159.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;2. Is your code throwing an error?&lt;BR /&gt;3. I can make some suggestions right off bat. I think I would used a dictionary or a tuple for the target and source information. Not two lists. so:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# tuple
my_tuple_list = [(target_1, source_1), (target_2, source_2)...  ...(target_n, source_n)]
# dict
my_dict = {target_1: source_1, target_2: source_2...  ...target_n: source_n}&lt;/LI-CODE&gt;&lt;P&gt;I would also suggest using os.path.join for creating paths not string concatenation with "+"&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.geeksforgeeks.org/python-os-path-join-method/" target="_blank"&gt;https://www.geeksforgeeks.org/python-os-path-join-method/&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Thu, 11 Aug 2022 00:31:51 GMT</pubDate>
    <dc:creator>forestknutsen1</dc:creator>
    <dc:date>2022-08-11T00:31:51Z</dc:date>
    <item>
      <title>Copying GDB Features to existing SDE Features</title>
      <link>https://community.esri.com/t5/python-questions/copying-gdb-features-to-existing-sde-features/m-p/1201650#M65276</link>
      <description>&lt;P&gt;I am trying to clear existing records in a list of SDE features and then copy duplicate (but updated) GDB records into those same SDE features.&amp;nbsp; Looking for advice on how to set up the loop through both lists within the append tool so each GBD feature is copied into its respective SDE feature.&amp;nbsp; The code below throws the error "ValueError: too many values to unpack".&lt;/P&gt;&lt;LI-CODE lang="python"&gt;SDEFeatures = [CBTSDE + "REF.SDE.NamedRMA", CBTSDE + "REF.SDE.NamedSMA", CBTSDE + "REF.SDE.OR_State_Type", CBTSDE + "REF.SDE.RdRt",
               CBTSDE + "REF.SDE.RMA", CBTSDE + "REF.SDE.Road_Easement", CBTSDE + "REF.SDE.Road_Gates", CBTSDE + "REF.SDE.Road_Type",
               CBTSDE + "REF.SDE.RoadRouteNamed", CBTSDE + "REF.SDE.SMA", CBTSDE + "REF.SDE.Stream_Fish_Barrier", CBTSDE + "REF.SDE.Stream_Fish_Use",
               CBTSDE + "REF.SDE.Stream_Flow_Regime", CBTSDE + "REF.SDE.Stream_Size", CBTSDE + "REF.SDE.Stream_StateType", CBTSDE + "REF.SDE.StreamRouteNamed", CBTSDE + "REF.SDE.StrRt"]
GDBFeatures = [CBTGDBp + "NamedRMA", CBTGDBp + "NamedSMA", CBTGDBp + "OR_State_Type", CBTGDBp + "RdRt", CBTGDBp + "RMA", CBTGDBp + "Road_Easement",
               CBTGDBp + "Road_Gates" + CBTGDBp + "Road_Type", CBTGDBp + "RoadRouteNamed", CBTGDBp + "SMA", CBTGDBp + "Stream_Fish_Barrier",
               CBTGDBp + "Stream_Fish_Use", CBTGDBp + "Stream_Flow_Regime", CBTGDBp + "Stream_Size", CBTGDBp + "Stream_StateType", CBTGDBp + "StreamRouteNamed", CBTGDBp + "StrRt"]

# Empty and Reload SDE feature
if current_status == 'YES':
    print 'Processing empty and reload SDE feature'
    for items in SDEFeatures:
        arcpy.DeleteRows_management(items)
    for (GDBitems, SDEitems) in (GDBFeatures, SDEFeatures):    
        arcpy.Append_management(GDBitems, SDEitems, "NO_TEST", "", "")
    print 'NetAcresCurrent SDE feature has been updated.'
else:
    print 'NetAcresCurrent SDE feature has NOT been updated.'
&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 14:09:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copying-gdb-features-to-existing-sde-features/m-p/1201650#M65276</guid>
      <dc:creator>ClintBoaz1</dc:creator>
      <dc:date>2022-08-11T14:09:01Z</dc:date>
    </item>
    <item>
      <title>Re: Copying GDB Features to existing SDE Features</title>
      <link>https://community.esri.com/t5/python-questions/copying-gdb-features-to-existing-sde-features/m-p/1201691#M65277</link>
      <description>&lt;P&gt;1. please insert you code as a code sample rather then a screenshot&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="forestknutsen1_0-1660177454159.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/48364iEEF059E4CF07D2D0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="forestknutsen1_0-1660177454159.png" alt="forestknutsen1_0-1660177454159.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;2. Is your code throwing an error?&lt;BR /&gt;3. I can make some suggestions right off bat. I think I would used a dictionary or a tuple for the target and source information. Not two lists. so:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# tuple
my_tuple_list = [(target_1, source_1), (target_2, source_2)...  ...(target_n, source_n)]
# dict
my_dict = {target_1: source_1, target_2: source_2...  ...target_n: source_n}&lt;/LI-CODE&gt;&lt;P&gt;I would also suggest using os.path.join for creating paths not string concatenation with "+"&lt;/P&gt;&lt;P&gt;&lt;A href="https://www.geeksforgeeks.org/python-os-path-join-method/" target="_blank"&gt;https://www.geeksforgeeks.org/python-os-path-join-method/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 00:31:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copying-gdb-features-to-existing-sde-features/m-p/1201691#M65277</guid>
      <dc:creator>forestknutsen1</dc:creator>
      <dc:date>2022-08-11T00:31:51Z</dc:date>
    </item>
    <item>
      <title>Re: Copying GDB Features to existing SDE Features</title>
      <link>https://community.esri.com/t5/python-questions/copying-gdb-features-to-existing-sde-features/m-p/1201736#M65281</link>
      <description>&lt;P&gt;We do something similar for migrating data to test servers and I'll echo &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/200586"&gt;@forestknutsen1&lt;/a&gt;'s suggestion of using a dictionary.&lt;/P&gt;&lt;P&gt;We use a list of featureclass names from a text file that we use to create the src_paths and dst_paths by iterating over the list and creating the path strings. We also track last edit times and check if the dataset is older/newer/same or different feature counts and handle it accordingly so we also have a lot more key:value entries.&lt;/P&gt;&lt;P&gt;The fc name would replace the 'fc_name' key in the dictionary below and is used for status/ error messages (omitted here):&lt;/P&gt;&lt;LI-CODE lang="c"&gt;fc_dict = {'fc_name': {'src_path': 'path to src fc', 'dst_path': 'path to dest fc'}, ... }

# then iterate over it:

for fc, fcPaths in fc_dict.items():
    if arcpy.Exists(fcPaths['dst_path']):
        arcpy.DeleteFeatures_management(dst_path)
        arcpy.Append_management(src_path, dst_path, "NO_TEST")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You could make the paths when you create the dictionary/ iterating over the list of featureclass names.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;fc_dict = {}

source_path = r'path to the source db\dataset.SDE.'
dest_path = r'path to the dest db'

for fc_name in ['fc1', 'fc2', 'fc3', ...]:
   fc_dict[fc_name] = {'src_path': os.path.join(source_path, fc_name}, 'dst_path': os.path.join(dest_path, 'REF.SDE.' + fc_name)}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 03:09:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copying-gdb-features-to-existing-sde-features/m-p/1201736#M65281</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-08-11T03:09:27Z</dc:date>
    </item>
    <item>
      <title>Re: Copying GDB Features to existing SDE Features</title>
      <link>https://community.esri.com/t5/python-questions/copying-gdb-features-to-existing-sde-features/m-p/1202025#M65288</link>
      <description>&lt;P&gt;You can zip your lists to get around that error:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;source = ['x', 'y', 'z']
target = ['a', 'b', 'c']

for a, b in zip(source, target):
    print a
    print b&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 17:03:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copying-gdb-features-to-existing-sde-features/m-p/1202025#M65288</guid>
      <dc:creator>forestknutsen1</dc:creator>
      <dc:date>2022-08-11T17:03:39Z</dc:date>
    </item>
    <item>
      <title>Re: Copying GDB Features to existing SDE Features</title>
      <link>https://community.esri.com/t5/python-questions/copying-gdb-features-to-existing-sde-features/m-p/1202058#M65289</link>
      <description>&lt;P&gt;My favorite pattern for this sort of stuff is to use a cvs file with named tuples. That way you can mange the paths in Excel. And you can get access to the "csv fields" with a dot operator within your python code.&lt;/P&gt;&lt;P&gt;python&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from collections import namedtuple
import csv

with open('features.csv') as features:
    reader = csv.DictReader(features)
    Data = namedtuple('Data', reader.fieldnames)
    feature_paths = [Data(**x) for x in reader]
for feature_path in feature_paths:
    print feature_path.source
    print feature_path.target&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;csv file&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;source,target
source_path_1,target_path_1
source_path_2,target_path_2
source_path_3,target_path_3&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Aug 2022 21:14:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copying-gdb-features-to-existing-sde-features/m-p/1202058#M65289</guid>
      <dc:creator>forestknutsen1</dc:creator>
      <dc:date>2022-08-11T21:14:25Z</dc:date>
    </item>
  </channel>
</rss>

