<?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: Output field name not showing up in spatial join result in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/output-field-name-not-showing-up-in-spatial-join/m-p/282053#M21760</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Heres another example of what I'm talking about.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to convert a shapefile to a feature class, I also have a geojson file with the field names as I would like them to appear in the output feature class. The `arcpy.FeatureClassToFeatureClass_conversion` functionality accepts a field map, so I tried to build one by looping through a geopandas geodataframe of the geojson file (to set my output field names) and by adding the shapefile to a fieldMappings object, and replacing the field map for each iteration:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; import arcpy&lt;BR /&gt;&amp;nbsp; &amp;nbsp; import geopandas&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; file_path = 'damage_results/Culverts/Culverts.shp'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; original_fields = arcpy.ListFields(file_path)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; original_fields = original_fields[2:]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; gdf = geopandas.read_file('damage_results/Culverts/result_culverts.json')&lt;BR /&gt;&amp;nbsp; &amp;nbsp; new_field_names = gdf.columns[:-1].to_list()&lt;BR /&gt; &lt;BR /&gt;&amp;nbsp; &amp;nbsp; fms = arcpy.FieldMappings()&lt;BR /&gt;&amp;nbsp; &amp;nbsp; fms.addTable(file_path)&lt;BR /&gt; &lt;BR /&gt;&amp;nbsp; &amp;nbsp; for i,field in enumerate(original_fields):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print i&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fm = fms.getFieldMap(i)&lt;BR /&gt; &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; out_field = fm.outputField&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; out_field.name = new_field_names&lt;I&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fm.outputField = out_field&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fms.replaceFieldMap(i, fm)&lt;BR /&gt; &lt;BR /&gt;&amp;nbsp; &amp;nbsp; for fm in fms:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print fm.outputField.name&lt;BR /&gt; arcpy.FeatureClassToFeatureClass_conversion(file_path, 'intermediate_damage.gdb',&lt;BR /&gt;'Culverts', field_mapping = fms)&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The second `for` loop is to verify that the output field names have been written properly, and it seems from within the script that they are. However when I open the Culverts feature class the field names are unchanged from the shapefile, which is rather infuriating.&lt;/P&gt;&lt;P&gt;Does the output field attribute in the `FieldMap` object actually work? Or is this a bug that ESRI needs to fix?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 15 May 2019 03:40:51 GMT</pubDate>
    <dc:creator>TheWorm</dc:creator>
    <dc:date>2019-05-15T03:40:51Z</dc:date>
    <item>
      <title>Output field name not showing up in spatial join result</title>
      <link>https://community.esri.com/t5/python-questions/output-field-name-not-showing-up-in-spatial-join/m-p/282052#M21759</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to use the `FieldMap` and the `FieldMappings` classes in `arcpy` in the context of a spatial join. I have two line layers as feature classes. These are `Roads` and `Culverts`. Roads has a copy of the `OBJECTID` field called `ID`. I am spatially joining `Roads` to `Culverts`, but I would like to control the name of the joined `ID` field from the road layer. Here's some python code I am using:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;fm = arcpy.FieldMap()&lt;/P&gt;&lt;P&gt;fms = arcpy.FieldMappings()&lt;/P&gt;&lt;P&gt;fm.addInputField('Road', 'ID')&lt;/P&gt;&lt;P&gt;out_field = fm.outputField&lt;/P&gt;&lt;P&gt;out_field.name = 'ROID'&lt;/P&gt;&lt;P&gt;fm.outputField = out_field&lt;/P&gt;&lt;P&gt;fms.addFieldMap(fm)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;arcpy.SpatialJoin_analysis(target_features="test.gdb/Culvert", join_features="test.gdb/Road", out_feature_class="test.gdb/join", join_operation="JOIN_ONE_TO_ONE", join_type="KEEP_ALL", field_mapping =fms, match_option="CLOSEST", search_radius="", distance_field_name="")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Unfortunately I get a result where the field is called `ID` (just like in the original road layer) and the values are all 0 in this field (which is incorrect). I have a couple of questions: - how do I control the name of the output field using the `FieldMap` and `FieldMappings` classes? - Why are the attributes all 0 and how can I fix that? - Can I use the `OBJECTID` of the road layer directly without having to make a copy called `ID`, and using the `FieldMap` and `FieldMappings` classes THanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 May 2019 02:51:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/output-field-name-not-showing-up-in-spatial-join/m-p/282052#M21759</guid>
      <dc:creator>TheWorm</dc:creator>
      <dc:date>2019-05-14T02:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Output field name not showing up in spatial join result</title>
      <link>https://community.esri.com/t5/python-questions/output-field-name-not-showing-up-in-spatial-join/m-p/282053#M21760</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Heres another example of what I'm talking about.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am trying to convert a shapefile to a feature class, I also have a geojson file with the field names as I would like them to appear in the output feature class. The `arcpy.FeatureClassToFeatureClass_conversion` functionality accepts a field map, so I tried to build one by looping through a geopandas geodataframe of the geojson file (to set my output field names) and by adding the shapefile to a fieldMappings object, and replacing the field map for each iteration:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; import arcpy&lt;BR /&gt;&amp;nbsp; &amp;nbsp; import geopandas&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; file_path = 'damage_results/Culverts/Culverts.shp'&lt;BR /&gt;&amp;nbsp; &amp;nbsp; original_fields = arcpy.ListFields(file_path)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; original_fields = original_fields[2:]&lt;BR /&gt;&amp;nbsp; &amp;nbsp; gdf = geopandas.read_file('damage_results/Culverts/result_culverts.json')&lt;BR /&gt;&amp;nbsp; &amp;nbsp; new_field_names = gdf.columns[:-1].to_list()&lt;BR /&gt; &lt;BR /&gt;&amp;nbsp; &amp;nbsp; fms = arcpy.FieldMappings()&lt;BR /&gt;&amp;nbsp; &amp;nbsp; fms.addTable(file_path)&lt;BR /&gt; &lt;BR /&gt;&amp;nbsp; &amp;nbsp; for i,field in enumerate(original_fields):&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print i&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fm = fms.getFieldMap(i)&lt;BR /&gt; &lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; out_field = fm.outputField&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; out_field.name = new_field_names&lt;I&gt;&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fm.outputField = out_field&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fms.replaceFieldMap(i, fm)&lt;BR /&gt; &lt;BR /&gt;&amp;nbsp; &amp;nbsp; for fm in fms:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; print fm.outputField.name&lt;BR /&gt; arcpy.FeatureClassToFeatureClass_conversion(file_path, 'intermediate_damage.gdb',&lt;BR /&gt;'Culverts', field_mapping = fms)&lt;/I&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The second `for` loop is to verify that the output field names have been written properly, and it seems from within the script that they are. However when I open the Culverts feature class the field names are unchanged from the shapefile, which is rather infuriating.&lt;/P&gt;&lt;P&gt;Does the output field attribute in the `FieldMap` object actually work? Or is this a bug that ESRI needs to fix?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 15 May 2019 03:40:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/output-field-name-not-showing-up-in-spatial-join/m-p/282053#M21760</guid>
      <dc:creator>TheWorm</dc:creator>
      <dc:date>2019-05-15T03:40:51Z</dc:date>
    </item>
  </channel>
</rss>

