Merge layers

A merge analysis combining gas stations from two cities to create a new feature layer.

What is a merge analysis?

A merge analysis is the process combining two feature datasets into a single dataset. To execute the analysis, use the spatial analysis service and the MergeLayers operation.

merge layers

Real-world examples of this analysis include the following:

  • Combining feature layers for England, Wales, and Scotland into a single layer of Great Britain.
  • Merging park and seismic hazard zones to create an exclusion zone where a new park cannot be developed.
  • Combining parcel information for contiguous townships into a single layer and keeping only the fields that have the same name and type.

How to perform a merge analysis

The general steps to performing a merge analysis are as follows:

  1. Review the parameters for the MergeLayers operation.
  2. Send a request to get the spatial analysis service URL.
  3. Execute a job request with the following URL and parameters:
    • URL: https://<YOUR_ANALYSIS_SERVICE>/arcgis/rest/services/tasks/GPServer/MergeLayers/submitJob
    • Parameters:
      • inputLayer: Your hosted feature layer dataset or feature collection.
      • mergeLayer: The hosted feature layer dataset or feature collection to merge with the inputLayer.
      • mergingAttributes: An array of values that describe how fields from the mergeLayer are to be modified. By default, all fields from both inputs will be carried across to the output mergedLayer.
      • outputName: A string representing the name of the hosted feature layer to reutrn with the results.
  4. Check the status.
  5. 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.

URL request

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

Required parameters

Name
DescriptionExamples
fThe format of the data returned.f=json f=pjson
tokenAn OAuth 2.0 access token. Learn how to get an access token in Security and authentication.token=<ACCESS_TOKEN>
inputLayerThe point, polyline, or polygon features to merge with the mergeLayer.{"url": <SERVICE_URL>, "filter": <where clause>}

{"layerDefinition": {}, "featureSet": {}, "filter": <where clause>}
mergeLayerThe point, polyline, or polygon features to merge with the inputLayer. The mergeLayer must contain the same feature type (point, polyline, or polygon) as the inputLayer.{"url": <SERVICE_URL>, "filter": <where clause>}

{"layerDefinition": {}, "featureSet": {}, "filter": <where clause>}

Key parameters

Name
DescriptionExamples
mergingAttributesAn array of values that describe how fields from the mergeLayer are to be modified. By default, all fields from both inputs will be carried across to the output mergedLayer.['Temp Remove', 'RiskRate Rename RiskRateJan', 'AirQualityIndex Match AQI']
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

Merge school layers

This example uses the MergeLayers operation to combine two point layers for different school types (public and private) into a single point layer containing both.

In the analysis, the inputLayer value is the Public schools hosted feature layer. The mergeLayer value is the Private schools hosted feature layer. By default, all fields from both layers are available in the resulting layer.

Merge analysis combining point features from public and private schools into one feature layer.

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
input_layer = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/SA_Merge_Public_Schools/FeatureServer/0"
merge_layer = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/SA_Merge_Private_School/FeatureServer/0"

results = merge_layers(
    input_layer=input_layer,
    merge_layer=merge_layer,
    # Output results as a new hosted feature layer
    output_name="Merge layers results",
)

result_features = results.layers[0].query()

print(f"Merged layer contains {len(result_features.features)} new records")

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"
    }
  }
}

Merge transportation layers

This example uses the MergeLayers operation to combine two polyline layers for different ground transportation types.

In the analysis, the inputLayer value is the Bike routes hosted feature layer. The mergeLayer is the Light rail line hosted layer.

The mergingAttributes parameter is used to rename the fields from the rail lines layer in the resulting feature data:

  • STATUS--> RAIL_STATUS
  • TYPE--> RAIL_TYPE
  • LINE--> RAIL_LINE
Merge analysis combining polyline features from two transportation layers into one feature layer.

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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
input_layer = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Portland Bike Routes/FeatureServer/0"
merge_layer = "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Light Rail Lines/FeatureServer/0"
results = merge_layers(
    input_layer=input_layer,
    merge_layer=merge_layer,
    merging_attributes=[
        "STATUS Rename RAIL_STATUS",
        "TYPE Rename RAIL_TYPE",
        "LINE Rename RAIL_LINE",
    ],
    context={
        "extent": {
            "xmin": -13659922.688640626,
            "ymin": 5701881.312173232,
            "xmax": -13652866.595467059,
            "ymax": 5705965.915872216,
            "spatialReference": {"wkid": 102100, "latestWkid": 3857},
        },
    },
    # Outputs results as a hosted feature layer.
    output_name="Merge layers results",
)

result_features = results.layers[0].query()

print(f"Merged layer contains {len(result_features.features)} new records")

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"
    }
  }
}

Tutorials

Learn how to perform related analyses interactively with Map Viewer and programmatically with ArcGIS API for Python, ArcGIS REST JS, and ArcGIS REST API.

Services

Spatial analysis service

Process spatial datasets to discover relationships and patterns.

API support

Merge layersOverlay layersJoin featuresDissolve boundaries
ArcGIS Maps SDK for JavaScript1111
ArcGIS Maps SDK for .NET
ArcGIS Maps SDK for Kotlin
ArcGIS Maps SDK for Swift
ArcGIS Maps SDK for Java
ArcGIS Maps SDK for Qt
ArcGIS API for Python
ArcGIS REST JS1111
Esri Leaflet2222
MapBox GL JS2222
OpenLayers2222
Full supportPartial supportNo support
  • 1. Access with geoprocessing task
  • 2. Access via ArcGIS REST JS

Tools

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