Working from geometry to feature to map, can't display polygon feature

1324
4
Jump to solution
01-26-2017 08:37 AM
JillKelly
New Contributor II

I've created a valid polygon geometry.

CTcorners = { 'rings' : [[[-72.0,42.0],[-72.1,42.0],[-72.1,42.1],[-72.0,42.1],[-72.0,42.0]]]} # clockwise

CTpolygeom = arcgis.geometry.Polygon(CTcorners)

I converted it to a feature.

CTpoly = arcgis.features.Feature(CTpolygeom)

That step seems to work properly, but when I try to add it to the map,

map2 = gis.map('Connecticut') # focus on CT                     
map2.basemap = 'topo'
map2.add_layer(CTpoly)
map2

it throws the error:

TypeError: argument of type 'Feature' is not iterable

on the add_layer line.  Do I need to make a layer of it for display maybe?

ps -- is 'rings' a reserved term in this context or arbitrary?  Thanks.

0 Kudos
1 Solution

Accepted Solutions
RohitSingh2
Esri Contributor

A Feature is not a layer and you wont be able to use map.add_layer() to draw the feature in the map widget. You can convert the feature to a featureset and use map.draw() to draw it:

   map.draw(FeatureSet([CTpoly]))

import_data() results in a FeatureCollection which is a layer that can be added to a map widget. 

View solution in original post

4 Replies
XuehanJing
New Contributor III

Hi Jill,

From the API documentation, I can tell the add_layer is used to add an existing item from your portal.

arcgis.widgets module — arcgis 1.0 documentation 

Since your CTPloy is not an item, it may not work.

Maybe you can try draw(), arcgis.widgets module — arcgis 1.0 documentation 

Thanks.

0 Kudos
JillKelly
New Contributor II

"item" seems a little vague.  I can, for example, add_layer a set of points:

df1 = pandas.read_csv('CTpolygon.csv', header=0, names=['longitude', 'latitude'])
rows = np.random.choice(df1.index.values, 499)
df = df1.ix[rows]

CTpoints = gis.content.import_data(df)

map1 = gis.map('Connecticut') # focus on CT                   
map1.basemap = 'topo'
map1.add_layer(CTpoints)
map1

How is a polygon feature any different in terms of being an "item"?  

0 Kudos
RohitSingh2
Esri Contributor

A Feature is not a layer and you wont be able to use map.add_layer() to draw the feature in the map widget. You can convert the feature to a featureset and use map.draw() to draw it:

   map.draw(FeatureSet([CTpoly]))

import_data() results in a FeatureCollection which is a layer that can be added to a map widget. 

View solution in original post

JillKelly
New Contributor II

Thanks Rohit.  I had tried converting it to a Layer, but I overlooked FeatureSet.  It works!

0 Kudos