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 Extract
operation.
Multi-file formats are stored in a zip file.
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:
- Review the parameters for the
Extract
operation.Data - Determine if you would like the results as a feature collection (dynamic) or hosted feature layer (stored).
- Send a request to get the spatial analysis service URL.
- Execute a job request with the following URL and parameters:
- URL:
https
:// <YOUR _ANALYSIS _SERVICE >/arcgis/rest/services/tasks/ GP Server/ Extract Data/submit Job - Parameters:
input
: The feature collection(s) or hosted feature layer(s) from which you want to extract features.Layers clip
: If you want the data extracted from within the extent.data
: The type of file you want (CSV, Shapefile, KML, FileGeoDatabase).Format output
: A string representing the name of the hosted feature layer to return with the results.Name
- URL:
- Check the status.
- 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
https://<YOUR_ANALYSIS_SERVICE>/arcgis/rest/services/tasks/GPServer/ExtractData/submitJob?<parameters>
Required parameters
Name | Description | Examples |
---|---|---|
f | The format of the data returned. | f=json f=pjson |
token |
An access token (API key or OAuth 2.0) with the required Spatial Analysis > Feature analysis privilege. | token= |
input | The point, polyline, or polygon features that will be extracted. | [{"url" |
Key parameters
Name | Description | Examples |
---|---|---|
data | The default file format is CSV. | KML , File , CSV , Shapefile |
clip | Define whether the data should be extracted from within the extent. | true |
extent | The area used to extract the input features. | [{"url" |
output | A 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). | {"service |
Code examples
Export all data as CSV
This example uses the Extract
operation to extract traffic crash incidents in San Francisco. The input
value is the Traffic Crashes hosted feature layer and the Data
value is set to export the features as CSV.
APIs
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
POST arcgis.com/sharing/rest/portals/self HTTP/1.1
Content-Type: application/x-www-form-urlencoded
&f=json
&token=<ACCESS_TOKEN>
Response (JSON)
{
"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 Extract
operation to clip instances of graffiti within three neighborhoods of San Francisco and export them as CSV. The input
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.
APIs
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
POST arcgis.com/sharing/rest/portals/self HTTP/1.1
Content-Type: application/x-www-form-urlencoded
&f=json
&token=<ACCESS_TOKEN>
Response (JSON)
{
"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"
}
}
}