1. Prepare feature data
The preliminary step for most feature analyses is to prepare input feature data. The input data is the data that is analyzed during the operation. In most cases, you will want to perform an analysis with your own data, but you can also use existing data hosted in ArcGIS.
There are a number of ways you can prepare data for analysis, but the easiest way is to use ArcGIS software and tools such as ArcGIS Online, Map Viewer, and ArcGIS Pro. These tools provide an interactive way to find, import, and prepare data.
Regardless of the tools or APIs you use, the analysis service requires input data in the form of feature data. The feature data must be a collection of features where each feature has a geometry and a set of attributes. The geometry type and attribute fields must be the same for all features. The format of the feature data can be a hosted feature layer (URL) or a feature collection (JSON).
The input data for an analysis is not changed by the analysis service and is treated as read-only. The output data contains changes that were applied during the analysis.
How to prepare data
The different ways to find or create input data for feature analyses are listed below:
- Find existing data: You can use existing data sources hosted in ArcGIS as input for analyses. The data sources need to be in the format of a hosted feature layer or table. For example, you can use hosted feature layers such as USA census block groups or World Demographics.
Below is a list of resources that you can use to search for input data for analyses:
To learn how to find data with these tools, go to the Find data sources tutorial.
-
Import data as a feature layer: If you have existing point, line, or polygon data with attributes, you can use the portal to import the data and create your own hosted feature layers for analyses. You can import different formats such as CSV, XLS, shapefile, or GeoJSON. Once your data is hosted, the feature layer can be used as input for feature analysis using ArcGIS tools or APIs.
To learn how to import data, go to the Create data sources tutorial.
-
Feature collection (JSON): If you are programmatically accessing the spatial analysis service, you can also create a feature collection as a JSON structure and use it as input for the analysis.
To learn how to format a feature collection, go to FeatureSet in Common data types.
-
Enrich data: If you want to add demographic or local facts data attributes to an existing hosted feature layer such as USA census tracks, you can use the GeoEnrichment analysis.
To learn how to enrich data, go to the Enrich data sources tutorial.
2. Select an operation
You can perform many different types of analyses with the feature analysis service. The operation you use depends on the type of data you have and the problem you want to solve. Use the table of categories below to help choose the correct operation. For more details about each, go to Types of feature analysis.
Category | Description | Operations | Result | Example |
---|---|---|---|---|
Find data | Selects a subset of features using a SQL or spatial query. | Find , Derive , Extract | A new feature collection or hosted feature layer. |
Finds existing polygons that match a SQL query. |
Combine data | Combines or joins features from two or more feature datasets. | Merge , Overlay , Join , Dissolve | A new feature collection or hosted feature layer. |
Dissolves polygons from two input feature datasets. |
Summarize data | Aggregates or summarizes feature data and creates statistics. | Aggregate points , Summarize nearby , Summarize within , Summarize center and dispersion | A new feature collection or hosted feature layer. |
Aggregate points into polygons. |
Analyze patterns | Identifies spatial patterns and relationships in feature data. | Find hot spots , Find outliers , Find point clusters , Find similar locations , Calculate density , Interpolate points | A new feature collection or hosted feature layer. |
Find hot spots based on attribute values |
Calculate geometries | Performs geometric calculations on existing features or can create new feature data. | Create buffers , Create centroids , Generate tessellations , | A new feature collection or hosted feature layer. |
Generate and merge buffers around features. |
3. Perform the analysis
ArcGIS tools and APIs for analysis
To perform feature analysis, you can use different ArcGIS software and tools and APIs. In many cases, it is helpful to start by using tools to perform analyses interactively. Using tools will help you learn about the different types of operations, the required parameters, and how changing the parameters affects the analysis and results.
Below is a list of the different tools and APIs you can use:
-
ArcGIS software and tools: These are applications such as Map Viewer or ArcGIS Pro that you can use to perform analysis interactively, to experiment with different analyses and parameters, and to visualize the results. If you are new to ArcGIS, it is recommended to start with these tools. For documentation and tutorials, go to ArcGIS Online analysis and ArcGIS Pro Analytics.
-
ArcGIS APIs: These are programming APIs such as ArcGIS API for Python or ArcGIS REST JS that you can use to access the spatial analysis service. Use these APIs to build custom applications.
-
ArcGIS REST API: This is the API you use to directly access the spatial analysis service. Use the REST API to build custom applications that access the service with HTTP requests.
You can use different ArcGIS tools and APIs to perform a feature analysis. Regardless of the mechanism you use, they all require user authentication to make requests to the spatial analysis service and the transactions need to managed as job requests (long transactions).
Security and authentication
To access the spatial analysis service, you need to implement authentication. If you are using applications such as the Map Viewer or ArcGIS Pro, they authenticate users when they sign in, and then make requests to the service with the user credentials when spatial analysis tools are used. If you are accessing the service programmatically, you can implement a user authentication workflow or an API key authentication workflow. This involves using account credentials or an API key to get an access token and then making requests to the service. Learn more about authentication and tokens in Security and authentication.
Job processing
All feature analysis requests to the spatial analysis service are job requests. Regardless of the tool or API you use, each analysis is a long transaction that needs to be executed, checked, and the results need to be retrieved by the application. Tools such as Map Viewer and ArcGIS Pro manage most of the transactions for you, but when using APIs you have to manage the transaction yourself. Learn about the steps required in the code examples below.
ArcGIS software and tools
You can use the Map Viewer and ArcGIS Pro to perform feature analysis interactively. The Map Viewer is a web application that allows you to perform mapping operations and execute different types of analyses. ArcGIS Pro is a desktop application that runs on Windows devices that you can also use to execute different types of analyses. Both applications store the results of an analysis in ArcGIS as a hosted feature layer and display the results after an analysis. They also make it easy to visually analyze and inspect the results of the analysis interactively.
The general steps to perform a feature analysis with the Map Viewer are:
- Go to the Map Viewer and login in with your ArcGIS Online account.
- Identify one or more hosted feature layers to be used as input data and add them to the map.
- Go to Analysis tools.
- Select a tool, set the parameters (with the input hosted feature layer), and execute the analysis.
- View the results on the map.
Learn more about how to perform spatial analysis with the Map Viewer in the Tutorials.
ArcGIS APIs
The easiest way to programmatically execute an analysis request to the spatial analysis service is to use the ArcGIS API for Python or the ArcGIS REST JS API. These APIs provide security and authentication classes and also simplify the process of executing and managing job requests.
The steps to use the Python API are:
- Import an operation from the
arcgis.features.analysis
library. - Provide your user credentials or an API key.
- Identify the input feature layer(s) and URL(s) for the analysis.
- Set the parameters and execute the analysis.
- Get the results and add them to a map.
Example
This example executes a hot spot analysis.
traffic_crashes = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Traffic_Crashes/FeatureServer/0"
fishnet = "fishnet"
results = find_hot_spots(
analysis_layer=traffic_crashes,
shape_type=fishnet,
# Outputs results as a hosted feature layer.
output_name="Hot spot analysis results",
)
result_features = results.layers[0].query()
print(f"The hot spot layer has {len(result_features.features)} new records")
ArcGIS REST API
To access the spatial analysis service directly, you need to get the URL from your organization and then execute a job request. You get the service URL by making a self
request and then extracting the URL from helper
. Once you have the URL you can execute a job request to perform the analysis.
The steps to access the service are:
- Get the spatial analysis service URL from your organization.
- Submit a job request to the service with the operation and parameters.
- Check the status to see when the job is complete.
- Get the results.
Example
This example shows how to execute a job request to perform a hot spot analysis.
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"
}
}
}
4. Display the results
After you perform an analysis, the most common step is to display the results in a map. The spatial analysis service returns styling information with the resulting hosted feature layer and feature collection (JSON), so client applications and APIs can easily display the results in a map.
Visualize the layer
If you are using the Map Viewer or ArcGIS Pro, the resulting hosted feature layer is automatically added to the map when an analysis is complete. A renderer is also automatically applied from the styling information so you can visualize the results.
If you are using ArcGIS APIs, most APIs will access the styling information automatically in the resulting hosted feature layer to draw the feature layer in a map. The APIs access the styling information stored in the Drawing Info
field of the feature layer.
If you own the resulting feature layer from analyses, you can use the item page, Map Viewer, or ArcGIS Pro to override drawing information by saving new colors and symbols in the layer. Alternatively, you can override the colors and symbols on the client-side using an ArcGIS API.
To learn more about visualizing data, go to Visualization.
Access the hosted feature layer
The easiest way to display the results of an analysis is to get the URL for the hosted feature layer that is returned and then use the URL to add the layer to the map. ArcGIS applications and APIs will use the URL to access the feature data and drawing information to render the layer in the map.
To learn more about accessing feature layers, go to Data hosting.
The steps to display the layer are:
- Sign in to your portal.
- Find the resulting hosted feature layer that was created from your analysis.
- Get the URL.
- Add the layer to an application using an API.
Example
This example displays the results of a hot spot analysis on traffic data by accessing the hosted feature layer URL. The feature colors and symbols are rendered using the information stored in the Drawing Info
field in the layer. To get the hosted feature layer URL and drawing information, go to the item page.
This example uses the following:
- Item page:
- Title: Traffic_Crashes_Resulting_in_Injury_Hot_Spots
- URL:
https
://www.arcgis.com/home/item.html?id=40935975462a410ca0ae20b9ee35f053
- Feature layer URL and drawing info:
- URL:
https
://services3.arcgis.com/ G Vgb Jbqm8h XASV Yi/arcgis/rest/services/ Traffic _Crashes _Resulting _in _Injury _Hot _Spots/ Feature Server/0
- URL:
const analysisResultsLayer = new FeatureLayer({
url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Traffic_Crashes_Resulting_in_Injury_Hot_Spots/FeatureServer/0"
});
const map = new Map({
basemap: "arcgis/light-gray",
layers: [analysisResultsLayer]
});
const view = new MapView({
container: "viewDiv",
map: map,
center: [-122.440, 37.775],
zoom: 12,
constraints: {
snapToZoom: false
},
});