<?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: Layer does not overwrite when using to_featurelayer() in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/layer-does-not-overwrite-when-using-to/m-p/1300381#M8804</link>
    <description>&lt;P&gt;Dan, I appreciate your response. Unfortunately have not found a way to overwrite like you can in pro.&lt;/P&gt;</description>
    <pubDate>Fri, 16 Jun 2023 19:56:07 GMT</pubDate>
    <dc:creator>ZacharyKasson</dc:creator>
    <dc:date>2023-06-16T19:56:07Z</dc:date>
    <item>
      <title>Layer does not overwrite when using to_featurelayer()</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/layer-does-not-overwrite-when-using-to/m-p/1296790#M8758</link>
      <description>&lt;P&gt;-Goal: I am trying to create a script to access a layer on portal and clone it. After cloning it I would like to overwrite a layer in either a SQL database or back in portal.&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Reason: As the original layer updates I would like to run the script to update the copy in which I have view layers created from.&lt;/P&gt;&lt;P&gt;-I have been able to copy the layer and publish it to portal using to_featurelayer()&lt;/P&gt;&lt;P&gt;The issue is that the layer will not overwrite the existing layer in portal.&lt;/P&gt;&lt;P&gt;Here is the code I have been trying:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def overwrite_existing_layer(source_layer_name,feature_service_id,copy_layer_name):
    try:

  
        # Connect to the ArcGIS Portal
        gis = GIS('pro')

        # Retrieve the feature layer you want to clone
        source_layer = gis.content.search(source_layer_name, item_type="Feature Layer")[0]
        
        # Create a temporary copy of the layer
        temporary_copy = source_layer.layers[0].query()
        
        # Creat Pandas df from temporary copy
        temp_sdf = temporary_copy.sdf

        # Create a dictionary for the properties of to_featurelayer method
        fl_properties = {
        'layer': 0,  
        'featureServiceId': feature_service_id  
        }


        # Overwrite the feature layer
        new_layer = temp_sdf.spatial.to_featurelayer(title=copy_layer_name, overwrite=True, service={'layer': 0, 'featureServiceId': feature_service_id})

        print("Temporary copy overwritten in SQL database.")

        print('Finished running script')

    except Exception as e:
        # Handle any errors that occur during the process
        print(f"An error occurred: {str(e)}")&lt;/LI-CODE&gt;&lt;P&gt;The script runs fine but does not overwrite the existing layer. I have the correct&amp;nbsp;feature_service_id from the existing layer in portal but am not sure why it does not recognize the existing layer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Jun 2023 17:08:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/layer-does-not-overwrite-when-using-to/m-p/1296790#M8758</guid>
      <dc:creator>ZacharyKasson</dc:creator>
      <dc:date>2023-06-07T17:08:39Z</dc:date>
    </item>
    <item>
      <title>Re: Layer does not overwrite when using to_featurelayer()</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/layer-does-not-overwrite-when-using-to/m-p/1297773#M8765</link>
      <description>&lt;P&gt;Normally in Pro there is an "overwriteOutputs" option" to enable you do do exactly what you want.&amp;nbsp; I dont' know if it can be used with the api and portal.&lt;/P&gt;&lt;P&gt;You might want to "delete" using the appropriate python arcgis api call prior to adding the newer version.&lt;/P&gt;</description>
      <pubDate>Fri, 09 Jun 2023 22:25:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/layer-does-not-overwrite-when-using-to/m-p/1297773#M8765</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2023-06-09T22:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: Layer does not overwrite when using to_featurelayer()</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/layer-does-not-overwrite-when-using-to/m-p/1300381#M8804</link>
      <description>&lt;P&gt;Dan, I appreciate your response. Unfortunately have not found a way to overwrite like you can in pro.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Jun 2023 19:56:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/layer-does-not-overwrite-when-using-to/m-p/1300381#M8804</guid>
      <dc:creator>ZacharyKasson</dc:creator>
      <dc:date>2023-06-16T19:56:07Z</dc:date>
    </item>
  </channel>
</rss>

