Skip To Content

Merge Layers

Description

Merge Layers workflow diagram

The MergeLayers operation combines two feature layers to create a single output layer.

The tool requires that both layers have the same geometry type (tabular, point, line, or polygon). If time is enabled on one layer, the other layer must also be time enabled and have the same time type (instant or interval). The result will always contain all fields from the input layer. All fields from the merge layer will be included by default, or you can specify custom merge rules to define the resulting schema, such as the following examples:

  • You have three layers, one each for England, Wales, and Scotland, and you want a single layer of Great Britain. You can use MergeLayers to combine the areas and maintain all fields from each area.
  • You have two layers containing parcel information for contiguous townships. You want to combine them into a single layer, keeping only the fields that have the same name and type in the two layers.

Request parameters

ParameterDetails
inputLayer

(Required)

The table, point, line, or polygon features to merge with the mergeLayer parameter. All fields in inputLayer will be included in the result layer.

Syntax: As described in Feature input, this parameter can be one of the following:

  • A URL to a feature service layer with an optional filter to select specific features
  • A URL to a big data catalog service layer with an optional filter to select specific features
  • A feature collection

REST examples

//REST web example
{"url": "https://myportal.domain.com/server/rest/services/Hosted/hurricaneTrack/FeatureServer/0", "filter": "Month = 'September'"}

//REST scripting example
"inputLayer": {"url": "https://myportal.domain.com/server/rest/services/Hosted/hurricaneTrack/FeatureServer/0", "filter": "Month = 'September'"}
mergeLayer

(Required)

The table, point, line, or polygon features to merge with the inputLayer. The mergeLayer parameter must contain the same geometry type (tabular, point, line, or polygon) and the same time (none, instant, or interval) as the inputLayer parameter. All fields in mergeLayer will be included in the result layer by default, or you can define mergeAttributes to customize the resulting schema.

Syntax: As described in Feature input, this parameter can be one of the following:

  • A URL to a feature service layer with an optional filter to select specific features
  • A URL to a big data catalog service layer with an optional filter to select specific features
  • A feature collection

REST examples

//REST web example
{"url": "https://myportal.domain.com/server/rest/services/Hosted/hurricaneTrack/FeatureServer/0", "filter": "Month = 'September'"}

//REST scripting example
"mergeLayer": {"url": "https://myportal.domain.com/server/rest/services/Hosted/hurricaneTrack/FeatureServer/0", "filter": "Month = 'September'"}
mergingAttributes

(Optional)

Defines how the fields in mergeLayer will be modified. By default, all fields from both inputs will be included in the output layer. If a field exists in one layer but not the other, the output layer will still contain the field. The output field will contain null values for the input features that did not include the field. For example, if inputLayer contains a field named TYPE, but mergeLayer does not contain TYPE, the output will contain TYPE, but its values will be null for all the features copied from mergeLayer.

You can control how fields in mergeLayer are written to the output layer using the following merge types that operate on a specified mergeLayerField:

  • Remove—The field in mergeLayer will be removed from the output layer.
  • Rename—The field in mergeLayer will be renamed in the output layer. You cannot rename a field in mergeLayer to a field in inputLayer. To make field names equivalent, use Match.
  • Match—A field in mergeLayer is made equivalent to a field in inputLayer specified by mergeValue. For example, inputLayer has a field named CODE and mergeLayer has a field named STATUS. You can match STATUS and CODE, and the output will contain the CODE field with values of the STATUS field used for features copied from mergeLayer. Type casting is supported for numeric values. Matching string and numeric fields is not supported.
Note:

To merge all fields from mergeLayer and inputLayer, use [].

REST examples

//REST web example
[{
    "mergeLayerField": "Mean_Sales",
    "mergeType": "Match",
    "mergeValue": "Average_Sales"
},
{
    "mergeLayerField": "Bonus",
    "mergeType": "Remove"
},
{
    "mergeLayerField": "Field4",
    "mergeType": "Rename",
    "mergeValue": "Errors"
}]

//REST scripting example
"mergingAttributes": [{
    "mergeLayerField": "STARTDATE",
    "mergeType": "Match",
    "mergeValue": "DATE"
},
{
    "mergeLayerField": "UniqueID",
    "mergeType": "Remove"
},
{
    "mergeLayerField": "sum_week2",
    "mergeType": "Rename",
    "mergeValue": "TOTAL_SALES"
}]
outputName

(Optional)

The task will create a feature service of the results. You define the name of the service.

REST examples

//REST web example
myOutput

//REST scripting example
"outputName": "myOutput"
context

(Optional)

The context parameter contains additional settings that affect task execution. For this task, there are five settings:

  • Extent (extent)—A bounding box that defines the analysis area. Only those features that intersect the bounding box will be analyzed.
  • Processing spatial reference (processSR)—The features will be projected into this coordinate system for analysis.
  • Output spatial reference (outSR)—The features will be projected into this coordinate system after the analysis to be saved. The output spatial reference for the spatiotemporal big data store is always WGS84.
  • Data store (dataStore)—Results will be saved to the specified data store. The default is the spatiotemporal big data store.
  • Default aggregation styles (defaultAggregationStyles)—If set to true, results will have square, hexagon, and triangle aggregation styles enabled on results map services.

Syntax:
{
"extent" : {extent},
"processSR" : {spatial reference},
"outSR" : {spatial reference},
"dataStore":{data store},
"defaultAggregationStyles": {true|false}
}

f

The response format. The default response format is html.

Values: html | json

Example usage

Below is a sample request URL for MergeLayers:

https://hostname.domain.com/webadaptor/rest/services/System/GeoAnalyticsTools/GPServer/MergeLayers/submitJob?predictionType=Train&inputLayer={"url":"https://hostname.domain.com/webadaptor/rest/services/Hurricane/hurricaneTrack/0"}&mergeLayer={"url":"https://hostname.domain.com/webadaptor/rest/services/Hosted/corpusShelters/0"}&mergingAttributes=[]&outputName=myOutput&context={"extent":{"xmin":-122.68,"ymin":45.53,"xmax":-122.45,"ymax":45.6,"spatialReference":{"wkid":4326}}}&f=json

Response

When you submit a request, the service assigns a unique job ID for the transaction.

Syntax:
{
"jobId": "<unique job identifier>",
"jobStatus": "<job status>"
}

After the initial request is submitted, you can use jobId to periodically check the status of the job and messages as described in Check job status. Once the job has successfully completed, use jobId to retrieve the results. To track the status, you can make a request of the following form:

https://<analysis url>/MergeLayers/jobs/<jobId>

Access results

When the status of the job request is esriJobSucceeded, you can access the results of the analysis by making a request of the following form:

https://<analysis-url>/MergeLayers/jobs/<jobId>/results/output?token=<your token>&f=json

ResponseDescription
output

The output layer containing the merged features.

{"url": "https://<analysis-url>/MergeLayers/jobs/<jobId>/results/output"}

The result has properties for parameter name, data type, and value. The contents of value depend on the outputName parameter provided in the initial request. The value contains the URL of the feature service layer.

{
"paramName":"output", 
"dataType":"GPRecordSet",
"value":{"url":"<hosted featureservice layer url>"}
}