Hi,
I am attempting to use the copy_feature_layer_collection in a Notebook on ArcGIS Online (Python 3). Previously this worked fine (possibly when AGOL was using an older version of the python?). Now it fails.
newHab = habItem.copy_feature_layer_collection(service_name = habName, layers = layer_ids_h, tables = table_ids_h, folder = folderName)
The error given looks like this:
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) /tmp/ipykernel_19/1373826970.py in <cell line: 0>() ---> 19 newHab = habItem.copy_feature_layer_collection(service_name = habName, layers = layer_ids_h, tables = table_ids_h, folder = folderName) /opt/conda/lib/python3.11/site-packages/arcgis/gis/__init__.py in copy_feature_layer_collection(self, service_name, layers, tables, folder, description, snippet, owner) > 13848 fs = FeatureLayerCollection(url=copied_item.url, gis=self._gis) 13849 fs_manager = fs.manager 13850 add_defs = {"layers": [], "tables": []} AttributeError: 'NoneType' object has no attribute 'url'
I have tested the item and all the input parameters - all seem valid.
ANy ideas why this might have happended? We used this to replace the clone_items() that also changed behavior after python updates.
thanks!
Joe
Hi @JoeNunn,
How are you creating the habItem Item object? Print the habItem variable to screen and see what is returned.
Hi @Clubdebambos , Its a feature layer collection with multiple layers (7 or 8 i think). Its we use it as a template:
Would there be a better way to generate a new hosted feature collection from a template (say from a schema?) than attempting to duplicate an existing feature collection?
Hi @JoeNunn,
I use the same workflow but I haven't had any issues. Here's my code below. Also works fine in an ArcGIS Online Notebook.
from arcgis.gis import GIS
################################################################################
## USER INPUT ##################################################################
new_service_name = "TESTING_DEEP_COPY"
item_id = "FS_ITEM_ID"
################################################################################
## ACCESS ARCGIS ONLINE ########################################################
agol = GIS("home")
################################################################################
## GET THE FEATURE SERVICE ITEM OBJECT #########################################
item = agol.content.get(item_id)
################################################################################
## INTEGER LISTS OF LAYERS & TABLES ############################################
## get the layer indexes
layers = list(range(len(item.layers)))
## get the table indexes
tables = list(range(len(item.tables)))
################################################################################
## COPY THE FEATURE SERVICE OBJECT ITEM ########################################
## copy the item - copies the shell/schema, no data is added to the layers/tables
copied_item = item.copy_feature_layer_collection(
service_name = new_service_name,
layers = layers,
tables = tables,
description = item.description,
snippet = item.snippet
)
print(copied_item)
################################################################################
print("\nSCRIPT COMPLETE")
Alternatively you can create an empty feature service and define your own layers, here's an example adding a point feature layer (blog), you can add multiple feature layers at once or add after the fact. You can get the field definitions from you current feature layer and define the workflow yourself to create a new feature service with your templated layers as a script.
All the best,
Glen