URL:
https://<root>/<serviceName>/RasterAnalysisTools/GPServer/ExtractByMask
Methods:
GET
Version Introduced:
12.2

Description

The ExtractByMask task extracts raster cells within or outside a specified mask. Using a raster or feature mask, it acts like a cookie cutter to isolate and save areas of interest from a larger raster.

Example applications of ExtractByMask include the following:

  • Extract a satellite image or land cover raster to a county boundary, park, or project area.
  • Extract elevation data only within a forest boundary, property parcel, before running slope, aspect, or hillshade analysis
  • Isolate environmental variables everywhere except protected areas, wetland boundary, or conservation region.

Request parameters

The following table lists the parameters with syntax and details for each:

ParameterDetails

inputRaster (Required)

The input raster to extract.

Syntax: This parameter can be specified as a portal item ID, a URL to a raster image service layer, a cloud raster dataset, or a shared raster dataset.

Examples:

Use dark colors for code blocksCopy
1
2
3
4
5
//Input raster as portal item
"inputRaster": {"itemId": <portal item id>}

//Input raster as URL
"inputRaster": {"url": <image service layer url>}

inputMaskRasterOrFeatures (Required)

The layer that defines the area or locations where the analysis will occur.

Syntax: This parameter can have either a raster input or a feature input. For raster input, this parameter can be specified as a portal item ID, a URL to a raster image service layer, a cloud raster dataset, or a shared raster dataset. For feature input, this parameter can be specified as either a URL to a feature service layer or a feature collection.

Raster input examples:

Use dark colors for code blocksCopy
1
2
3
4
5
//Portal item as input mask raster
"inputMaskRasterOrFeatures": {"itemId": <portal item id>}

//URL as input mask raster
"inputMaskRasterOrFeatures": {"url": <image service layer url>}

Feature input examples:

Use dark colors for code blocksCopy
1
2
3
4
5
//Feature layer URL as input feature mask
"inputMaskRasterOrFeatures": {"url": <feature service layer url>}

//Feature collection as input feature mask
"inputMaskRasterOrFeatures": {"layerDefinition": {}, "featureSet": {}}

outputRasterName (Required)

The name of the output image service that will be created.

You can specify the name, or you can create an empty service using Portal Admin Sharing API and use the return JSON object as input to this parameter.

Syntax: A JSON object describes the name of the output or the output raster.

Output name example:

Use dark colors for code blocksCopy
1
"outputRasterName":{"serviceProperties":{"name":"testrasteranalysis"}}

Output raster examples:

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//Output portal item:
"outputRasterName":{"itemId": <portal item id>}

//Output url:
"outputRasterName":{"url": <image service url>}

//Output raster layer service:
"outputRasterName": {
  "serviceProperties": {
    "name": "testrasteranalysis",
    "serviceUrl": "https://<server name>/server/rest/services/Hosted/testrasteranalysis/ImageServer"
  },
  "itemProperties": {
    "itemId": "8cfbd3ec25584d0d8f4ed23b8ff7c43b",
    "folderId": "sdfwerfbd3ec25584d0d8f4"
  }
}

extractionArea

Specifies whether cells inside or outside the locations defined by the input mask will be selected and written to the output raster. When set as INSIDE, cells within the input mask will be selected and written to the output raster. All cells outside the mask will receive NoData on the output raster. When set as OUTSIDE, cells outside the input mask will be selected and written to the output raster. All cells covered by the mask will receive NoData. The default value is INSIDE.

Syntax: An enumerated string value

Values: INSIDE | OUTSIDE

analysisExtent

The extent that defines the area to be extracted.

By default, the output extent is calculated as the intersection of the Input Raster and Input Raster or Feature Mask Data extents. Processing is performed only within the limits of this intersecting area. Cells outside the extent are assigned NoData values.

Extent Syntax:

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
  "extent": {
    "xmin": <minimum x-coordinate>,
    "ymin": <minimum y-coordinate>,
    "xmax": <maximum x-coordinate>,
    "ymax": <maximum y-coordinate>,
    "spatialReference": {"wkid": <spatial reference well-known identifier>}
  }

Example:

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
"analysisExtent": {
    "xmin": 445577.8322,
    "ymin": 204482.0639,
    "xmax": 510381.4416,
    "ymax": 250810.0426,
    "spatialReference": {
      "wkid": 32145
  		}
}

context

Contains additional settings that affect task processing. This task has the following settings:

  • Extent (extent)—A bounding box that defines the analysis area.

  • Output Spatial Reference (outSR )—The output raster will be projected into the output spatial reference.

  • Snap Raster (snapRaster )—The output raster will have its cells aligned with the specified snap raster.

  • Cell Size (cellSize )—The output raster will have the resolution specified by cell size.

  • Mask (mask)—Only cells that fall within the analysis mask will be considered in the operation.

f

The response format. The default response format is html .

Values: html | json | pjson

Response

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

Use dark colors for code blocksCopy
1
2
3
4
{
  "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 Checking job status. Once the job has successfully completed, you use the jobId to retrieve the results. To track the status, you can make a request of the following form:

Use dark colors for code blocksCopy
1
https://<raster analysis tools url>/ExtractByMask/jobs/<jobId>

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:

Use dark colors for code blocksCopy
1
https://<raster analysis tools url>/ExtractByMask/jobs/<jobId>/results/<output parameters>

Example usage

The following is a sample request URL for ExtractByMask :

Use dark colors for code blocksCopy
1
https://services.myserver.com/arcgis/rest/services/System/RasterAnalysisTools/GPServer/ExtractByMask/submitJob

JSON Response syntax

The response returns the outputRaster output parameter, which have properties for parameter name, data type, and value. The content of value is always the itemId of the output raster dataset and the image service URL.

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
{
  "paramName": <parameter name>,
  "dataType": "GPString",
  "value": {
    "itemId": <item Id>,
    "url": <URL>
  }
}

JSON Response example

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
{
  "paramName": "outputRaster",
  "dataType": "GPString",
  "value": {
    "itemId": "f121390b85ef419790479fc75b493efd",
    "url": "https://<server name>/arcgis/rest/services/Hosted/<service name>/ImageServer"
  }
}

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