Select to view content in your preferred language

Python script to change data source of feature layer

815
2
10-26-2023 03:00 PM
Ivy_Hinson
Occasional Contributor

I am trying to write a script that updates a feature layer on arcgis online. I need to replace the data source to the new feature class each time I run the script. How can I accomplish this?

0 Kudos
2 Replies
MobiusSnake
MVP Regular Contributor

Assuming you're talking about hosted feature layers (as opposed to those coming from Enterprise), I could be mistaken but I don't believe this is possible.  Feature classes are completely abstracted away in AGOL, and users (along with the API) only have access to feature layers.

I'm going to take a guess and speculate you want to do this to make web maps, apps, forms, etc. use an updated data source, rather than modifying the maps/apps/etc. to use to a new feature layer?  I believe it's possible to change the source of a feature layer view (although I'm not sure how to do it in Python), so a solution may be to do this:

  • Initially:
    • Publish a feature layer
    • Create feature layer views
    • Configure your maps/apps/etc. to use the views
  • When an update is required:
    • Publish your updated feature layer
    • Alter the views to use the new layer as their sources
    • Delete the original layer
0 Kudos
MeganWheatley
Regular Contributor

Why are you needing to replace the data source? Can you not truncate and append the data in your hosted feature layer to accomplish what you are needing?

Also, AGOL now has the ability to swap views so if you want to do something like that it could be helpful. 

0 Kudos