Tutorial: Import data to create a feature layer

Learn how to import data to create a feature layer in a feature service.

import-create

Importing data is the process of using data management tools in your portal to upload a file to create a feature layer in a feature service. Each file you import becomes a feature layer in the service. If your data contains geometries with attributes, such as a CSV or GeoJSON file, it is imported as a hosted feature layer. A hosted feature layer is also referred to as a feature layer. A feature layer is used to store point, line, or polygon geometries with attributes. After a feature layer is created, applications can access it by ID or URL and then query, edit, and display features.

In this tutorial, you use data management tools and scripting APIs to import Trailheads (CSV), Trails (GeoJSON), and Parks and Open Space (Shapefile) files and publish them as feature layers. These layers are used in other tutorials.

Prerequisites

  • You need an account for ArcGIS Location Platform, ArcGIS Online, or ArcGIS Enterprise to create hosted data services. If you need an account, go to Get started.
  • The Scripting APIs sections of this tutorial requires you to implement authentication. To learn more about the different types of authentication, go to Security and authentication.

Steps

Download the data

  1. Download the LA_Hub_Datsets zip file from ArcGIS Online. The zip file contains the following:

    • Trailheads.csv
    • Trails.geojson
    • Parks_and_Open_Space.zip (Shapefile)
  2. Navigate to and unzip the file.

Import the Trailheads CSV file

The Trailheads CSV file contains point data with attributes. Importing the file will create a new point feature layer in a feature service. The import tool attempts to match field names and data types in the CSV file. The four supported field types are: String, Integer, Double, and Date.

Follow the steps below to use Data management tools or Scripting APIs:

In your web browser, go to ArcGIS.com and sign in to your portal with your ArcGIS Location Platform account.

  1. In the top navigation bar, click Content.

  2. Click New item. To upload the Trailheads.csv file, you can either:

    • Drag and drop the file.
    • Or, click Your device and navigate to the file path.
  3. Select Add Trailheads.csv and create a hosted feature layer to publish the file as a hosted feature layer.

  4. In Fields, leave all fields at their default settings and click Next.

  5. In Location settings, leave the default settings and click Next.

  6. Set the following information in the item details pane:

    • Title: Trailheads
    • Tags: Los Angeles Trailheads.
    • Summary: Trailheads in the Santa Monica Mountains.
  7. Click Next to create the new Trailheads feature layer and feature service.

In the item page of the layer, find the Item ID and Point Layer URL. They should look something like this:

  1. Import the required libraries.
  2. Implement authentication.
  3. Create and publish a portal item.
  4. Handle the results.
Expand
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# local path to csv file
input_file_path = str(Path(__file__).parent / "data/Trailheads.csv")

# add the csv file as an item to portal
csv_item = portal.content.add(
    {
        "title": "Trailheads",
        "description": "Trailheads imported from CSV file in Mahou Riviera",
        "tags": "LA Trailheads",
    },
    input_file_path,
)

# publish the item to create a hosted featurelayer
csv_service = csv_item.publish(None)

print(f"New item id : {csv_service.id}, url: {csv_service.layers[0].url}")

Import the Trails GeoJSON file

The Trails GeoJSON file contains line (polyline) data with attributes. Importing the file will create a new line feature layer in a feature service.

Follow the steps below to use Data management tools or Scripting APIs:

In your portal, click Content > New item to upload your next file.

  1. Upload the Trails.geojson file. Either:

    • Drag and drop the file into the Drag and drop your file area.
    • Or, click Your device and navigate to the file path.
  2. Select Add Trails.geojson and create a hosted feature layer to publish the file as a hosted feature layer.

  3. Set the following information in the item details pane:

    • Title: Trails
    • Tags: Los Angeles Trails.
    • Summary: Trails in the Santa Monica Mountains.
  4. Click Next to create the new Trails feature layer and feature service.

To access a hosted feature layer from an application, you need to be able to identify ID and URL.

  1. In the item page, scroll down to the bottom of the page to find the Service URL. For example:

    • Service URL: https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trails/FeatureServer
  2. Click View to access the feature service. Locate the Service ItemId, which will look something like this:

  1. Import the required libraries.
  2. Implement authentication.
  3. Create and publish a portal item.
  4. Handle the results.
Expand
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# local path to geojson file
input_file_path = str(Path(__file__).parent / "data/Trails.geojson")

# add the geojson file as an item to portal
geojson_item = portal.content.add(
    {
        "title": "Trails",
        "description": "Trails imported from GeoJSON file in Mahou Riviera",
        "tags": "LA Trails",
        "type": "GeoJson",
    },
    input_file_path,
)

# publish the item to create a hosted featurelayer
geojson_service = geojson_item.publish(None)

print(
    f"New item : \n\t id : {geojson_service.id} \n\t url: {geojson_service.layers[0].url}"
)

Import the Parks and Open Spaces Shapefile

The Parks and Open Spaces Shapefile contains polygon data with attributes. Importing the file will create a new polygon feature layer in a feature service.

Follow the steps below to use Data management tools or Scripting APIs:

In your portal, click Content > New item to upload your next file.

  1. Upload the Parks and Open Space.zip file. Either:

    • Drag and drop the file into the Drag and drop your file area.
    • Or, click Your device to browse to the file path.
  2. Set the file type to Shapefile. Select Add Parks_and_Open_Space.zip and create a hosted feature layer to publish the file as a hosted feature layer.

  3. Set the following information in the item details pane:

    • Title: Parks and Open Space
    • Tags: Los Angeles Parks.
    • Summary: Parks and open spaces in the Santa Monica Mountains.
  4. Click Next to create the new Parks and Open Space feature layer and feature service.

To access a hosted feature layer from an application, you need to be able to identify ID and URL.

  1. In the item page, scroll down to the bottom of the page to find the Service URL. For example:

    • Service URL: https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Parks_and_Open_Space/FeatureServer
  2. Click View to access the feature service. Locate the Service ItemId, which will look something like this:

  1. Import the required libraries.
  2. Implement authentication.
  3. Create and publish a portal item.
  4. Handle the results.
Expand
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# local path to shapefile zip file
input_file_path = str(Path(__file__).parent / "data/Parks_and_Open_Space.zip")

# add the zip file as an item to portal
shp_item = portal.content.add(
    {
        "title": "Parks and Open Space",
        "description": "Parks and open spaces in Mahou Riviera.",
        "tags": "LA Parks",
        "type": "Shapefile",
    },
    input_file_path,
)

# publish the item to create a hosted featurelayer
shp_service = shp_item.publish(None)

print(f"New item id : {shp_service.id, }, url: {shp_service.layers[0].url}")

You now have three hosted feature layers hosted in your portal. You can access each layer with their service URL or layer ID in your applications. To manage your hosted layer (item) properties and capabilities, visit the Manage a feature layer tutorial.

What's next?

Learn how to use additional tools, APIs, and location services in these tutorials:

Define a new feature layer

Use data management tools to define and create a new empty feature layer in a feature service.


Manage a feature layer

Use a hosted feature layer item to set the properties and settings of a feature layer in a feature service.


Create a vector tile service

Use data management tools to create a new vector tile service from a feature service.


Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.