<?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: Automating a Field Calculation Using 2 Datasets in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/automating-a-field-calculation-using-2-datasets/m-p/1155186#M52985</link>
    <description>&lt;P&gt;Are you married to doing it with ModelBuilder? Because that seems like an easy job for Python (untested):&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os

parcels = [
    "path:/to/Parcel_Dataset_1",
    "path:/to/Parcel_Dataset_2",
    "path:/to/Parcel_Dataset_3",
    ]
apn = "path:/to/APN_Dataset"


# read the parcel data
parcel_data = dict()
for parcel in parcels:
    parcel_name = os.path.basename(parcel)
    join_field_values = [row[0] for row in arcpy.da.SearchCursor(parcel, ["JoinField"])]
    parcel_data[parcel_name] = join_field_values

# parcel_data looks like this:
#parcel_data = {
#    "Parcel_Dataset_1": [1, 2, 3, 4, 5, 6],
#    "Parcel_Dataset_2": [7, 8, 9],
#    "Parcel_Dataset_3": [1, 2, 5, 8, 10, 11],
#    }

# open an UpdateCursor on APN, filter only features where TargetField is empty
with arcpy.da.UpdateCursor(apn, ["JoinField", "TargetField"], "TargetField IS NULL") as cursor:
    # loop throguh the APN features
    for join_value, parcel_name in cursor:
        # loop through the parcel datasets
        for p in parcel_data:
            if join_value in parcel_data[p]:
                # there is a match in this parcel dataset
                parcel_name = p
                # stop looping through the rest of the parcel datasets
                break
        # write the parcel dataset name to the APN dataset
        # note: if no match was found in all of the parcel datasets, parcel_name
        # will be null
        cursor.updateRow([join_value, parcel_name])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then the problem would be simply how to sort your parcel datasets. You can input them in the correct order manually, but if they have a date or version number or something similar in their name, you can also do it automatically&lt;/P&gt;</description>
    <pubDate>Fri, 18 Mar 2022 12:02:53 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2022-03-18T12:02:53Z</dc:date>
    <item>
      <title>Automating a Field Calculation Using 2 Datasets</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/automating-a-field-calculation-using-2-datasets/m-p/1155133#M52978</link>
      <description>&lt;P&gt;I'm trying to populate a field based on the output of a "Field Join" between two datasets. Specifically:&lt;/P&gt;&lt;P&gt;IF an item in &lt;STRONG&gt;APN_Dataset&lt;/STRONG&gt; "matches" (based on Field Join tool) an item in &lt;EM&gt;&lt;STRONG&gt;Parcel_Datset&lt;/STRONG&gt;&lt;/EM&gt;, THEN "JoinParcelDataset" field cell = name of &lt;EM&gt;&lt;STRONG&gt;Parcel_Dataset&lt;/STRONG&gt;&lt;/EM&gt; (there are 71 of these datasets that I also want to iterate through with "iterate dataset" in modelbuilder)&amp;nbsp;&lt;/P&gt;&lt;P&gt;My problem follows as such:&lt;/P&gt;&lt;P&gt;1. Moving the 71 datasets to a workspace in chronological order for sequential iteration (newest to oldest)&lt;/P&gt;&lt;P&gt;2. I do not know where to enter the SQL expression (calculate field/calculate value tool? inside of modelbuilder)&lt;/P&gt;&lt;P&gt;3. I only want the name of Parcel_Dataset to be assigned to the matching cell if the cell is &amp;lt;null&amp;gt;&lt;/P&gt;&lt;P&gt;This would be some kind of nested loop, inside one of the tools in model builder with an interator for the 71 datasets I would like to compare against a single table. Thanks for your help!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 18 Mar 2022 05:25:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/automating-a-field-calculation-using-2-datasets/m-p/1155133#M52978</guid>
      <dc:creator>BK710</dc:creator>
      <dc:date>2022-03-18T05:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: Automating a Field Calculation Using 2 Datasets</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/automating-a-field-calculation-using-2-datasets/m-p/1155186#M52985</link>
      <description>&lt;P&gt;Are you married to doing it with ModelBuilder? Because that seems like an easy job for Python (untested):&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import os

parcels = [
    "path:/to/Parcel_Dataset_1",
    "path:/to/Parcel_Dataset_2",
    "path:/to/Parcel_Dataset_3",
    ]
apn = "path:/to/APN_Dataset"


# read the parcel data
parcel_data = dict()
for parcel in parcels:
    parcel_name = os.path.basename(parcel)
    join_field_values = [row[0] for row in arcpy.da.SearchCursor(parcel, ["JoinField"])]
    parcel_data[parcel_name] = join_field_values

# parcel_data looks like this:
#parcel_data = {
#    "Parcel_Dataset_1": [1, 2, 3, 4, 5, 6],
#    "Parcel_Dataset_2": [7, 8, 9],
#    "Parcel_Dataset_3": [1, 2, 5, 8, 10, 11],
#    }

# open an UpdateCursor on APN, filter only features where TargetField is empty
with arcpy.da.UpdateCursor(apn, ["JoinField", "TargetField"], "TargetField IS NULL") as cursor:
    # loop throguh the APN features
    for join_value, parcel_name in cursor:
        # loop through the parcel datasets
        for p in parcel_data:
            if join_value in parcel_data[p]:
                # there is a match in this parcel dataset
                parcel_name = p
                # stop looping through the rest of the parcel datasets
                break
        # write the parcel dataset name to the APN dataset
        # note: if no match was found in all of the parcel datasets, parcel_name
        # will be null
        cursor.updateRow([join_value, parcel_name])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then the problem would be simply how to sort your parcel datasets. You can input them in the correct order manually, but if they have a date or version number or something similar in their name, you can also do it automatically&lt;/P&gt;</description>
      <pubDate>Fri, 18 Mar 2022 12:02:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/automating-a-field-calculation-using-2-datasets/m-p/1155186#M52985</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-03-18T12:02:53Z</dc:date>
    </item>
  </channel>
</rss>

