What I am trying to do: Take a layer from ArcGIS Enterprise, clone it as a temporary file, overwrite a file in SQL DB, delete temporary file.
What I have tried so far:
def overwrite_existing_layer(source_layer_name, sql_database, layer_name):
try:
# Connect to the ArcGIS Portal
gis = GIS('pro')
portal_dstore = gis.datastore
# 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()
# Save the temporary copy to overwrite the existing layer in the SQL database
Don't know how to do this using arcgis.gis. (tried a variety of things)
print("Temporary copy overwritten in SQL database.")
# Delete the temporary copy
portal_dstore.delete_layers(temporary_copy)
if not temporary_copy.exists:
print("Temporary copy deleted.")
print('Finished running script')
except Exception as e:
# Handle any errors that occur during the process
print(f"An error occurred: {str(e)}")`
Issue: I have not been able to find a way to save the copy to our SQL DB
Alternative option: Just clone the layer in portal and publish it back to portal (ultimate goal is to create view layers of clone which cannot be done on original)
Code I have tried for that:
def overwrite_existing_layer(source_layer_name, layer_name):
try:
# Connect to the ArcGIS Portal
gis = GIS('pro')
portal_dstore = gis.datastore
# 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 = ContentManager.clone_items(items=source_layer, folder=folder)
print("Temporary copy overwritten in SQL database.")
# Delete the temporary copy
portal_dstore.delete_layers(temporary_copy)
if not temporary_copy.exists:
print("Temporary copy deleted.")
print('Finished running script')
except Exception as e:
# Handle any errors that occur during the process
print(f"An error occurred: {str(e)}")
Issue: I have not been able to find a way to save the cloned layer to portal (this is probably confused on what is meant by folder. Is that just a folder I'd like it to be saved in within my enterprise portal?