<?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 Python API: How to update feature layer attributes from a second feature layer using common ID? in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-api-how-to-update-feature-layer-attributes/m-p/867767#M4503</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have what I hope is a simple question. I simply need to use the Python API to update attribute values in a feature layer based on values in another feature layer, using a common ID. Here's the scenario:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I have a feature layer of work orders&lt;/LI&gt;&lt;LI&gt;I have another feature layer with approvals for those work orders&lt;/LI&gt;&lt;LI&gt;Both layers have a common work order ID&lt;/LI&gt;&lt;LI&gt;I need a script to check the approvals layer and write "Approved" in a relevant field of the work orders layer for any matching records&lt;/LI&gt;&lt;LI&gt;I need to avoid ArcPy (because the script will run on PythonAnywhere so there's no way to set up the licensing necessary for ArcPy).&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance, your help is much appreciated!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 07 Sep 2019 17:08:53 GMT</pubDate>
    <dc:creator>JosephRhodes3</dc:creator>
    <dc:date>2019-09-07T17:08:53Z</dc:date>
    <item>
      <title>Python API: How to update feature layer attributes from a second feature layer using common ID?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-api-how-to-update-feature-layer-attributes/m-p/867767#M4503</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have what I hope is a simple question. I simply need to use the Python API to update attribute values in a feature layer based on values in another feature layer, using a common ID. Here's the scenario:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;I have a feature layer of work orders&lt;/LI&gt;&lt;LI&gt;I have another feature layer with approvals for those work orders&lt;/LI&gt;&lt;LI&gt;Both layers have a common work order ID&lt;/LI&gt;&lt;LI&gt;I need a script to check the approvals layer and write "Approved" in a relevant field of the work orders layer for any matching records&lt;/LI&gt;&lt;LI&gt;I need to avoid ArcPy (because the script will run on PythonAnywhere so there's no way to set up the licensing necessary for ArcPy).&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance, your help is much appreciated!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 07 Sep 2019 17:08:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-api-how-to-update-feature-layer-attributes/m-p/867767#M4503</guid>
      <dc:creator>JosephRhodes3</dc:creator>
      <dc:date>2019-09-07T17:08:53Z</dc:date>
    </item>
    <item>
      <title>Re: Python API: How to update feature layer attributes from a second feature layer using common ID?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-api-how-to-update-feature-layer-attributes/m-p/867768#M4504</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I figured it out and thought I'd post my code here in case it helps anyone (and in case someone wants to pick it apart - suggestions for improvement are welcome!).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from arcgis.gis import GIS&lt;BR /&gt;import pandas as pd&lt;BR /&gt;from arcgis.features import SpatialDataFrame&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;gis = GIS(&amp;lt;portal_url&amp;gt;, &amp;lt;username&amp;gt;, &amp;lt;password&amp;gt;")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;workOrderMaster = GIS().content.get(&amp;lt;itemID&amp;gt;)&lt;BR /&gt;workOrderFlayer = workOrderMaster.layers[0]&lt;BR /&gt;workOrderSdf = SpatialDataFrame.from_layer(workOrderFlayer)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;approvals = GIS().content.get(&amp;lt;itemID&amp;gt;)&lt;BR /&gt;approvalFlayer = approvals.layers[0]&lt;BR /&gt;approvalsSdf = SpatialDataFrame.from_layer(approvalFlayer)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;df=approvalsSdf.sort_values('CreationDate', ascending=True)&lt;BR /&gt;df=df.drop_duplicates(subset="workOrderId")&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;workOrder_fset = workOrderFlayer.query()&lt;BR /&gt;approval_fset = approvalFlayer.query()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;overlap_rows = pd.merge(left = workOrderSdf, right = df, how='inner', on = 'workOrderId')&lt;BR /&gt;all_features = workOrder_fset.features&lt;BR /&gt;approval_updates = approval_fset.features&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for workOrderId in overlap_rows['workOrderId']:&lt;BR /&gt; original_feature = [f for f in all_features if f.attributes['workOrderId'] == workOrderId][0]&lt;BR /&gt; update_feature = [f for f in approval_updates if f.attributes['workOrderId'] == workOrderId][0]&lt;BR /&gt; workOrder_edit = original_feature&lt;BR /&gt; approval_edit = update_feature&lt;BR /&gt; &lt;BR /&gt; workOrder_edit.attributes['apprName'] = approval_edit.attributes['approved_by']&lt;BR /&gt; workOrder_edit.attributes['isAppr'] = approval_edit.attributes['approvedecline']&lt;BR /&gt; workOrder_edit.attributes['apprDate'] = approval_edit.attributes['approved_on']&lt;BR /&gt; workOrder_edit.attributes['apprNote'] = approval_edit.attributes['approvalNotes']&lt;BR /&gt; update_result = workOrderFlayer.edit_features(updates=[workOrder_edit])&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 08 Sep 2019 17:57:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-api-how-to-update-feature-layer-attributes/m-p/867768#M4504</guid>
      <dc:creator>JosephRhodes3</dc:creator>
      <dc:date>2019-09-08T17:57:06Z</dc:date>
    </item>
    <item>
      <title>Re: Python API: How to update feature layer attributes from a second feature layer using common ID?</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/python-api-how-to-update-feature-layer-attributes/m-p/1043564#M5880</link>
      <description>&lt;P&gt;Hi Joseph,&lt;/P&gt;&lt;P&gt;what happened if you'd like to update your attributes based on the geometry changes, more concretely polygons? what I mean if you have change in some records and the change is done with the geometry, how do you do it?&lt;/P&gt;&lt;P&gt;Ashraf,&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 07:48:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/python-api-how-to-update-feature-layer-attributes/m-p/1043564#M5880</guid>
      <dc:creator>afana1972</dc:creator>
      <dc:date>2021-04-03T07:48:10Z</dc:date>
    </item>
  </channel>
</rss>

