Select to view content in your preferred language

add_layer 'NoneType' object is not iterable

4725
10
Jump to solution
01-03-2021 06:42 PM
glewi3
by
Emerging Contributor

im trying to do tutorial at here:

https://developers.arcgis.com/python/sample-notebooks/land-cover-classification-using-unet/

when i get up to this line i get the error

m.add_layer(world_imagery_layer)
TypeError: 'NoneType' object is not iterable

however the other item can be added to my map (m) just fine

m.add_layer(label_layer)

 

 

ive tried:

https://community.esri.com/t5/arcgis-api-for-python-questions/nonetype-quot-error-when-adding-layer-...

but apparently                  .Layer()                 isn't an attribute

AttributeError: 'GIS' object has no attribute 'Layer'

 

 

im not sure why one layer can be added but the other can't?

 

0 Kudos
1 Solution

Accepted Solutions
MehdiPira1
Esri Contributor

Hi @glewi3 

What version of API are you using?

I'm getting the same error in 1.8.1 however I tested it in 1.8.3 and it's working.

I can recommend to upgrade your ArcGIS API for Python version to 1.8.3 and it should work.

MehdiPira1_0-1609730516367.png

MehdiPira1_1-1609730560511.png

 

 

 

View solution in original post

0 Kudos
10 Replies
RandyBurton
MVP Alum

I assume somewhere in your code you are setting a value for world_imagery_layer.  Something like:

 

world_imagery_item = ent_gis.content.search("title: WorldImagery_AOI_NewYork owner:api_data_owner", "Map Image Layer")[0]

world_imagery_layer = world_imagery_item.layers[0]

m.add_layer(world_imagery_layer)

 

The error suggests you might have a typo in the layer's name.  The layer would not be found and a None would be returned.  If you don't spot the error, you should share the bit of code where the  world_imagery_layer is being set.

0 Kudos
glewi3
by
Emerging Contributor

world_imagery_item = gis.content.search("title: WorldImagery_AOI_NewYork",
"Map Image Layer")[0] # the index might change
world_imagery_item

 

world_imagery_layer = world_imagery_item.layers[0]

 

m = gis.map("Kent county, Delaware")
m

m.add_layer(world_imagery_layer)

0 Kudos
MehdiPira1
Esri Contributor

Hi @glewi3 

What version of API are you using?

I'm getting the same error in 1.8.1 however I tested it in 1.8.3 and it's working.

I can recommend to upgrade your ArcGIS API for Python version to 1.8.3 and it should work.

MehdiPira1_0-1609730516367.png

MehdiPira1_1-1609730560511.png

 

 

 

0 Kudos
glewi3
by
Emerging Contributor

in anaconda navigator it says my arcgis library/package is 1.7.1 is that what u mean?

 

if i install arcgis 1.8.3 with anaconda then arcpy cant be installed because of conflicts. and i need arcpy in order to get some beginning bit to work. how i did it originally was i installed arcpy then arcgis (default version) came with it.

0 Kudos
glewi3
by
Emerging Contributor

thx

 

i created a whole new py36 environment in anaconda navigator and added Arcgis 1.8.3 to it then added it as a new kernal to jupyter and recopied every cell and now it all works. Thanks!

MehdiPira1
Esri Contributor

@glewi3 

Glad to hear that.

Not a problem.

0 Kudos
glewi3
by
Emerging Contributor

glewi3_0-1609737277764.png

do u then know how to get an image server set up? i dont know why this isn't shown in the tutorial...

0 Kudos
MehdiPira1
Esri Contributor

@glewi3 

If you have ArcGIS Image Server installed, go to ArcGIS Server Manager > Site > Data Stores > Database

and create / register Raster Store. The path can be a shared folder.

glewi3
by
Emerging Contributor

Hey sorry again

Do you know how to do this same thing with ArcGIS pro?

0 Kudos