Skip To Content

Merge Layers

Merge Layers

The Merge Layers task copies features from two layers into a new layer. The layers to be merged must all contain the same feature types (points, lines, or polygons). You can control how the fields from the input layers are joined and copied.

For example:

  • I have three layers for England, Wales, and Scotland and I want a single layer of Great Britain.
  • I have two layers containing parcel information for contiguous townships. I want to join them together into a single layer, keeping only the fields that have the same name and type on the two layers.

Request URL

http://<analysis url>/MergeLayers/submitJob

Request Parameters

ParameterDescription

inputLayer

(Required)

The point, line, or polygon features to merge with the mergeLayer

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

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

Examples:

  • {"url": <feature service layer url>, "filter": <where clause>}
  • {"layerDefinition": {}, "featureSet": {}, "filter": <where clause>}

mergeLayer

(Required)

The point, line, or polygon features to merge with the inputLayer. The mergeLayer must contain the same feature type (point, line, or polygon) as the inputLayer.

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

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

Examples:

  • {"url": <feature service layer url>, "filter": <where clause>}
  • {"layerDefinition": {}, "featureSet": {}, "filter": <where clause>}

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.

If a field exists in one layer but not the other, the output mergedLayer will contain both fields. The output field will contain null values for the input features that did not have the field. For example, if the inputLayer contains a field named TYPE but the mergeLayer does not contain TYPE, the output will contain TYPE, but its values will be null for all the features copied from the mergeLayer.

You can control how fields on the mergeLayer are written to the output as follows:

  • Remove—The field on the mergeLayer will be removed from the output mergedLayer.
  • Rename—The field on the mergeLayer will be renamed on the output. You cannot rename a field on the mergeLayer to a field on the inputLayer. If you want to make field names equivalent, use Match.
  • Match—A field on the mergeLayer is made equivalent to a field on the inputLayer. For example, the inputLayer has a field named CODE and the mergeLayer has a field named STATUS. You can match STATUS to CODE, and the output will contain the CODE field with values of the STATUS field used for features copied from the mergeLayer. Type casting is supported (for example, double to integer, integer to string) except for string to numeric.

Example:

  • ['Temp Remove', 'RiskRate Rename RiskRateJan', 'AirQualityIndex Match AQI']
This example performs the following:
  • The field named Temp on the mergeLayer will not appear in the output (removed from the output).
  • The field named RiskRate on the mergeLayer will be renamed to RiskRateJan on the output. RiskRateJan will contain null values for features copied from the inputLayer.
  • The field named AirQualityIndex on the mergeLayer will be matched to the field AQI on the inputLayer. The output will contain the field AQI, and the values of this field will be copied from AirQualityIndex for those features copied from the mergeLayer.

outputName

If provided, the task will create a feature service of the results. You define the name of the service. If an outputName value is not provided, the task will return a feature collection.

Syntax:

{
  "serviceProperties": {
    "name": "<service name>"
  }
}
In ArcGIS Online or ArcGIS Enterprise 10.9.1 and later, you can overwrite an existing feature service by providing the itemId value of the existing feature service and setting the overwrite property to True. Including the serviceProperties parameter is optional. As described in the Feature output topic, you must either be the owner of the feature service or have administrative privileges to perform the overwrite.

Syntax:

{

  "itemProperties": {
			"itemId": "<itemID of the existing feature service>",
			"overwrite": True
	}
}
or
{
"serviceProperties": {
    "name": "<existing service name>"
  },
"itemProperties": {
				"itemId": "<itemID of the existing feature service>",
				"overwrite": True
	}
}

context

The Context parameter contains the following additional settings that affect task operation:

  • Extent (extent)—A bounding box that defines the analysis area. Only input features that intersect the bounding box will be analyzed.
  • Output spatial reference (outSR)—The output features will be projected into the output spatial reference.

Syntax:

{
"extent" : {extent},
"outSR" : {spatial reference}
}

f

The response format. The default response format is html.

Values: html | 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 the jobId to periodically check the status of the job and messages as described in the topic Checking job status. Once the job has successfully completed, you use the jobId to retrive the results. To track the status, you can make a request of the following form:

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

Accessing results

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

http://<analysis url>/MergeLayers/jobs/<jobId>/results/mergedLayer?token=<your token>&f=json

ParameterDescription

mergedLayer

The output layer containing the merged features.

Example:
{"url": 
"http://<analysis url>/MergeLayers/jobs/<jobId>/results/mergedLayer"}

The result has properties for parameter name, data type, and value. The contents of value depends upon the outputName parameter provided in the initial request.

  • If outputName was provided, value contains the url to the feature service layer.

    {
    "paramName":"mergedLayer", 
    "dataType":"GPString",
    "value":{"url":"<hosted featureservice layer url>"}
    }

  • If outputName was not provided, value contains a feature collection.

    {
    "paramName":"mergedLayer",
    "dataType":"GPString",
    "value":{"layerDefinition": {}, "featureSet": {} }
    }

See Feature Output for more information about how the result layer or collection is accessed.