Masking / clipping raster

08-12-2021 10:39 AM
New Contributor II

I am working with the latest iOS SDK (100.11).

I have a web map with a raster layer. I also have an area of interest, which actually is a farm lot (irregular polygon) and I would like to mask/clip the raster with that geometry so the raster is only visible for the AOI. Any ideas where to start?

The image would look like this one: 


0 Kudos
4 Replies
by Esri Contributor
Esri Contributor

Hi Juan,

We are aware of this question and currently I'm drafting a reply. Runtime SDK iOS provides limited support for Raster Functions: and it is possible to clip a raster with a raster function.

Update 210814:

According to our core team, currently Runtime only support rectangular clipping. If you would like to request the clip raster with polygon feature in the future version of Runtime, I'd like to pass along your request to @DiveshGoyal .


Meanwhile, if you want to try out clipping with a rectangular box, here is a snippet that might help.

func clipRasterJSONString() {
    let rasterFunctionJSON = """
    let rasterFunction = AGSRasterFunction.fromJSON(rasterFunctionJSON, error: nil) as! AGSRasterFunction
    if let rasterFunctionArguments = rasterFunction.arguments {
        let rasterNames = rasterFunctionArguments.rasterNames
        rasterFunctionArguments.setRaster(raster, withName: rasterNames.first!)
        let newRaster = AGSRaster(rasterFunction: rasterFunction)
        let newRasterLayer = AGSRasterLayer(raster: newRaster)
    } else {
        print("Clip raster failed")

You can either define the clipping box in a local Raster Function JSON file or in a JSON string, as shown above. Then, create a new raster with the raster function and add the layer to the map.


Attached is a demo app for clipping a raster. Please see the reference doc for the raster function JSON template.




New Contributor II

Although it is indeed a clip, that is not the effect I am looking for.

Anyway, thanks for the feedback and the detailed information.

0 Kudos
Esri Regular Contributor

Hi @JuanPeralta_ESRIES,

Can you explain the effect you were looking for please? I thought that you were trying to clip a displayed raster to a polygon area of interest.

0 Kudos
New Contributor II

Hi @Nicholas-Furness

the arguments for that raster function define a rectangle (min/max x/y), but I was trying to clip a raster with an irregular polygon. The idea is to clip a continuous raster (NDVI values in my case) with the farm parcel geometry, so that way you have a map like the one I included in my first post: a standard ArcGIS basemap and on top of it a raster layer with the NDVI values just for that parcel.

There are a number of AgTech mobile apps with this effect, but I guess they do this in the backend, actually clipping the raster and storing it for each client/farm parcel. I was trying to avoid the geoprocessing in the backend ;)

If you want to see some real examples you can DM me.

What I am trying to achieve: I would like to show that ArcGIS SDKs + Living Atlas is a quick-win vs all this ad-hoc AgTech solutions, because they need to maintain quite a complex platform to acquire, store and process all those satellite datasets in the backend, while ArcGIS does most of it out-of-the-box. 

Thanks for the follow-up

0 Kudos