I am trying to come up with a method that utilizes lyrx files to routinely overwrite a feature layer on ArcGIS Portal. I've tried a few methods that utilize Python scripts, ModelBuilder and Task Scheduler to accomplish this, but I feel like the main issue is with the file format (lyrx).
I am back at square one with this, so any feedback/suggestions?
aprx = arcpy.mp.ArcGISProject(aprx_path)
map = aprx.listMaps()[0]
layer = map.addDataFromPath(lyr_file_path)
outputfc_path = f"{outputgdb}/{outputfc_name}"
arcpy.FeatureClassToFeatureClass_conversion(in_features = layer, out_path = outputgdb, out_name = outputfc_name)
print(f"Feature class created at: {outputfc_path}")
gis = GIS(portalurl, username, password)
item = gis.content.get(itemid)
flayer_collection = FeatureLayerCollection.fromitem(item)
flayer_collection.manager.overwrite(outputfc_path)
try:
flayer_collection.manager.overwrite(outputfc_path)
print("Feature layer has been successfully overwritten with updated data.")
except Exception as e:
print(f"Error during overwrite: {e}")
All my variables are assigned in a different section which shows personal info so i cant include it in the post. This has worked the best in terms of making the lyr into a feature class. However, when uploading to portal it says that it has been modifeid, but the feature count is not what it should be!