<?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: Append/edit_features in AGOL (large dataset) in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/append-edit-features-in-agol-large-dataset/m-p/1150865#M7205</link>
    <description>&lt;P&gt;&amp;nbsp;First thing: have you tried using &lt;STRONG&gt;sanitize_columns=False&lt;/STRONG&gt; when you convert the dataframe? It defaults to True, and does have the potential to mess with your columns quite a bit, depending on the original names. But I know there are places where it will sanitize the column names and &lt;EM&gt;not &lt;/EM&gt;let you choose otherwise.&lt;/P&gt;&lt;P&gt;For chunking your edits, I do the same thing, basically.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;i = 0
chunk = 200

while i &amp;lt; len(sdf):
    fs = sdf.iloc[i:i+chunk].spatial.to_featureset()
    featurelayer.edit_features(adds=fs)
    i += chunk&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;I have a few services I regularly append to and edit, and some of them are quite large datasets (though I wouldn't call them "massive"), and this method seems to work just fine.&lt;/P&gt;&lt;P&gt;Finally, if you're working w/ JSON data, you &lt;EM&gt;can &lt;/EM&gt;submit a list of dicts to the edit_feature function, so long as the follow the same format as it expects. I have a couple scripts that use that method for one reason or another.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;feats = [
    {
        'attributes': {
            'some_attribute': 'a value',
            'another_attribute': 1002.14
        },
        'geometry': {
            'x': 44.05,
            'y': 27.2201,
            'spatialReference': {
                'wkid': 4326
            }
        }
    },
    {
        'attributes': {
            'some_attribute': 'a different value',
            'another_attribute': -1.04
        },
        'geometry': {
            'x': 41.3,
            'y': 28.912,
            'spatialReference': {
                'wkid': 4326
            }
        }
    }
]

featurelayer.edit_features(adds=feats)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 04 Mar 2022 20:28:49 GMT</pubDate>
    <dc:creator>jcarlson</dc:creator>
    <dc:date>2022-03-04T20:28:49Z</dc:date>
    <item>
      <title>Append/edit_features in AGOL (large dataset)</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/append-edit-features-in-agol-large-dataset/m-p/1150769#M7202</link>
      <description>&lt;P&gt;I am writing a pipeline script that gets data from different sources using post requests, adds them to a geodataframe and processes the data using Geopandas functions. Then I need to add the result to AGOL.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't use local files, everything is in memory.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can I use gis.content.add to add a geojson dictionary to AGOL? Or any other in memory data like a feature set..&lt;BR /&gt;&lt;BR /&gt;I have been trying this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;gis=GIS("https://arcgis.com", username, password)

json_gdf=gdf.to_json()
data_properties = {
    'title': 'new_test',
    'description': 'test',
    'tags': 'test',
    'type': 'GeoJson'
}
flayer=gis.content.add(data_properties, json_gdf)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I get the following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;flayer=gis.content.add(data_properties, json_gdf)&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;File "/mnt/c/Users//Documents/Github//.venv/lib/python3.8/site-packages/arcgis/gis/__init__.py", line 5141, in add&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;itemid = self._portal.add_item(&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;File "/mnt/c/Users//Documents/Github//.venv/lib/python3.8/site-packages/arcgis/gis/_impl/_portalpy.py", line 362, in add_item&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&amp;nbsp;raise RuntimeError("File(" + data + ") not found.")&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;In a way it makes sense, because ContentManager.add expects the following formats:&lt;BR /&gt;"&lt;SPAN class=""&gt;Content&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;can be a file (such as a service definition, shapefile, CSV, layer package, file geodatabase, geoprocessing package, map package) or it can be a URL (to an ArcGIS Server service, WMS service, or an application).&lt;/SPAN&gt;"&lt;BR /&gt;&lt;BR /&gt;What are my options here?&lt;BR /&gt;I also tried adding the geodataframe to AGOL directly using spatial.to_featurelayer - it works, but the field names are messed up, since that tool uses a shapefile as an intermediary (e.g. "SOURCE_FEATURE" becomes "&lt;SPAN&gt;source_fea"&lt;/SPAN&gt;). That means I cannot append that data to an existing feature layer without having to write hundreds of field mapping rules.&lt;/P&gt;&lt;P&gt;NOTE: edit_features is not an option, the data is too big, and even chunked, it takes too long to add (and times out in Azure, but that's another story).&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 17:47:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/append-edit-features-in-agol-large-dataset/m-p/1150769#M7202</guid>
      <dc:creator>ASLPipeline</dc:creator>
      <dc:date>2022-03-04T17:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: Append/edit_features in AGOL (large dataset)</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/append-edit-features-in-agol-large-dataset/m-p/1150777#M7203</link>
      <description>&lt;P&gt;Take a look at &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#arcgis.features.GeoAccessor.from_geodataframe" target="_self"&gt;arcgis.features.GeoAccessor.from_geodataframe&lt;/A&gt;. You can convert your geodataframe to a spatially enabled dataframe, which can then be written directly to a new layer using &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#arcgis.features.GeoAccessor.to_featurelayer" target="_self"&gt;to_featurelayer&lt;/A&gt;. Using an intermediate shapefile shouldn't be necessary.&lt;/P&gt;&lt;P&gt;There is also the &lt;A href="https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html#arcgis.features.FeatureLayer.append" target="_self"&gt;append&lt;/A&gt; function, but I don't have any experience with using it.&lt;/P&gt;&lt;P&gt;I know you said it's another story, but how does edit_features time out? How are you chunking it up when you try that?&lt;/P&gt;&lt;P&gt;Also: your post makes it sound like you want this data to get added to an existing layer, rather than be added as a new layer, so it's a bit confusing that you're focusing on the content.add function here. Is the end goal a separate layer, or edits to an existing service?&lt;/P&gt;&lt;P&gt;If the latter: are you simply adding new records to the layer, or are some rows being updated / deleted?&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 18:00:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/append-edit-features-in-agol-large-dataset/m-p/1150777#M7203</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-03-04T18:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: Append/edit_features in AGOL (large dataset)</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/append-edit-features-in-agol-large-dataset/m-p/1150833#M7204</link>
      <description>&lt;P&gt;I am sorry for the confusion.&lt;BR /&gt;Yes, I am trying to add new records to an existing layer. I was using edit_features with good results, but this being a massive dataset - it times out. I am rerunning now to be able to add the exact error here.&lt;/P&gt;&lt;P data-unlink="true"&gt;How do I chunk? I wrote a function that basically iterates over the feature set and adds a couple hundred features at a time. Nothing fancy.&lt;BR /&gt;&lt;BR /&gt;Documentation for edit_features also mentions: "&lt;SPAN&gt;When making large number (250+ records at once) of edits,&amp;nbsp;&lt;/SPAN&gt;&lt;A title="arcgis.features.FeatureLayer.append" href="https://developers.arcgis.com/python/api-reference/arcgis.features.toc.html?highlight=edit_features#arcgis.features.FeatureLayer.append" target="_blank" rel="noopener"&gt;&lt;SPAN class=""&gt;append&lt;/SPAN&gt;&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;should be used over&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;edit_features&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;to improve performance and ensure service stability."&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;Tried&amp;nbsp;arcgis.features.GeoAccessor.from_geodataframe and&amp;nbsp;&amp;nbsp;to_featurelayer - but it messes up the field names. It's not me using the intermediate shapefile, the to_featurelayer tool uses it, thus it messes up those field names. This makes it unusable with the append tool (unless I do field mappings)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 19:34:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/append-edit-features-in-agol-large-dataset/m-p/1150833#M7204</guid>
      <dc:creator>ASLPipeline</dc:creator>
      <dc:date>2022-03-04T19:34:11Z</dc:date>
    </item>
    <item>
      <title>Re: Append/edit_features in AGOL (large dataset)</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/append-edit-features-in-agol-large-dataset/m-p/1150865#M7205</link>
      <description>&lt;P&gt;&amp;nbsp;First thing: have you tried using &lt;STRONG&gt;sanitize_columns=False&lt;/STRONG&gt; when you convert the dataframe? It defaults to True, and does have the potential to mess with your columns quite a bit, depending on the original names. But I know there are places where it will sanitize the column names and &lt;EM&gt;not &lt;/EM&gt;let you choose otherwise.&lt;/P&gt;&lt;P&gt;For chunking your edits, I do the same thing, basically.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;i = 0
chunk = 200

while i &amp;lt; len(sdf):
    fs = sdf.iloc[i:i+chunk].spatial.to_featureset()
    featurelayer.edit_features(adds=fs)
    i += chunk&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;I have a few services I regularly append to and edit, and some of them are quite large datasets (though I wouldn't call them "massive"), and this method seems to work just fine.&lt;/P&gt;&lt;P&gt;Finally, if you're working w/ JSON data, you &lt;EM&gt;can &lt;/EM&gt;submit a list of dicts to the edit_feature function, so long as the follow the same format as it expects. I have a couple scripts that use that method for one reason or another.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;feats = [
    {
        'attributes': {
            'some_attribute': 'a value',
            'another_attribute': 1002.14
        },
        'geometry': {
            'x': 44.05,
            'y': 27.2201,
            'spatialReference': {
                'wkid': 4326
            }
        }
    },
    {
        'attributes': {
            'some_attribute': 'a different value',
            'another_attribute': -1.04
        },
        'geometry': {
            'x': 41.3,
            'y': 28.912,
            'spatialReference': {
                'wkid': 4326
            }
        }
    }
]

featurelayer.edit_features(adds=feats)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 20:28:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/append-edit-features-in-agol-large-dataset/m-p/1150865#M7205</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-03-04T20:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: Append/edit_features in AGOL (large dataset)</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/append-edit-features-in-agol-large-dataset/m-p/1150908#M7206</link>
      <description>&lt;P&gt;I also do chunks with edit_features to avoid time outs. In a recent version of the python API they also added the future parameter which will allow asynchronous updates. I haven't had a chance to see what kind of effect that has on timeouts though.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JoshKalovGIS_0-1646430676839.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35666i4D53FE80CBF3618D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JoshKalovGIS_0-1646430676839.png" alt="JoshKalovGIS_0-1646430676839.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Josh&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 21:52:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/append-edit-features-in-agol-large-dataset/m-p/1150908#M7206</guid>
      <dc:creator>JoshKalovGIS</dc:creator>
      <dc:date>2022-03-04T21:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: Append/edit_features in AGOL (large dataset)</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/append-edit-features-in-agol-large-dataset/m-p/1151273#M7207</link>
      <description>&lt;P&gt;Documentation says sanitize_columns is set to False by default, but I just tried it nonetheless. This was the code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sdf = GeoAccessor.from_geodataframe(gdf)
lyr = sdf.spatial.to_featurelayer(title='test', sanitize_columns=False)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I got the following error:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;FONT color="#FF0000"&gt;Exception: TypeError: to_featurelayer() got an unexpected keyword argument 'sanitize_columns'&lt;BR /&gt;&lt;BR /&gt;&lt;FONT color="#000000"&gt;I like the way you chunk the sdf before converting to a Feature Set, I will probably steal that bit of code. I used to chunk the Feature Set.&lt;BR /&gt;I got the script to work locally without getting a timeout, by adding certain problematic chunks feature by feature:&lt;/FONT&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;try:
    add_result = Target_Layer.layers[0].edit_features(adds=fset)
except:
    for feature in fset:
        try:
            add_result = Target_Layer.layers[0].edit_features(adds=[feature])
        except:
            # some error message&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;FONT color="#000000"&gt;&amp;nbsp;I'll see how this acts once deployed to Azure.&lt;/FONT&gt;&lt;BR /&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2022 14:47:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/append-edit-features-in-agol-large-dataset/m-p/1151273#M7207</guid>
      <dc:creator>ASLPipeline</dc:creator>
      <dc:date>2022-03-07T14:47:49Z</dc:date>
    </item>
  </channel>
</rss>

