<?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 Updating polygon features from a feature layer in arcgis API Python in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/updating-polygon-features-from-a-feature-layer-in/m-p/1043566#M39295</link>
    <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I'm trying to replicate the code published by ESRI in &lt;A title="Update feature in a feature layer" href="https://developers.arcgis.com/python/sample-notebooks/updating-features-in-a-feature-layer/" target="_self"&gt;https://developers.arcgis.com/python/sample-notebooks/updating-features-in-a-feature-layer/&lt;/A&gt;&amp;nbsp;.&amp;nbsp;&amp;nbsp;In the link example, they use point geometry, but in my case I’m trying to update polygon geometry. I have updated the code to work with polygon geometry but I’m receiving the following error "None of [Index([('SHAPE',)], dtype='object')] are in the [columns]", which is related to the input geometry line in my code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;my code is&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# complete the updates
from arcgis import geometry #use geometry module to project the records
from copy import deepcopy

for cr_id in overlap_rows['cr_id']:
    # get the feature to be updated
    original_feature = [f for f in all_features if f.attributes['cr_id'] == cr_id][0]
    feature_to_be_updated = deepcopy(original_feature)
    
    print(str(original_feature))
    
    # get the matching row from the update layer ()
    matching_row = CRID_New_ly_FS2.where(CRID_New_ly_FS2.cr_id == cr_id).dropna()
    
    #get geometries in the destination coordinate system
    input_geometry = {'rings': float(matching_row[[['SHAPE']]])}
        
    output_geometry = geometry.project(geometries = [input_geometry],
                                       in_sr = CRID_Old_FS.spatial_reference['wkid'],
                                       out_sr = CRID_Old_FS.spatial_reference['latestWkid'],
                                       gis = gis1)
    
    # assign the updated values
    feature_to_be_updated.geometry = output_geometry[0]
    feature_to_be_updated.attributes['cr_id'] = int(matching_row['cr_id'])
    feature_to_be_updated.attributes['C31013'] = matching_row['C31013'].values[0]
    feature_to_be_updated.attributes['big_shape'] = matching_row['big_shape'].values[0] 
    feature_to_be_updated.attributes['site_name'] = matching_row['site_name'].values[0]
    feature_to_be_updated.attributes['awh_stage'] = int(matching_row['awh_stage'])
    feature_to_be_updated.attributes['awh_package'] = int(matching_row['awh_package'])
    
   # #add this to the list of features to be updated
    features_for_update.append(feature_to_be_updated)
   # 
    print(str(feature_to_be_updated))
    print("========================================================================")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&amp;nbsp;&lt;/P&gt;&lt;P&gt;many thanks&lt;/P&gt;&lt;P&gt;Ash&lt;/P&gt;</description>
    <pubDate>Sat, 03 Apr 2021 08:25:14 GMT</pubDate>
    <dc:creator>afana1972</dc:creator>
    <dc:date>2021-04-03T08:25:14Z</dc:date>
    <item>
      <title>Updating polygon features from a feature layer in arcgis API Python</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/updating-polygon-features-from-a-feature-layer-in/m-p/1043566#M39295</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;I'm trying to replicate the code published by ESRI in &lt;A title="Update feature in a feature layer" href="https://developers.arcgis.com/python/sample-notebooks/updating-features-in-a-feature-layer/" target="_self"&gt;https://developers.arcgis.com/python/sample-notebooks/updating-features-in-a-feature-layer/&lt;/A&gt;&amp;nbsp;.&amp;nbsp;&amp;nbsp;In the link example, they use point geometry, but in my case I’m trying to update polygon geometry. I have updated the code to work with polygon geometry but I’m receiving the following error "None of [Index([('SHAPE',)], dtype='object')] are in the [columns]", which is related to the input geometry line in my code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;my code is&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# complete the updates
from arcgis import geometry #use geometry module to project the records
from copy import deepcopy

