Select to view content in your preferred language

AGOL-Using Python to create feature layer from URL

85
3
Monday
MaggieT
Emerging Contributor

I sometimes need to create new, discrete layers with the same forms and symbology as a template layer. Manually, the way to do this is to create a new feature layer and select "provide an ArcGIS Server layer URL." Is there a straightforward way to do this with python in an AGOL notebook? Or do I need to get into the JSON for the template layer and somehow apply that to a new blank layer (I'm pretty new to doing stuff like that so please dumb it down if so)?

0 Kudos
3 Replies
RichardHowe
Frequent Contributor

We use the clone_items method from the ArcGIS API for Python. Whilst primarily designed for copying data from one portal to another, you can make the source and target portal the same. You will need to use some code to rename the clone once it's done, but it works well for us

0 Kudos
Clubdebambos
MVP Regular Contributor

This is a nice option. Just to note I had issues with this in the past where I could only clone a feature service once, it would throw and error if I attempted to clone a second time. Have you ever come across this issue? When I get a chance I'll test it out for myself! I have used the ArcGIS API for Python successfully to create deep copies of a Feature Service or a single Feature Layer.

Here's a couple of workflows...

~ learn.finaldraftmapping.com
0 Kudos
RichardHowe
Frequent Contributor

I have to confess, we build the maps in their entirety, complete with symbology, forms etc. then clone the web map item (rather than individual feature layers) and allow the process to clone all the component feature services as part of the process and we never hit an issue, as long as the: 

copy_data=True
and
search_existing_items=False

parameters are used. I would play with combining those parameters though and I think you should get what you need.

0 Kudos