<?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: Stable patterns for truncate and loading large datasets in ArcGIS Online programmatically in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/stable-patterns-for-truncate-and-loading-large/m-p/1549637#M10780</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/202029"&gt;@Jay_Gregory&lt;/a&gt;,&amp;nbsp;I've recommended the following &lt;A href="https://community.esri.com/t5/arcgis-online-documents/overwrite-arcgis-online-feature-service-using/ta-p/904457" target="_self"&gt;script&lt;/A&gt; to several users who have had success.&amp;nbsp; Just today I updated it to include upsert functionality.&lt;/P&gt;</description>
    <pubDate>Thu, 17 Oct 2024 18:17:34 GMT</pubDate>
    <dc:creator>JakeSkinner</dc:creator>
    <dc:date>2024-10-17T18:17:34Z</dc:date>
    <item>
      <title>Stable patterns for truncate and loading large datasets in ArcGIS Online programmatically</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/stable-patterns-for-truncate-and-loading-large/m-p/1549113#M10778</link>
      <description>&lt;P&gt;I'm curious what the best practices are for truncate and load for large datasets into ArcGIS Online feature services using Python.&amp;nbsp; My inclination is to use a spatial data frame, the manager.truncate and edit_features methods on the featurelayer class.&amp;nbsp; However is writing 100k records using edit_features supported?&amp;nbsp; Should I break it up into chunks of 10k and load that way?&amp;nbsp; Maybe wait 10 seconds between each load?&lt;/P&gt;&lt;P&gt;Another patten (one I don't like is much) is using a CSV, shapefile, or something else and then doing the "overwrite layer" pattern.&amp;nbsp; However in most cases I am querying the source data from an API or database elsewhere so its easier to create a SDF instead of a shapefile or CSV.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yet another is creating a new feature service from the data and choosing replace layer.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The context here is I will sometimes get some unexplained errors using the edit_features method - it will just crash and say "json decode error".&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2024 16:03:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/stable-patterns-for-truncate-and-loading-large/m-p/1549113#M10778</guid>
      <dc:creator>Jay_Gregory</dc:creator>
      <dc:date>2024-10-16T16:03:10Z</dc:date>
    </item>
    <item>
      <title>Re: Stable patterns for truncate and loading large datasets in ArcGIS Online programmatically</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/stable-patterns-for-truncate-and-loading-large/m-p/1549637#M10780</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/202029"&gt;@Jay_Gregory&lt;/a&gt;,&amp;nbsp;I've recommended the following &lt;A href="https://community.esri.com/t5/arcgis-online-documents/overwrite-arcgis-online-feature-service-using/ta-p/904457" target="_self"&gt;script&lt;/A&gt; to several users who have had success.&amp;nbsp; Just today I updated it to include upsert functionality.&lt;/P&gt;</description>
      <pubDate>Thu, 17 Oct 2024 18:17:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/stable-patterns-for-truncate-and-loading-large/m-p/1549637#M10780</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2024-10-17T18:17:34Z</dc:date>
    </item>
    <item>
      <title>Re: Stable patterns for truncate and loading large datasets in ArcGIS Online programmatically</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/stable-patterns-for-truncate-and-loading-large/m-p/1551023#M10785</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/10527"&gt;@JakeSkinner&lt;/a&gt;&amp;nbsp;Thanks - though this seems a little beefy for a lot of use cases.&amp;nbsp; But my question is specific to large feature classes - I would like to use the following two methods:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def truncate_portal_data(fl_url:str)-&amp;gt;object:
    """Truncates a feature layer or able through the REST endpoint

    Args:
        fl_url (str): REST endpoint of the feature layer

    Returns:
        object: results object
    """
    ids = fl_url.query(return_ids_only=True)['objectIds']
    results = fl_url.edit_features(deletes=ids) if len(ids)&amp;gt;0 else  {"results":"No features to delete"}
    return results


def update_portal_data(df:pd.DataFrame, fl_url:str, truncate:bool=True, chunk_size:int=500)-&amp;gt;object:
    import numpy as np
    from time import sleep
    """Adds features from a dataframe to a Portal / AGOL feature service.  
    Args:
        df (pd.DataFrame): DataFrame from which to update features
        fl_url (str): Feature service URL
        truncate (bool, optional): Truncate table before updating. Defaults to True.

    Returns:
        object: results of update operation
    """
    if truncate:
        truncate_portal_data(fl_url)
    numchunks = int(len(df)/chunk_size) or 1
    chunks = np.array_split(df,numchunks)
    for chunk in chunks:
         fl_url.edit_features(adds=chunk.spatial.to_featureset())
         sleep(5)
    return True&lt;/LI-CODE&gt;&lt;P&gt;But my question is is there any reason your script is preferable over the much simpler API methods above for large feature classes?&lt;/P&gt;</description>
      <pubDate>Tue, 22 Oct 2024 18:21:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/stable-patterns-for-truncate-and-loading-large/m-p/1551023#M10785</guid>
      <dc:creator>Jay_Gregory</dc:creator>
      <dc:date>2024-10-22T18:21:54Z</dc:date>
    </item>
  </channel>
</rss>

