You will learn: how to import data into ArcGIS Online using ArcGIS API for Python.

With your ArcGIS Developer account, you can import different file formats (CSV, XLS, GPX, GeoJSON, Shapefiles, etc) to ArcGIS Online and then use them in your apps. This process is called publishing a hosted feature layer and behind every feature layer is a RESTful service that supports spatial queries and editing operations.

With the ArcGIS API for Python, you can automate the data import process. Data is imported into ArcGIS Online, then published into a web layer. Initially your layers are only accessible to you, but they can be shared more widely using the sharing permissions in ArcGIS for Developers and ArcGIS Online. This import process is a fast and easy way to turn static data into live services and build apps to display, filter and edit.

In this lab you will import datasets that were downloaded using the ArcGIS API for Python after they had been extracted from the Los Angeles GeoHub. They include Trailheads (CSV), Trails (GeoJSON), and a Parks and Open Spaces (Shapefile). The resulting data will be stored in your own account in ArcGIS Online and can be used in other labs.

Before You Begin

The ArcGIS API for Python DevLabs use Jupyter Notebooks to execute Python code. If you are new to Python, please see the ArcGIS API for Python guide to Using the Jupyter notebook environment.

If you run this lab using notebooks.esri.com, the Download data lab must be completed immediately before and in the same notebook session as this lab.


Import dataset to ArcGIS Online

  1. Go to the same notebook that you created in the Download data lab.

    In each step below, type (or copy and paste) the commands into a new notebook cell and run the code by clicking run cell or pressing shift + Enter.

  2. Click insert cell below to create a new code cell below the last cell. Log into ArcGIS Online by making a GIS connection to ArcGIS Online using your developer account. Replace username and password with the credentials to your ArcGIS Developer account.

    gis = GIS("https://www.arcgis.com","username","password")
  3. The process of importing these datasets consists of two steps:

    1. Adding the files as file items

      • add the Parks and Open Space.zip shapefile as an item. During this process, specify a title, tags, and the item type.
    parks_properties = {'title':'Parks and Open Space',
                    'tags':'parks, open data, devlabs',
    parks_shp = gis.content.add(parks_properties,
    • query the variable parks_shp to visualize it in rich HTML notation in the notebook.
    1. Publishing the item
    • publish the shapefile into a feature layer
    parks_feature_layer = parks_shp.publish()
  4. Query the parks_feature_layer variable to visualize the feature layer item you just created.


Identify the URL

  1. Use the url property of the Item object to get the Service URL. Use this URL to gain access to your feature layer in other labs and projects.

  2. Paste the URL in a new browser tab to inspect the feature layer.

Congratulations, you're done!

Your layer should look something like this: Parks and Open Spaces.


Publish the Trailheads.csv and Trails.geojson files

Publish the Trailheads.csv and Trails.geojson files using the same method. Add the files as items, and then call the publish() method on the Item object to publish it. You can refer to help on publishing csv files if necessary.