<?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: Undocumented mergeRule in FieldMapping in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/undocumented-mergerule-in-fieldmapping/m-p/1316477#M26947</link>
    <description>&lt;P&gt;Awesome find!&amp;nbsp; If you're not comfortable using the undocumented merge rule in your production code, maybe you could use a Join merge rule into a text field, then follow up your spatial join with a calculate field or update cursor to parse out the number of unique values in each string (split it into a list on the join delimiter, then convert the list to a set and find the set's length).&lt;/P&gt;</description>
    <pubDate>Tue, 08 Aug 2023 15:43:16 GMT</pubDate>
    <dc:creator>SamSzotkowski</dc:creator>
    <dc:date>2023-08-08T15:43:16Z</dc:date>
    <item>
      <title>Undocumented mergeRule in FieldMapping</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/undocumented-mergerule-in-fieldmapping/m-p/1303650#M26924</link>
      <description>&lt;P&gt;I've made an interesting finding with SpatialJoin_analysis's field mapping. It appears that there are some undocumented merge rules that produce correct output.&lt;/P&gt;&lt;P&gt;My scenario is as follows. I have one layer that contains points with several fields. The second layer contains a grid that I would like to aggregate the points from the first layer into. To accomplish this I am calling the SpatialJoin_analysis operation:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.SpatialJoin_analysis(
    layer_grid,
    curr_layer,
    new_layer_path,
    join_operation="JOIN_ONE_TO_ONE",
    join_type="KEEP_COMMON",
    match_option="INTERSECT",
    field_mapping=get_field_mapping(curr_layer))&lt;/LI-CODE&gt;&lt;P&gt;where the output of the get_field_mapping(curr_layer) method returns a valid field mapping.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def get_field_mapping(layer):
    """Creates a mapping between selected fields from the origin GDB to the
    output GDB. The output fields will aggregate multiple entries either by
    a sum or count operation.

    """
    fm_value_16 = arcpy.FieldMap()
    fm_vreg = arcpy.FieldMap()
    intsct_mapping = arcpy.FieldMappings()

    fm_value_16.addInputField(layer, "PRICE_2016_ADJUSTED")
    fm_value_16.mergeRule = "Sum"
    fm_out_val_16 = arcpy.Field()
    fm_out_val_16.name = "Value_2016_Sum"
    fm_out_val_16.type = "Double"
    fm_value_16.outputField = fm_out_val_16

    fm_vreg.addInputField(layer, "V_REG_NUMBER")
    fm_vreg.mergeRule = "Unique"
    fm_out_vreg = arcpy.Field()
    fm_out_vreg.name = "VRN_Unique_Count"
    fm_out_vreg.type = "Integer"
    fm_vreg.outputField = fm_out_vreg

    intsct_mapping.addFieldMap(fm_value_16)
    intsct_mapping.addFieldMap(fm_vreg)

    return intsct_mapping&lt;/LI-CODE&gt;&lt;P&gt;Each point in the first layer has two fields, PRICE_2016_ADJUSTED and V_REG_NUMBER, that I want merged. For PRICE_2016_ADJUSTED I want its values to be summed, while for V_REG_NUMBER I want to calculate the number of unique values. Essentially, I want functionality similar to the Sum and Unique rules from (&lt;A href="https://pro.arcgis.com/en/pro-app/2.9/tool-reference/analysis/summary-statistics.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/2.9/tool-reference/analysis/summary-statistics.htm&lt;/A&gt;). However, according to the documentation for fieldMap (&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/fieldmap.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/latest/arcpy/classes/fieldmap.htm&lt;/A&gt;) I'm restricted to only using "Sum" as a valid mergeRule.&lt;/P&gt;&lt;P&gt;Yet, this line (&lt;FONT face="courier new,courier"&gt;fm_vreg.mergeRule = "Unique"&lt;/FONT&gt;) &lt;EM&gt;does&amp;nbsp;&lt;/EM&gt;in fact produce the number of unique entries in the aggregated point! Is this behaviour intentional and if so, can this be used in production code?&lt;/P&gt;</description>
      <pubDate>Tue, 27 Jun 2023 22:00:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/undocumented-mergerule-in-fieldmapping/m-p/1303650#M26924</guid>
      <dc:creator>Variable80</dc:creator>
      <dc:date>2023-06-27T22:00:26Z</dc:date>
    </item>
    <item>
      <title>Re: Undocumented mergeRule in FieldMapping</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/undocumented-mergerule-in-fieldmapping/m-p/1316477#M26947</link>
      <description>&lt;P&gt;Awesome find!&amp;nbsp; If you're not comfortable using the undocumented merge rule in your production code, maybe you could use a Join merge rule into a text field, then follow up your spatial join with a calculate field or update cursor to parse out the number of unique values in each string (split it into a list on the join delimiter, then convert the list to a set and find the set's length).&lt;/P&gt;</description>
      <pubDate>Tue, 08 Aug 2023 15:43:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/undocumented-mergerule-in-fieldmapping/m-p/1316477#M26947</guid>
      <dc:creator>SamSzotkowski</dc:creator>
      <dc:date>2023-08-08T15:43:16Z</dc:date>
    </item>
  </channel>
</rss>

