<?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 copy features - works only for Points? in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/copy-features-works-only-for-points/m-p/8587#M696</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi All&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm writing a arcpy script to copy many feature classes from one workspace (file geo database) to another. It's important for me that the script works between existing feature classes, i.e. Not try to create new feature classes, but appends the copied features as new features to the existing feature classes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you know Batch-Copy-Paste, this is the same, only without messing up the PLTS_Compilation info.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Due to the above requirements it seemed out of the question to use either of:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CopyFeatures_management()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.FeatureClassToGeodatabase_conversion()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.FeatureClassToFeatureClass_conversion()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.Copy_management()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;even with the 'overwrite output' turned on, as they all aim at creating a new output feature class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I therefore decided to go row-by-row with a Search-cursor and an Insert-cursor.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The two .gdb already exist, and have identical structure (schema) but the output.gdb holds no features in the feature classes&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The script looks like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import os, arcpy
 
def inventory_data(workspace, datatypes):
&amp;nbsp;&amp;nbsp;&amp;nbsp; for path, path_names, data_names in arcpy.da.Walk(workspace, datatype=datatypes):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for data_name in data_names:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; yield os.path.join(path, data_name)

def match_feature_names(FA,lstFB):
&amp;nbsp;&amp;nbsp;&amp;nbsp; FAName = FA[FA.rfind("\\")+1:]
&amp;nbsp;&amp;nbsp;&amp;nbsp; for FB in lstFB:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if FAName in FB:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return FB
&amp;nbsp;&amp;nbsp;&amp;nbsp; return False

#Main
genWSA = inventory_data(r"C:\data\input.gdb", "FeatureClass")
lstWSA = list(genWSA)
genWSB = inventory_data(r"C:\data\output.gdb", "FeatureClass")
lstWSB = list(genWSB)

for FCA in lstWSA:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Copying:"+FCA
&amp;nbsp;&amp;nbsp;&amp;nbsp; lst_field_names = [fldX.name for fldX in arcpy.ListFields(FCA)]
&amp;nbsp;&amp;nbsp;&amp;nbsp; curWrite = arcpy.da.InsertCursor(match_feature_names(FCA,lstWSB),lst_field_names)
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(FCA,"*") as curRead:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in curRead:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; curWrite.insertRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp; del curRead,curWrite&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;For some reason it only works well for Point feature classes. Any Line or Polygon feature class have the attributes copied correctely, but the 'shape' is empty. Also the length- and area-field holds only 0 (zero) in all output rows&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Any suggestion are appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Martin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 18 Nov 2013 19:04:10 GMT</pubDate>
    <dc:creator>MartinHvidberg</dc:creator>
    <dc:date>2013-11-18T19:04:10Z</dc:date>
    <item>
      <title>copy features - works only for Points?</title>
      <link>https://community.esri.com/t5/python-questions/copy-features-works-only-for-points/m-p/8587#M696</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi All&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm writing a arcpy script to copy many feature classes from one workspace (file geo database) to another. It's important for me that the script works between existing feature classes, i.e. Not try to create new feature classes, but appends the copied features as new features to the existing feature classes.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you know Batch-Copy-Paste, this is the same, only without messing up the PLTS_Compilation info.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Due to the above requirements it seemed out of the question to use either of:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CopyFeatures_management()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.FeatureClassToGeodatabase_conversion()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.FeatureClassToFeatureClass_conversion()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.Copy_management()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;even with the 'overwrite output' turned on, as they all aim at creating a new output feature class.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I therefore decided to go row-by-row with a Search-cursor and an Insert-cursor.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The two .gdb already exist, and have identical structure (schema) but the output.gdb holds no features in the feature classes&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The script looks like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import os, arcpy
 
def inventory_data(workspace, datatypes):
&amp;nbsp;&amp;nbsp;&amp;nbsp; for path, path_names, data_names in arcpy.da.Walk(workspace, datatype=datatypes):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for data_name in data_names:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; yield os.path.join(path, data_name)

def match_feature_names(FA,lstFB):
&amp;nbsp;&amp;nbsp;&amp;nbsp; FAName = FA[FA.rfind("\\")+1:]
&amp;nbsp;&amp;nbsp;&amp;nbsp; for FB in lstFB:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if FAName in FB:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; return FB
&amp;nbsp;&amp;nbsp;&amp;nbsp; return False

#Main
genWSA = inventory_data(r"C:\data\input.gdb", "FeatureClass")
lstWSA = list(genWSA)
genWSB = inventory_data(r"C:\data\output.gdb", "FeatureClass")
lstWSB = list(genWSB)

for FCA in lstWSA:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Copying:"+FCA
&amp;nbsp;&amp;nbsp;&amp;nbsp; lst_field_names = [fldX.name for fldX in arcpy.ListFields(FCA)]
&amp;nbsp;&amp;nbsp;&amp;nbsp; curWrite = arcpy.da.InsertCursor(match_feature_names(FCA,lstWSB),lst_field_names)
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(FCA,"*") as curRead:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in curRead:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; curWrite.insertRow(row)
&amp;nbsp;&amp;nbsp;&amp;nbsp; del curRead,curWrite&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;For some reason it only works well for Point feature classes. Any Line or Polygon feature class have the attributes copied correctely, but the 'shape' is empty. Also the length- and area-field holds only 0 (zero) in all output rows&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Any suggestion are appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Best regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Martin&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Nov 2013 19:04:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copy-features-works-only-for-points/m-p/8587#M696</guid>
      <dc:creator>MartinHvidberg</dc:creator>
      <dc:date>2013-11-18T19:04:10Z</dc:date>
    </item>
    <item>
      <title>Re: copy features - works only for Points?</title>
      <link>https://community.esri.com/t5/python-questions/copy-features-works-only-for-points/m-p/8588#M697</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Is there a reason why you are not simply copying them from one filegeodatabase to the other in Catalog?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Nov 2013 19:06:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copy-features-works-only-for-points/m-p/8588#M697</guid>
      <dc:creator>RobertBorchert</dc:creator>
      <dc:date>2013-11-18T19:06:00Z</dc:date>
    </item>
    <item>
      <title>Re: copy features - works only for Points?</title>
      <link>https://community.esri.com/t5/python-questions/copy-features-works-only-for-points/m-p/8589#M698</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Is there a reason why you are not simply copying them from one filegeodatabase to the other in Catalog?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes - Two reasons.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1) Copying like that would not append features to an existing feature class, it would create a new feature classe with a '_1' name.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2) It would be time consuming. The data bases have 20-30 Feature classes, with potentially hundreds of subtypes (though they are not all populated). I need to do it often, so I would like it to be automatic.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have used the Batch-Copy-Paste tool. But the data base is multi-scale, and batch-copy-paste don't honour that, it puts the default Production Compilation Scale on all output features.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;/M&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Nov 2013 19:29:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/copy-features-works-only-for-points/m-p/8589#M698</guid>
      <dc:creator>MartinHvidberg</dc:creator>
      <dc:date>2013-11-18T19:29:47Z</dc:date>
    </item>
  </channel>
</rss>

