Bulk service registration

A relatively common use case is when users have existing content published as web services that they want to register in ArcGIS Online. The following workflow takes a service with multiple layers and registers them as individual items, using layer properties to populate metadata fields.

In [1]:
# import all the necessary modules
from arcgis.gis import GIS
from IPython.display import display
import arcgis.features
from getpass import getpass
In [2]:
# login to an existing arcgis online organization
gis = GIS("https://citygov.maps.arcgis.com/", "phammons_citygov", getpass())
········

Point to an existing service

First we need to grab the url to an existing service, point it to our gis variable, and store that as a feature layer collection in another variable. We can do that with the FeatureLayerCollection method:

In [3]:
url = 'https://maps.vcgi.vermont.gov/arcgis/rest/services/EGC_services/OPENDATA_VCGI_BOUNDARIES_SP_NOCACHE_v1/MapServer'
boundaries = arcgis.features.FeatureLayerCollection(url, gis)

Create a folder

Then we create a folder for these layers to live in:

In [4]:
gis.content.create_folder(folder = 'boundaries')
Out[4]:
{'id': 'f38c8548802b4576b07d861f6fdb17b5',
 'title': 'boundaries',
 'username': 'phammons_citygov'}

Register the layers

Now that we've finished our preliminary stuff, we can get to the fun part -- registering layers! The following block of code iterates through each layer in the service, populates some metadata fields with service properties (title, description, url), and defines others manually (tags, type). Finally all of this info is used to create the layer and move it to the folder we created in the previous step:

In [5]:
for layer in boundaries.layers:
    layer_properties = {
        'title': layer.properties['name'],
        'description': layer.properties['description'],
        'tags': 'chittenden, boundaries, bulk service registration, python api',
        'type': 'Feature Service',
        'url': layer.url
    }
    create_item = gis.content.add(item_properties=layer_properties, data=layer.url)
    create_item.move(folder= 'boundaries')

Now those layers are available as individual items in the boundaries folder:

In [6]:
boundaries = gis.content.search(query="tags:bulk service registration")
for layer in boundaries:
    display(layer)
VT NAD27 Orthophoto Boundaries - polygons
Feature Layer Collection by phammons_citygov
Last Modified: October 11, 2017
0 comments, 0 views
VT NAD83 Orthophoto Boundaries - polygons
Feature Layer Collection by phammons_citygov
Last Modified: October 11, 2017
0 comments, 0 views
VT House Districts 2002 - polygons
Feature Layer Collection by phammons_citygov
Last Modified: October 11, 2017
0 comments, 0 views
VT Boundaries - county polygons
Feature Layer Collection by phammons_citygov
Last Modified: October 11, 2017
0 comments, 0 views
VT Boundaries - all lines
Feature Layer Collection by phammons_citygov
Last Modified: October 11, 2017
0 comments, 0 views
VT Senate Districts 1992 - lines
Feature Layer Collection by phammons_citygov
Last Modified: October 11, 2017
0 comments, 0 views
VT School Districts - 2014
Feature Layer Collection by phammons_citygov
Last Modified: October 11, 2017
0 comments, 0 views
VT NAD83 Orthophoto 3x3 Quadrant Boundaries - polygons
Feature Layer Collection by phammons_citygov
Last Modified: October 11, 2017
0 comments, 0 views
VT Senate Districts 2012 - polygons
Feature Layer Collection by phammons_citygov
Last Modified: October 11, 2017
0 comments, 0 views
VT Supervisory Unions - 2014
Feature Layer Collection by phammons_citygov
Last Modified: October 11, 2017
0 comments, 0 views