Select to view content in your preferred language

Creating View Layer Problem

372
1
08-20-2024 11:13 AM
Labels (1)
Pukawai
Emerging Contributor

I'm trying to create some View layers using code I found here but am having some problems.

The code below runs without errors and creates the View Layer, but if I try to add the layer to a map I get the incredibly useful error "An error occurred loading this layer". Further investigation revealed that the View Layer's item details does not list any layers even though the code says there is one.

I can create a view layer manually using the same feature layer and it works fine and does list the layer in the view layer's item details.

I've commented out the portion of the code that adds a definition query as it does not seem to be relevant to the problem. Any insights as to what's going on here would be greatly appreciated.

from arcgis import GIS
from arcgis.features import FeatureLayerCollection
gis = GIS('https://www.arcgis.com', 'USER', 'PWD')

sourceLayer = "Overhead"
source_search = gis.content.search(sourceLayer)
for s in source_search:
    if(s.title == sourceLayer and s.type == "Feature Service"):
        source_flc = FeatureLayerCollection.fromitem(s)
        print(s)
        # Create View from Source Hosted Feature Layer
        new_view = source_flc.manager.create_view(name="ThreePhaseOH")
        view_flc = FeatureLayerCollection.fromitem(new_view)
        print(len(view_flc.layers))
#        view_layer = view_flc.layers[0]
#        view_def = {"viewDefinitionQuery" : "(wmBaseKv >= 2.4) AND (wmBaseKv < 2.5)"}
#        view_layer.manager.update_definition(view_def)
        print(new_view)

 

0 Kudos
1 Reply
JohnYaist1
Esri Contributor

Hi @Pukawai - Can you please contact Esri Support so we can try to reproduce this onsite and investigate further?

0 Kudos