Select to view content in your preferred language

create_view Does not work if layer ids are not ordered sequentially

325
4
06-09-2024 06:40 AM
Labels (1)
RandyMcGregor_Home
Occasional Contributor

Views created programmatically from services that have non-sequential layer ids are unusable. I created a view from this code:

source_search = gis.content.search("test_20240608_unique_ids_assigned_all_around")[0]
source_flc = FeatureLayerCollection.fromitem(source_search)

new_view = source_flc.manager.create_view(name="unid_all_around_view")

Source-Service layer ids:

RandyMcGregor1_2-1717940262608.png

 

View layer ids:

RandyMcGregor1_1-1717940200627.png

When the view is opened in the map viewer, the layers are messed up. The Route line layer has become a point layer and one of the point layers (the one with the very long name!) has become a line. A complete mess.

RandyMcGregor1_0-1717940084014.png

This happens consistently, on more than one platform. It does not happen when views are created manually. Also, create_view works fine when the layers are ordered sequentially 0 to N, top-down.

0 Kudos
4 Replies
Dirk_Vandervoort
Occasional Contributor

I've experienced this issue. I believe it is a defect that Esri should correct: create_view fails to index the layers sequentially.

I see you commented on my other thread.

Meanwhile, the workaround is to manually zero-based index the layers in the hosted feature layer using https://ago-assistant.esri.com/ 

Dirk_Vandervoort_0-1718032592182.png

I'm working on a solution in Python but haven't gotten there yet.

 

RandyMcGregor_Home
Occasional Contributor

It's actually a bug, but I can't scare it up at the moment. The status of the bug is 'As-Designed' which I do not understand.

0 Kudos
RandyMcGregor_Home
Occasional Contributor

The 'workaround' offered by the bug-description, is to create the view manually in AGOL.

0 Kudos
RandyMcGregor_Home
Occasional Contributor

Thanks. I'll check that out. There is a 'preserve_layer_ids' property in the create_view method, but I haven't gotten it to accept True

create_view(name = viewName, preserve_layer_ids = True) throws an error. Replace True with False and it works but that's the default and not what I want for this. 

0 Kudos