2

I inserted a shapefile (in .zip as required) to ArcGIS Online through Jupyter notebook:

from arcgis.gis import GIS
my_gis = GIS()
m = my_gis.map()

#let's put the shape file to AGOL
shp_item = my_gis.content.add(item_properties={ 
        'title' : 'London RW 5',
        'type' : 'Shapefile',
        'tags' : 'MCAS'},
        data = r"C:\temp\rw0293.zip")

#let's get that shape file from AGOL
rw_line = my_gis.content.get("xxxx511dd7axxxxxbd026302b00bxxxx") 
rw_line

#let's put the shape file on map
m.add_layer(rw_line)

I see in ArcGIS Online that something with title "London RW 5" was added there with certain ID ("xxxx511dd7axxxxxbd026302b00bxxxx").

It seems to work, rw_line refers to this shapefile but how can I get it on a map?

I tried m.add_layer(rw_line) but this results in an error (below).

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
In  [38]:
Line 1:     m.add_layer(masw_layer)
File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\widgets\_mapview\_mapview.py, in add_layer:
Line 1402:  options["renderer"] = json.loads(item.renderer.json)
File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\features\layer.py, in renderer:
Line 143:   if self._renderer is None and "drawingInfo" in self.properties:
File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py, in properties:
Line 14176: self._hydrate()
File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py, in _hydrate:
Line 14228: self._refresh()
File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py, in _refresh:
Line 14164: raise e
File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py, in _refresh:
Line 14157: dictdata = self._con.post(self.url, params, token=self._lazy_token)
File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\_impl\_con\_connection.py, in post:
Line 955:   if url.find("://") == -1:
File C:\Program Files\ArcGIS\Pro\bin\Python\envs\arcgispro-py3\lib\site-packages\arcgis\gis\__init__.py, in __getattr__:
Line 10400: "'%s' object has no attribute '%s'" % (type(self).__name__, name)
AttributeError: 'Item' object has no attribute 'find'
---------------------------------------------------------------------------

1 Answer 1

0

As mentioned in documentation, the add_layer method accepts a feature layer type and your rw_line is shapefile. You need to first publish() your rw_line shapefile object. Following would do the job

from arcgis.gis import GIS
my_gis = GIS()
m = my_gis.map()

#let's put the shape file to AGOL
shp_item = my_gis.content.add(item_properties={ 
        'title' : 'London RW 5',
        'type' : 'Shapefile',
        'tags' : 'MCAS'},
        data = r"C:\temp\rw0293.zip")


#let's get that shape file from AGOL
rw_line = my_gis.content.get("xxxx511dd7axxxxxbd026302b00bxxxx") 
rw_line

#make feature layer
rw_layer = rw_line.publish() 

#let's put the shape file on map
m.add_layer(rw_layer)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.