I was wondering if anyone had any experience or examples rendering raster functions as a raster layer.
Every time I pass a raster function with the mask_function the whole raster isn't shown.
I use a function of the following
{ "raster_function":{"type":"Mask_function"}, "raster_function_arguments": { "nodata_values":{"double_array":["0.0","1.0","2.0","3.0","4.0","5.0","6.0","7.0","8.0","9.0","10.0","11.0","12.0","13.0","14.0","15.0","16.0","17.0","18.0","19.0","20.0","21.0","22.0","23.0","24.0","25.0","26.0","27.0","28.0","29.0","30.0","31.0","32.0","33.0","34.0","35.0","36.0","37.0","38.0","39.0","40.0","41.0","42.0","43.0","44.0","45.0","46.0","47.0","48.0","49.0","50.0"],"type":"Raster_function_variable"}, "nodata_interpretation":{"nodata_interpretation":"all","type":"Raster_function_variable"}, "raster":{"name":"raster","is_raster":true,"type":"Raster_function_variable"}, "type":"Raster_function_arguments" },"type":"Raster_function_template"}
I have also tried using instead of string values just regular values in the form of [0.0, 1.0, 2.0, ...]
My code looks like the following
class func loadOnlineRasterImage(function: String, complete: @escaping (AGSRasterLayer) ->()) {
let x = URL.init(string: "https://utility.arcgis.com/usrsvcs/servers/11e0cb598d77463cbe3b90d5e53f37d6/rest/services/WorldElevation/Terrain/ImageServer")
let imageServiceRaster = AGSImageServiceRaster.init(url: x!)
let serviceInfo = imageServiceRaster.serviceInfo
let renderingRule = AGSRenderingRule(renderingRuleJSON: [
"rasterFunction": function,
"format":"jpg"
])
imageServiceRaster.renderingRule = renderingRule
imageServiceRaster.load { (error) in
if let error = error {
print(error)
return
}
let rasterFunction = self.setRasterfunction(raster: imageServiceRaster)
let finalRaster = AGSRaster.init(rasterFunction: rasterFunction)
print("nardo")
print(error)
let rasterLayer = AGSRasterLayer(raster: finalRaster)
complete(rasterLayer)
}
}
class func setRasterfunction(raster: AGSImageServiceRaster) -> AGSRasterFunction{
var x: [Double] = []
for index in 0...50 {
x.append(Double(index))
}
var xx = x.map({abc -> String in "\(abc)"}).joined(separator: ",")
var content = "{ \"raster_function\":{\"type\":\"Mask_function\"}, \"raster_function_arguments\": { \"nodata_values\":{\"double_array\":[{{replace}}],\"type\":\"Raster_function_variable\"}, \"nodata_interpretation\":{\"nodata_interpretation\":\"all\",\"type\":\"Raster_function_variable\"}, \"raster\":{\"name\":\"raster\",\"is_raster\":true,\"type\":\"Raster_function_variable\"}, \"type\":\"Raster_function_arguments\" },\"type\":\"Raster_function_template\"}".replacingOccurrences(of: "{{replace}}", with: xyz )
print(content)
FileUtil.writefile(name: "hi.json", content: content )
let docDir = try! FileManager.default.url(for: .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
let mapUrl = docDir.appendingPathComponent("hi.json")
let rasterFunction = AGSRasterFunction(fileURL: mapUrl)
// initialize the arguments of the raster function
let rasterFunctionArguments = rasterFunction.arguments
print(rasterFunctionArguments.debugDescription)
let rasterNames = rasterFunctionArguments!.rasterNames
// assuming rasterNames has 2 entries, set the 2 rasters
rasterFunctionArguments!.setRaster(raster, withName: rasterNames[0])
return rasterFunction
}
The first function uses the second function to create a raster function and load it into a new agsraster which is then placed in a layer. I know that the file is properly being written as I've checked it. I'm not sure what I'm doing wrong : \
Does anyone have any working examples or advice?