Raster function (service)

Loading

Code

import QtQuick 2.6
import QtQuick.Controls 1.4
import Esri.ArcGISRuntime 100.2
import Esri.ArcGISExtras 1.1

Rectangle {
    id: rootRectangle
    clip: true

    width: 800
    height: 600

    property real scaleFactor: System.displayScaleFactor
    property string dataPath: System.userHomePath + "/ArcGIS/Runtime/Data/raster/"

    MapView {
        anchors.fill: parent
        id: mapView

        Map {
            // create a basemap from a tiled layer and add to the map
            BasemapStreets {}

            // create and add a raster layer to the map
            RasterLayer {
                // create the raster layer from an image service raster
                ImageServiceRaster {
                    id: imageServiceRaster
                    url: "http://sampleserver6.arcgisonline.com/arcgis/rest/services/NLCDLandCover2001/ImageServer"

                    // zoom to the extent of the raster once it's loaded
                    onLoadStatusChanged: {
                        if (loadStatus === Enums.LoadStatusLoaded) {
                            mapView.setViewpointGeometry(imageServiceRaster.serviceInfo.fullExtent);
                        }
                    }
                }
            }
        }
    }

    // Create a button to apply the raster function
    Rectangle {
        id: button
        property bool pressed: false

        anchors {
            right: parent.right
            bottom: parent.bottom
            rightMargin: 20 * scaleFactor
            bottomMargin: 40 * scaleFactor
        }

        width: 45 * scaleFactor
        height: width
        color: pressed ? "#959595" : "#D6D6D6"
        radius: 100
        border {
            color: "#585858"
            width: 1 * scaleFactor
        }

        Image {
            anchors {
                centerIn: parent
                verticalCenterOffset: -3 * scaleFactor
            }
            width: 26 * scaleFactor
            height: width
            source: "qrc:/Samples/Layers/RasterFunctionService/RasterImageAnalysisHillshade.png"
        }

        MouseArea {
            anchors.fill: parent
            onPressed: button.pressed = true
            onReleased: button.pressed = false
            onClicked: applyRasterFunction()
        }
    }

    function applyRasterFunction() {
        if (!hillShadeJson.exists) {
            console.log("JSON file for the raster function does not exist");
            return;
        }

        // create raster function
        var rasterFunction = ArcGISRuntimeEnvironment.createObject("RasterFunction", {path: dataPath + "/hillshade_simplified.json"});
        // get the arguments
        var rasterFunctionArguments = rasterFunction.arguments;
        // set the raster
        rasterFunctionArguments.setRaster("raster", imageServiceRaster);

        // create the raster from the raster function
        var raster = ArcGISRuntimeEnvironment.createObject("Raster", { rasterFunction: rasterFunction });

        // create raster layer from raster
        var rasterLayer = ArcGISRuntimeEnvironment.createObject("RasterLayer", { raster: raster });

        // add raster to map
        mapView.map.operationalLayers.clear();
        mapView.map.operationalLayers.append(rasterLayer);
    }

    FileInfo {
        id: hillShadeJson
        url: dataPath + "/hillshade_simplified.json"
    }
}


In this topic
  1. Code