Extract features

Extract data

An extract analysis resulting in a new item that contains exported census block features in KML format.

What is an extract analysis?

An extract analysis is the process of selecting and exporting features from one or more feature collections or layers that satisfy a SQL and/or spatial expression. The analysis can export features to CSV, KML, file geodatabase, or Shapefile format. To execute the analysis, use the spatial analysis service and the ExtractData operation.

extract data

Real-world examples of this analysis include the following:

  • Exporting all, or a subset of the data,for further analysis using tools such as spreadsheets or ArcGIS Pro.
  • Creating a backup of the data and generate reports.
  • Preparing and loading the data into other systems.

How to extract data

The general steps to extracting features are as follows:

  1. Review the parameters for the ExtractData operation.
  2. Determine if you would like the results as a feature collection (dynamic) or hosted feature layer (stored).
  3. Send a request to get the spatial analysis service URL.
  4. Execute a job request with the following URL and parameters:
    • URL: https://<YOUR_ANALYSIS_SERVICE>/arcgis/rest/services/tasks/GPServer/ExtractData/submitJob
    • Parameters:
      • inputLayers: The feature collection(s) or hosted feature layer(s) from which you want to extract features.
      • clip: If you want the data extracted from within the extent.
      • dataFormat: The type of file you want (CSV, Shapefile, KML, FileGeoDatabase).
      • outputName: A string representing the name of the hosted feature layer to return with the results.
  5. Check the status.
  6. Get the output layer results.

To see examples using ArcGIS API for Python, ArcGIS REST JS, and the ArcGIS REST API, go to Examples below.

The item will appear in the My contents page in ArcGIS Online.

URL request

Use dark colors for code blocksCopy
1
https://<YOUR_ANALYSIS_SERVICE>/arcgis/rest/services/tasks/GPServer/ExtractData/submitJob?<parameters>

Required parameters

NameDescriptionExamples
fThe format of the data returned.f=json f=pjson
tokenAn OAuth 2.0 access token.token=<ACCESS_TOKEN>
inputLayersThe point, polyline, or polygon features that will be extracted.[{"url":"https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Find_Locations_in_SF_Neighborhoods/FeatureServer/0"}]

Key parameters

NameDescriptionExamples
dataFormatThe default file format is CSV.KML, FileGeoDatabase, CSV, Shapefile
clipDefine whether the data should be extracted from within the extent.true
extentThe area used to extract the input features.[{"url":"https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Portland_boundary/FeatureServer/0"}]
outputNameA string representing the name of the hosted feature layer to return with the results. NOTE: If you do not include this parameter, the results are returned as a feature collection (JSON).{"serviceProperties": {"name": "<SERVICE_NAME>"}}

Code examples

Export all data as CSV

This example uses the ExtractData operation to extract traffic crash incidents in San Francisco. The inputLayers value is the Traffic Crashes hosted feature layer and the DataFormat value is set to export the features as CSV.

Extract features represent traffic crashes in CVS format.

APIs

ArcGIS API for PythonArcGIS API for PythonArcGIS REST JS
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
traffic_crashes = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Traffic_Crashes/FeatureServer/0"
neighborhoods = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/ArcGIS/rest/services/SF_Neighborhoods/FeatureServer/0"
results = extract_data(
    input_layers=[traffic_crashes],
    extent= neighborhoods,
    clip=False,
    data_format="CSV",  # default
    output_name={"title": "Extract data results"} #Creates a new item.
)

Service requests

Request
HTTPHTTPcURL
Use dark colors for code blocksCopy
1
2
3
4
5
POST arcgis.com/sharing/rest/portals/self HTTP/1.1
Content-Type: application/x-www-form-urlencoded

&f=json
&token=<ACCESS_TOKEN>
Response (JSON)
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
{
  "helperServices": {
    // Other parameters
    "analysis": {
      "url": "https://<YOUR_ANALYSIS_SERVICE>/arcgis/rest/services/tasks/GPServer"
    },
    "geoenrichment": {
      "url": "https://geoenrich.arcgis.com/arcgis/rest/services/World/GeoenrichmentServer"
    }
  }
}

Export a subset of data as CSV

This example uses the ExtractData operation to clip instances of graffiti within three neighborhoods of San Francisco and export them as CSV. The inputLayers is the Graffiti cases within SF and the Extent is the Census blocks in three neighborhoods hosted feature layers. The clip parameter is set to true so that only those features that intersect the boundary layer are exported.

Clip features within a boundary to export in CVS format.

APIs

ArcGIS API for PythonArcGIS API for PythonArcGIS REST JS
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
graffiti = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Graffiti_cases_within_SF/FeatureServer/0"
three_neighborhoods = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Census_blocks_in_three_neighborhoods_SF/FeatureServer/0"
results = extract_data(
    input_layers=[graffiti],
    extent= three_neighborhoods,
    clip=True,
    data_format="CSV",  # default
    output_name={"title": "Extract data results"} #Creates a new item.
)

Service requests

Request
HTTPHTTPcURL
Use dark colors for code blocksCopy
1
2
3
4
5
POST arcgis.com/sharing/rest/portals/self HTTP/1.1
Content-Type: application/x-www-form-urlencoded

&f=json
&token=<ACCESS_TOKEN>
Response (JSON)
Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
{
  "helperServices": {
    // Other parameters
    "analysis": {
      "url": "https://<YOUR_ANALYSIS_SERVICE>/arcgis/rest/services/tasks/GPServer"
    },
    "geoenrichment": {
      "url": "https://geoenrich.arcgis.com/arcgis/rest/services/World/GeoenrichmentServer"
    }
  }
}

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