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:
Thanks!
Hi Juan,
We are aware of this question and currently I'm drafting a reply. Runtime SDK iOS provides limited support for Raster Functions: https://developers.arcgis.com/ios/layers/add-raster-data/#create-a-raster-from-a-raster-function 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 = """
{
"raster_function_arguments":
{
"minx":{"double":2250000,"type":"Raster_function_variable"},
"miny":{"double":-4100000,"type":"Raster_function_variable"},
"maxx":{"double":2350000,"type":"Raster_function_variable"},
"maxy":{"double":-3900000,"type":"Raster_function_variable"},
"dx":{"double":100000,"type":"Raster_function_variable"},
"dy":{"double":100000,"type":"Raster_function_variable"},
"raster":{"name":"raster","is_raster":true,"type":"Raster_function_variable"},
"type":"Raster_function_arguments"
},
"raster_function":{"type":"Clip_function"},
"type":"Raster_function_template"
}
"""
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)
mapView.map?.operationalLayers.add(newRasterLayer)
} 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.
References:
- https://developers.arcgis.com/ios/api-reference/interface_a_g_s_raster_function.html
Although it is indeed a clip, that is not the effect I am looking for.
Anyway, thanks for the feedback and the detailed information.
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.
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