for cr_id in overlap_rows['cr_id']:
    # get the feature to be updated
    original_feature = [f for f in all_features if f.attributes['cr_id'] == cr_id][0]
    feature_to_be_updated = deepcopy(original_feature)
    
    print(str(original_feature))
    
    # get the matching row from the update layer ()
    matching_row = CRID_New_ly_FS2.where(CRID_New_ly_FS2.cr_id == cr_id).dropna()
    
    #get geometries in the destination coordinate system
    input_geometry = {'rings': float(matching_row[[['SHAPE']]])}
        
    output_geometry = geometry.project(geometries = [input_geometry],
                                       in_sr = CRID_Old_FS.spatial_reference['wkid'],
                                       out_sr = CRID_Old_FS.spatial_reference['latestWkid'],
                                       gis = gis1)
    
    # assign the updated values
    feature_to_be_updated.geometry = output_geometry[0]
    feature_to_be_updated.attributes['cr_id'] = int(matching_row['cr_id'])
    feature_to_be_updated.attributes['C31013'] = matching_row['C31013'].values[0]
    feature_to_be_updated.attributes['big_shape'] = matching_row['big_shape'].values[0] 
    feature_to_be_updated.attributes['site_name'] = matching_row['site_name'].values[0]
    feature_to_be_updated.attributes['awh_stage'] = int(matching_row['awh_stage'])
    feature_to_be_updated.attributes['awh_package'] = int(matching_row['awh_package'])
    
   # #add this to the list of features to be updated
    features_for_update.append(feature_to_be_updated)
   # 
    print(str(feature_to_be_updated))
    print("========================================================================")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions?&amp;nbsp;&lt;/P&gt;&lt;P&gt;many thanks&lt;/P&gt;&lt;P&gt;Ash&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 08:25:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/updating-polygon-features-from-a-feature-layer-in/m-p/1043566#M39295</guid>
      <dc:creator>afana1972</dc:creator>
      <dc:date>2021-04-03T08:25:14Z</dc:date>
    </item>
    <item>
      <title>Re: Updating polygon features from a feature layer in arcgis API Python</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/updating-polygon-features-from-a-feature-layer-in/m-p/1043573#M39297</link>
      <description>&lt;P&gt;did you check the nesting depth in&lt;/P&gt;&lt;P&gt;&lt;EM&gt;input_geometry = {'rings': float(matching_row[[['SHAPE']]])}&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;throw a print statement in to see if you are getting the appropriate content&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 09:50:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/updating-polygon-features-from-a-feature-layer-in/m-p/1043573#M39297</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2021-04-03T09:50:38Z</dc:date>
    </item>
    <item>
      <title>Re: Updating polygon features from a feature layer in arcgis API Python</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/updating-polygon-features-from-a-feature-layer-in/m-p/1043581#M39298</link>
      <description>&lt;P&gt;Hi Dan,&lt;/P&gt;&lt;P&gt;Thanks for your reply.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think your comment triggered me to print every step in my code and I think the problem reside in the dictionary format resulted from the "input_geometry" line code.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The matching_row is a record, which contains the SHAPE attribute. So the code should be&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;input_geometry = {'rings': matching_row['SHAPE']}. However, printing one record, will produce the ploygon geometry&amp;nbsp;&lt;SPAN&gt;{"rings": [[[-149459.83432124555, 6834762.7625... }Name: SHAPE, dtype: geometry. The problem is how to access the dictionary values of [[[]]]?&lt;/SPAN&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;SPAN&gt;Ashraf,&amp;nbsp;&lt;/SPAN&gt;&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 03 Apr 2021 11:50:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/updating-polygon-features-from-a-feature-layer-in/m-p/1043581#M39298</guid>
      <dc:creator>afana1972</dc:creator>
      <dc:date>2021-04-03T11:50:49Z</dc:date>
    </item>
    <item>
      <title>Re: Updating polygon features from a feature layer in arcgis API Python</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/updating-polygon-features-from-a-feature-layer-in/m-p/1097521#M42134</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/470415"&gt;@afana1972&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;The following code snippet should work.&lt;/P&gt;&lt;P&gt;You just need to change the layer names and variables accordingly.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis import geometry #use geometry module to project the records
from copy import deepcopy

original_item = gis.content.get("item_id")
original_layers = original_item.layers
fLyr = original_item.layers[0]
fset = fLyr.query()

new_item = gis.content.get("item_id")
new_fLyr = new_item.layers[0]
new_fset = new_fLyr.query()
new_fset_features = new_fLyr.query().features
new_flayer_rows = new_fset.sdf

features_to_be_added = []
template_hostedFeature = deepcopy(fset.features[0])
for index, row in new_flayer_rows.iterrows():
    feature_to_be_updated = deepcopy(template_hostedFeature)
    input_geometry = new_fset_features[index].geometry
    
    output_geometry = geometry.project(geometries = [input_geometry],
                                       in_sr = fset.spatial_reference['wkid'], 
                                       out_sr = fset.spatial_reference['latestWkid'], 
                                       gis = gis1)
    
    # assign the updated values
    feature_to_be_updated.geometry = output_geometry[0]
    feature_to_be_updated.attributes['cr_id'] = int(row['cr_id'])
    feature_to_be_updated.attributes['C31013'] = row['C31013'].values[0]
    feature_to_be_updated.attributes['big_shape'] = row['big_shape'].values[0] 
    feature_to_be_updated.attributes['site_name'] = row['site_name'].values[0]
    feature_to_be_updated.attributes['awh_stage'] = int(row['awh_stage'])
    feature_to_be_updated.attributes['awh_package'] = int(row['awh_package'])
    
   # #add this to the list of features to be updated
   features_to_be_added.append(feature_to_be_updated)

original_layers[0].edit_features(adds = features_to_be_added) &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope that's helpful.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Sep 2021 03:46:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/updating-polygon-features-from-a-feature-layer-in/m-p/1097521#M42134</guid>
      <dc:creator>MehdiPira1</dc:creator>
      <dc:date>2021-09-13T03:46:57Z</dc:date>
    </item>
  </channel>
</rss>

