Select to view content in your preferred language

Count cars script not working, KeyError: 'layers'

625
3
04-12-2024 01:28 AM
DavideBoazzi
New Contributor

I'm running this count cars in aerial imagery script  and everything seems to be working until I run the detection block. It says KeyError: 'layers'. How to fix this?

DavideBoazzi_0-1712910340126.png

 

0 Kudos
3 Replies
Clubdebambos
Frequent Contributor

Hi @DavideBoazzi 

We are missing important steps in your script, can you post the entire code before you get the error?

In the example you are following, the imagery variable is a list containing four Image Layer item objects. Your script is assuming that imagery[i] (one of these Image Layer objects) has a property called layers. Make sure your imagery list is indeed a list of Imagery Layers. 

If you print(imagery), is a list of Imagery Layer Item objects returned?

~ learn.finaldraftmapping.com
0 Kudos
DavideBoazzi
New Contributor

Hi @Clubdebambos I'm running exactly the same code that is provided in the link, with no changes. I also published my layers as imagery layers.

Here's what

imagery = gis.content.search("aerial*") 

print(imagery)

returns (I loaded 4 layers and 4 these layers are displayed):

[<Item title:"aerial3" type:Image owner:MICGis>, <Item title:"aerial1" type:Image owner:MICGis>, <Item title:"aerial4" type:Image owner:MICGis>, <Item title:"aerial2" type:Image owner:MICGis>]

 

0 Kudos
Clubdebambos
Frequent Contributor

Hi @DavideBoazzi ,

Your Item type says Image, not Imagery Layer like in the example.

Do your items in ArcGIS Online say Imagery Layer like below?

Clubdebambos_0-1713258474108.png

This type of Image content item will not work.

Clubdebambos_2-1713261331474.png

There is a difference between an Image

Clubdebambos_0-1713260712505.png

and an Imagery Layer which is an Image Service 

Clubdebambos_1-1713260874227.png

Source: https://developers.arcgis.com/rest/users-groups-and-items/items-and-item-types.htm

 

 

 

 

~ learn.finaldraftmapping.com
0 Kudos