Hi, I'm trying to use the overwrite feature within the Python API to add/update a feature layer. The script is supposed to update the layers data every morning, but it's not doing so. I'm not getting any error message, in fact, the overwrite method is returning 'success' : True. See below the code I'm using for the update/overwrite inside my python script. I followed the instructions in https://developers.arcgis.com/python/sample-notebooks/overwriting-feature-layers/ and reuse a method in another post here to go from table to pandas dataframe. Can anyone help, if I do the overwrite manually within Pro with layers generated by the script everything works fine and the data is updated.
from arcgis import GIS
import arcpy
import pandas as pd
import numpy as np
from arcgis.features import FeatureLayerCollection
import os
Default_gdb = 'Project.gdb'
arcpy.env.overwriteOutput = True
arcpy.env.workspace = Default_gdbgis = GIS("pro")
parcel_layer = gis.content.get(id_layer1)
parcel_layer = parcel_layer.layers[0]
parcelDF = parcel_layer.query().sdf
DB = 'DBConnection.odc/dbo.Refresh'
arcpy.conversion.TableToGeodatabase(DB, Default_gdb)
def table_to_data_frame(in_table, input_fields=None, where_clause=None):
"""Function will convert an arcgis table into a pandas dataframe with an object ID index, and the selected
input fields using an arcpy.da.SearchCursor."""
OIDFieldName = arcpy.Describe(in_table).OIDFieldName
if input_fields:
final_fields = [OIDFieldName] + input_fields
else:
final_fields = [field.name for field in arcpy.ListFields(in_table)]
data = [row for row in arcpy.da.SearchCursor(in_table, final_fields, where_clause=where_clause)]
fc_dataframe = pd.DataFrame(data, columns=final_fields)
fc_dataframe = fc_dataframe.set_index(OIDFieldName, drop=True)
return fc_dataframe
CDW = table_to_data_frame(os.path.join(Default_gdb, 'dbo_Refresh'))
parcel_land = parcelDF.merge(CDW, left_on='FOLIO', right_on='FOLIO', how='left')
parcel_land .spatial.to_featureclass(os.path.join(Default_gdb, 'Data_All'))
data_layer = gis.content.get(id2)
data_item = FeatureLayerCollection.fromitem(data_layer)
data_item.manager.overwrite(os.path.join(Default_gdb, 'Data_All'))