<?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: Field names differ in a memory feature class in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/field-names-differ-in-a-memory-feature-class/m-p/1552444#M73094</link>
    <description>&lt;P&gt;Try running the Append with the 'NO_TEST' option for the schema_type parameter.&lt;/P&gt;</description>
    <pubDate>Fri, 25 Oct 2024 16:57:38 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2024-10-25T16:57:38Z</dc:date>
    <item>
      <title>Field names differ in a memory feature class</title>
      <link>https://community.esri.com/t5/python-questions/field-names-differ-in-a-memory-feature-class/m-p/1552270#M73089</link>
      <description>&lt;P&gt;I am creating a script that makes a feature class using an existing on SDE, puts some data in it, and runs some processing on it, and then appends the data back to the original feature class using the append tool.&lt;/P&gt;&lt;P&gt;I create a tmp feature class in memory for this, which seems fine, but when I go to append back to the original feature class, the field names are different.&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, OBJECTID field on SDE is renamed objectid in memory, thus breaking the append (similar behavior for any st_* field).&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a solution to this? I'd rather not use insert and update cursor...&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2024 11:18:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-names-differ-in-a-memory-feature-class/m-p/1552270#M73089</guid>
      <dc:creator>tcrammond</dc:creator>
      <dc:date>2024-10-25T11:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Field names differ in a memory feature class</title>
      <link>https://community.esri.com/t5/python-questions/field-names-differ-in-a-memory-feature-class/m-p/1552399#M73092</link>
      <description>&lt;P&gt;What functions do you use to create the feature class and do the append? Some thoughts:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;&lt;STRONG&gt;to_featureclass&lt;/STRONG&gt; (and other functions) has a parameter &lt;STRONG&gt;sanitize_columns&lt;/STRONG&gt; that creates snake_case column names. You can set it to &lt;STRONG&gt;False&lt;/STRONG&gt; to allow your field names to stay in the format of the input data.&lt;/LI&gt;&lt;LI&gt;Sometimes the sanitize parameter is "baked in". But you can still explicitly rename the columns before the append. Tedious, but possible.&lt;/LI&gt;&lt;/OL&gt;&lt;LI-CODE lang="python"&gt;col_dict = {
  "oldname_1": "NEWNAME1",
  "oldname_2": "NEWNAME2"
}

temp_layer.rename(columns=col_dict, inplace=True)&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 25 Oct 2024 16:01:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-names-differ-in-a-memory-feature-class/m-p/1552399#M73092</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2024-10-25T16:01:02Z</dc:date>
    </item>
    <item>
      <title>Re: Field names differ in a memory feature class</title>
      <link>https://community.esri.com/t5/python-questions/field-names-differ-in-a-memory-feature-class/m-p/1552416#M73093</link>
      <description>&lt;P&gt;Something that might be easier is using an Insert Cursor to avoid stuff like that. &lt;A href="mailto:Shape@," target="_blank"&gt;Shape@,&lt;/A&gt;&amp;nbsp;OID@ are both very useful.&lt;/P&gt;&lt;P&gt;That being said, if you're appending stuff in, I don't think the OBJECTID matters? Or if it does, you should probably have it as a separate field that you manage.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The other question is: Why not just do everything in the original feature class, just using a version to do it? You have the enterprise gdb anyway; you may as well take advantage of it.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2024 16:29:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-names-differ-in-a-memory-feature-class/m-p/1552416#M73093</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-10-25T16:29:58Z</dc:date>
    </item>
    <item>
      <title>Re: Field names differ in a memory feature class</title>
      <link>https://community.esri.com/t5/python-questions/field-names-differ-in-a-memory-feature-class/m-p/1552444#M73094</link>
      <description>&lt;P&gt;Try running the Append with the 'NO_TEST' option for the schema_type parameter.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Oct 2024 16:57:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-names-differ-in-a-memory-feature-class/m-p/1552444#M73094</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-10-25T16:57:38Z</dc:date>
    </item>
    <item>
      <title>Re: Field names differ in a memory feature class</title>
      <link>https://community.esri.com/t5/python-questions/field-names-differ-in-a-memory-feature-class/m-p/1552802#M73098</link>
      <description>&lt;P&gt;Maybe use field mapping,&lt;/P&gt;&lt;LI-CODE lang="c"&gt;import arcpy

# Paths to your original feature class (SDE) and  in-memory feature class
sde_fc = "feature_class"
in_memory_fc = "in_memory/tmp_feature_class"

# Create FieldMappings object
field_mappings = arcpy.FieldMappings()

# Add fields from the in-memory feature class to the FieldMappings
for field in arcpy.ListFields(in_memory_fc):
    field_map = arcpy.FieldMap()
    field_map.addInputField(in_memory_fc, field.name)
    
    # If needed, set the output field name to match the SDE feature class field
    if field.name.lower() == "objectid":
        output_field = field_map.outputField
        output_field.name = "OBJECTID"
        field_map.outputField = output_field
    
    field_mappings.addFieldMap(field_map)

# Append with FieldMappings to ensure they are correct
arcpy.management.Append(in_memory_fc, sde_fc, "NO_TEST", field_mappings)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, you might try to disable qualified field names.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;# Disable qualified field names
arcpy.env.qualifiedFieldNames = False

# Perform  Append
arcpy.management.Append(in_memory_fc, sde_fc, "NO_TEST")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 28 Oct 2024 14:55:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-names-differ-in-a-memory-feature-class/m-p/1552802#M73098</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-10-28T14:55:33Z</dc:date>
    </item>
    <item>
      <title>Re: Field names differ in a memory feature class</title>
      <link>https://community.esri.com/t5/python-questions/field-names-differ-in-a-memory-feature-class/m-p/1561213#M73217</link>
      <description>&lt;P&gt;I think the issue is that this is essentially an UPSERT operation, where not all the old content is updated. So I want to keep un-updated old records, update some existing ones, and append new ones (if they exist).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm using insert/create cursors, but hoping to make this more efficient.&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2024 13:30:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/field-names-differ-in-a-memory-feature-class/m-p/1561213#M73217</guid>
      <dc:creator>tcrammond</dc:creator>
      <dc:date>2024-11-21T13:30:21Z</dc:date>
    </item>
  </channel>
</rss>

