<?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 Pull corresponding field values based on one conditional merge rule in field mapping in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/pull-corresponding-field-values-based-on-one/m-p/1168159#M54448</link>
    <description>&lt;P&gt;I'm using the field mapping object in ArcGIS Pro to try set up a spatial join with specific field values in the output. Apologies as I am very new to programming in general, so this may be rudimentary / code is not polished.&lt;/P&gt;&lt;P&gt;I have two shapefiles:&lt;/P&gt;&lt;P&gt;1) Line water pipe data with attributes (pipes)&lt;/P&gt;&lt;P&gt;2) Polygon areas of interest (currentAOI)&lt;/P&gt;&lt;P&gt;Since there are multiple pipe segments (with differing attribute info) for each larger area of interest, I need to specify a merge rule so that only the information for the longest pipe segment within the AOI is maintained. I realize that I can set merge rules for each field, but I want the other resulting fields to be dependent on the merge rule for only one of the fields.&lt;/P&gt;&lt;P&gt;I set a rule for the length field, but the "first" merge rule is automatically applied to each of the other individual fields. Instead, I need whatever field values associated with the longest length value to be retained. See the "one to many" photo example where you can see all the other values, and the resulting "one to one" join where it mixes and matches the resulting field values.&lt;/P&gt;&lt;P&gt;Here is the field mapping code:&lt;/P&gt;&lt;P&gt;fieldMappings = arcpy.FieldMappings()&lt;BR /&gt;fm_id = arcpy.FieldMap()&lt;BR /&gt;fm_length = arcpy.FieldMap()&lt;BR /&gt;fm_material = arcpy.FieldMap()&lt;BR /&gt;fm_diameter = arcpy.FieldMap()&lt;BR /&gt;fm_year = arcpy.FieldMap()&lt;BR /&gt;&lt;BR /&gt;# create fields&lt;BR /&gt;ID = "ID"&lt;BR /&gt;length = "Length_mi"&lt;BR /&gt;material = "Material"&lt;BR /&gt;diameter = "Diameter"&lt;BR /&gt;year = "Year_"&lt;BR /&gt;&lt;BR /&gt;fm_id.addInputField(currentAOI, ID)&lt;/P&gt;&lt;P&gt;fm_length.addInputField(pipes, length)&lt;BR /&gt;fm_material.addInputField(pipes, material)&lt;BR /&gt;fm_diameter.addInputField(pipes, diameter)&lt;BR /&gt;fm_year.addInputField(pipes, year)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;# Set the output field properties for FieldMap objects&lt;BR /&gt;id_name = fm_id.outputField&lt;BR /&gt;id_name.name = 'ID'&lt;BR /&gt;fm_id.outputField = id_name&lt;/P&gt;&lt;P&gt;len_name = fm_length.outputField&lt;BR /&gt;len_name.name = 'Length_mi'&lt;BR /&gt;fm_length.outputField = len_name&lt;/P&gt;&lt;P&gt;mat_name = fm_material.outputField&lt;BR /&gt;mat_name.name = 'Material'&lt;BR /&gt;fm_material.outputField = mat_name&lt;/P&gt;&lt;P&gt;diam_name = fm_diameter.outputField&lt;BR /&gt;diam_name.name = 'Diameter'&lt;BR /&gt;fm_diameter.outputField = diam_name&lt;/P&gt;&lt;P&gt;year_name = fm_year.outputField&lt;BR /&gt;year_name.name = 'Year_'&lt;BR /&gt;fm_year.outputField = year_name&lt;/P&gt;&lt;P&gt;fieldMappings.addFieldMap(fm_id)&lt;BR /&gt;fieldMappings.addFieldMap(fm_length)&lt;BR /&gt;fieldMappings.addFieldMap(fm_material)&lt;BR /&gt;fieldMappings.addFieldMap(fm_diameter)&lt;BR /&gt;fieldMappings.addFieldMap(fm_year)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;fm_length.mergeRule = "max"&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;####################################################################################&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;spJoinPipe = arcpy.analysis.SpatialJoin(currentAOI, pipes, str(outputPath) + "/currentAOI_Pipes_SpJoin_one.shp", field_mapping=fieldMappings)&lt;/P&gt;&lt;P&gt;dropFields2 = ["Join_Count", "TARGET_FID"]&amp;nbsp;&lt;BR /&gt;arcpy.management.DeleteField(spJoinPipe, dropFields2)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is greatly appreciated. Thank you.&lt;/P&gt;</description>
    <pubDate>Tue, 26 Apr 2022 22:33:53 GMT</pubDate>
    <dc:creator>shmae__</dc:creator>
    <dc:date>2022-04-26T22:33:53Z</dc:date>
    <item>
      <title>Pull corresponding field values based on one conditional merge rule in field mapping</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/pull-corresponding-field-values-based-on-one/m-p/1168159#M54448</link>
      <description>&lt;P&gt;I'm using the field mapping object in ArcGIS Pro to try set up a spatial join with specific field values in the output. Apologies as I am very new to programming in general, so this may be rudimentary / code is not polished.&lt;/P&gt;&lt;P&gt;I have two shapefiles:&lt;/P&gt;&lt;P&gt;1) Line water pipe data with attributes (pipes)&lt;/P&gt;&lt;P&gt;2) Polygon areas of interest (currentAOI)&lt;/P&gt;&lt;P&gt;Since there are multiple pipe segments (with differing attribute info) for each larger area of interest, I need to specify a merge rule so that only the information for the longest pipe segment within the AOI is maintained. I realize that I can set merge rules for each field, but I want the other resulting fields to be dependent on the merge rule for only one of the fields.&lt;/P&gt;&lt;P&gt;I set a rule for the length field, but the "first" merge rule is automatically applied to each of the other individual fields. Instead, I need whatever field values associated with the longest length value to be retained. See the "one to many" photo example where you can see all the other values, and the resulting "one to one" join where it mixes and matches the resulting field values.&lt;/P&gt;&lt;P&gt;Here is the field mapping code:&lt;/P&gt;&lt;P&gt;fieldMappings = arcpy.FieldMappings()&lt;BR /&gt;fm_id = arcpy.FieldMap()&lt;BR /&gt;fm_length = arcpy.FieldMap()&lt;BR /&gt;fm_material = arcpy.FieldMap()&lt;BR /&gt;fm_diameter = arcpy.FieldMap()&lt;BR /&gt;fm_year = arcpy.FieldMap()&lt;BR /&gt;&lt;BR /&gt;# create fields&lt;BR /&gt;ID = "ID"&lt;BR /&gt;length = "Length_mi"&lt;BR /&gt;material = "Material"&lt;BR /&gt;diameter = "Diameter"&lt;BR /&gt;year = "Year_"&lt;BR /&gt;&lt;BR /&gt;fm_id.addInputField(currentAOI, ID)&lt;/P&gt;&lt;P&gt;fm_length.addInputField(pipes, length)&lt;BR /&gt;fm_material.addInputField(pipes, material)&lt;BR /&gt;fm_diameter.addInputField(pipes, diameter)&lt;BR /&gt;fm_year.addInputField(pipes, year)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;# Set the output field properties for FieldMap objects&lt;BR /&gt;id_name = fm_id.outputField&lt;BR /&gt;id_name.name = 'ID'&lt;BR /&gt;fm_id.outputField = id_name&lt;/P&gt;&lt;P&gt;len_name = fm_length.outputField&lt;BR /&gt;len_name.name = 'Length_mi'&lt;BR /&gt;fm_length.outputField = len_name&lt;/P&gt;&lt;P&gt;mat_name = fm_material.outputField&lt;BR /&gt;mat_name.name = 'Material'&lt;BR /&gt;fm_material.outputField = mat_name&lt;/P&gt;&lt;P&gt;diam_name = fm_diameter.outputField&lt;BR /&gt;diam_name.name = 'Diameter'&lt;BR /&gt;fm_diameter.outputField = diam_name&lt;/P&gt;&lt;P&gt;year_name = fm_year.outputField&lt;BR /&gt;year_name.name = 'Year_'&lt;BR /&gt;fm_year.outputField = year_name&lt;/P&gt;&lt;P&gt;fieldMappings.addFieldMap(fm_id)&lt;BR /&gt;fieldMappings.addFieldMap(fm_length)&lt;BR /&gt;fieldMappings.addFieldMap(fm_material)&lt;BR /&gt;fieldMappings.addFieldMap(fm_diameter)&lt;BR /&gt;fieldMappings.addFieldMap(fm_year)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;fm_length.mergeRule = "max"&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;####################################################################################&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;spJoinPipe = arcpy.analysis.SpatialJoin(currentAOI, pipes, str(outputPath) + "/currentAOI_Pipes_SpJoin_one.shp", field_mapping=fieldMappings)&lt;/P&gt;&lt;P&gt;dropFields2 = ["Join_Count", "TARGET_FID"]&amp;nbsp;&lt;BR /&gt;arcpy.management.DeleteField(spJoinPipe, dropFields2)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help is greatly appreciated. Thank you.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Apr 2022 22:33:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/pull-corresponding-field-values-based-on-one/m-p/1168159#M54448</guid>
      <dc:creator>shmae__</dc:creator>
      <dc:date>2022-04-26T22:33:53Z</dc:date>
    </item>
  </channel>
</rss>

