<?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: Join csv to multiple feature classes in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/join-csv-to-multiple-feature-classes/m-p/1009344#M59266</link>
    <description>&lt;P&gt;Thanks &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215600"&gt;@DanPatterson&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/167692"&gt;@DavidPike&lt;/a&gt;&amp;nbsp;. Yes, sorry that was due to a paste error.&lt;/P&gt;&lt;P&gt;Join field only work for the first feature class in the gdb. It wont join the other FCs.&lt;/P&gt;&lt;P&gt;Once I figure out how to join a single csv to all the feature classes within my geodatabase I can just&amp;nbsp; calculate over the fields I need.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 14 Dec 2020 16:58:09 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2020-12-14T16:58:09Z</dc:date>
    <item>
      <title>Join csv to multiple feature classes</title>
      <link>https://community.esri.com/t5/python-questions/join-csv-to-multiple-feature-classes/m-p/1009300#M59262</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I have a csv as follow;&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;NAME&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Category&amp;nbsp; &amp;nbsp; &amp;nbsp;Model&lt;/P&gt;&lt;P&gt;H1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Bridge&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;BG&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AB1&lt;/P&gt;&lt;P&gt;H2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Tunnel&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;TL&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AB2 etc etc&lt;/P&gt;&lt;P&gt;I have a geodatabase with multiple feature classes:&lt;/P&gt;&lt;P&gt;Working.gdb&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;(within each FC there is a FILENAME field with the Model number)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FcOne (FILENAME: AB1, ID: Empty, NAME: Empty, Category: Empty)&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;FcTwo etc etc&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to join the csv to all the FCs and field calculate the empty fields in the gdb with those in the csv.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using Blakes code&amp;nbsp; :&lt;/P&gt;&lt;PRE&gt;#Join CSV and populate fields&lt;BR /&gt;csv_values = {&lt;BR /&gt;    row[3]: {"ID": row[0], "NAME": row[1], "Category": row[2]}&lt;BR /&gt;    for row in arcpy.da.SearchCursor(Add_CSV, ["ID", "NAME", "Category", "Model"])&lt;BR /&gt;}&lt;BR /&gt;for fc in fcList:&lt;BR /&gt;    with arcpy.da.UpdateCursor(fc, ["FILENAME", "ID", "NAME", "CATEGORY"]) as u_cursor:&lt;BR /&gt;        for filename, id, name, category in u_cursor:&lt;BR /&gt;            csv_record = Add_CSV.get(filename)&lt;BR /&gt;            assert csv_record, "No value found for {} filename {} in CSV".format(fc, filename)&lt;BR /&gt;            id = csv_record["ID"]&lt;BR /&gt;            name = csv_record["NAME"]&lt;BR /&gt;            category = csv_record["Category"]&lt;BR /&gt;            u_cursor.updateRow([filename, id, name, category])&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get the following error:&lt;/P&gt;&lt;P&gt;csv_record = Add_CSV.getValue(filename)&lt;BR /&gt;AttributeError: 'str' object has no attribute 'getValue'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not sure how to fix this. Can you assist?&lt;/P&gt;</description>
      <pubDate>Tue, 15 Dec 2020 15:16:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/join-csv-to-multiple-feature-classes/m-p/1009300#M59262</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2020-12-15T15:16:40Z</dc:date>
    </item>
    <item>
      <title>Re: Join csv to multiple feature classes</title>
      <link>https://community.esri.com/t5/python-questions/join-csv-to-multiple-feature-classes/m-p/1009307#M59263</link>
      <description>&lt;P&gt;&lt;A href="https://community.esri.com/t5/python-blog/code-formatting-the-community-version/ba-p/1007633" target="_blank" rel="noopener"&gt;Code formatting ... the Community Version - GeoNet, The Esri Community&lt;/A&gt;&amp;nbsp;would help with format and indentation checking.&lt;/P&gt;&lt;P&gt;What did the code do? or have you even tested it?&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2020 15:53:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/join-csv-to-multiple-feature-classes/m-p/1009307#M59263</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2020-12-14T15:53:12Z</dc:date>
    </item>
    <item>
      <title>Re: Join csv to multiple feature classes</title>
      <link>https://community.esri.com/t5/python-questions/join-csv-to-multiple-feature-classes/m-p/1009311#M59264</link>
      <description>&lt;P&gt;I'm guessing there is indentation in the code, please use the formatting options to make it readable.&lt;/P&gt;&lt;P&gt;What does each FC look like after the join? The data model is confusing and not very well explained, i.e. why is BRIDGE a field in the FC and why are they separate FCs?&lt;/P&gt;&lt;P&gt;Unsure what you want to achieve with the cursor how it is, it's assigning each field value to itself for each row.&amp;nbsp; If you want to do field value reassignment, import all the fields you need in the [&lt;SPAN&gt;HS2FieldCalculator] and reassign them by index.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2020 15:58:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/join-csv-to-multiple-feature-classes/m-p/1009311#M59264</guid>
      <dc:creator>DavidPike</dc:creator>
      <dc:date>2020-12-14T15:58:03Z</dc:date>
    </item>
    <item>
      <title>Re: Join csv to multiple feature classes</title>
      <link>https://community.esri.com/t5/python-questions/join-csv-to-multiple-feature-classes/m-p/1009344#M59266</link>
      <description>&lt;P&gt;Thanks &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215600"&gt;@DanPatterson&lt;/a&gt;&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/167692"&gt;@DavidPike&lt;/a&gt;&amp;nbsp;. Yes, sorry that was due to a paste error.&lt;/P&gt;&lt;P&gt;Join field only work for the first feature class in the gdb. It wont join the other FCs.&lt;/P&gt;&lt;P&gt;Once I figure out how to join a single csv to all the feature classes within my geodatabase I can just&amp;nbsp; calculate over the fields I need.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2020 16:58:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/join-csv-to-multiple-feature-classes/m-p/1009344#M59266</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2020-12-14T16:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: Join csv to multiple feature classes</title>
      <link>https://community.esri.com/t5/python-questions/join-csv-to-multiple-feature-classes/m-p/1009373#M59267</link>
      <description>&lt;P&gt;I've come to prefer simply reading the contents of the join table (your CSV) into a dictionary and then looping through each feature class and looking up the field values to calculate. For example, if Model field is your key field, read the data into a dictionary like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;csv_values = {
    row[3]: {"ID": row[0], "NAME": row[1], "Category": row[2]}
    for row in arcpy.da.SearchCursor(csv, ["ID", "NAME", "Category", "Model"])
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So each key is a unique Model (assuming there are no duplicates here) and the value is another dictionary with the other fields. This would let you look up the values like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for fc in fcList:
    with arcpy.da.UpdateCursor(fc, ["FILENAME", "ID", "NAME", "Category"]) as u_cursor:
        for filename, id, name, category in u_cursor:
            csv_record = csv_data.get(filename)
            assert csv_record, "No value found for {} filename {} in CSV".format(fc, filename)
            id = csv_record["ID"]
            name = csv_record["NAME"]
            category = csv_record["Category"]
            u_cursor.updateRow([filename, id, name, category])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;If you have millions of records, this might hog memory.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Dec 2020 18:11:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/join-csv-to-multiple-feature-classes/m-p/1009373#M59267</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2020-12-14T18:11:06Z</dc:date>
    </item>
    <item>
      <title>Re: Join csv to multiple feature classes</title>
      <link>https://community.esri.com/t5/python-questions/join-csv-to-multiple-feature-classes/m-p/1009675#M59275</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt;&amp;nbsp;I worked around an error i was getting&amp;nbsp;&lt;SPAN class="comment-copy"&gt;. The next error is as follow: &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="comment-copy"&gt;AssertionError: No value found for _1XC07_CED_EE_EFB_ES04_CGG0_000038 filename 1XC07-CED-EE-EFB-ES04-CGG0-000038 in CSV &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="comment-copy"&gt;_1XC07_CED_EE_EFB_ES04_CGG0_000038 is the name of one of the feature classes in my geodatabase. Its seems as though it is trying to match the "model" in CSV to the title of feature and not the "FILENAME" field within the feature class.&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/SPAN&gt;Any help would be appreciated.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Dec 2020 09:25:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/join-csv-to-multiple-feature-classes/m-p/1009675#M59275</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2020-12-16T09:25:52Z</dc:date>
    </item>
  </channel>
</rss>

