Local server geoprocessing

View on GitHub
Sample viewer app

Create contour lines from local raster data using a local geoprocessing package .gpkx and the contour geoprocessing tool.

screenshot

Use case

For executing offline geoprocessing tasks in your ArcGIS Runtime apps via an offline (local) server.

How to use the sample

Contour Line Controls (Top Left):

  • Interval - Specifies the spacing between contour lines.
  • Generate Contours - Adds contour lines to map using interval.
  • Clear Results - Removes contour lines from map.

How it works

  1. Add raster data to map using as an ArcGISTiledLayer.
  2. Create and run the Local Server.

    • LocalServer::instance creates the Local Server.
    • LocalServer::start() starts the server asynchronously.
  3. Wait for server to be in the LocalServerStatus::Started state.

    • LocalServer::statusChanged() fires whenever the running status of the Local Server changes.
  4. Start a LocalGeoprocessingService and run a GeoprocessingTask

    • new LocalGeoprocessingService(Url, ServiceType), creates a local geoprocessing service
    • LocalGeoprocessingService::start() starts the service asynchronously.
    • new GeoprocessingTask(LocalGeoprocessingService.url() + "/Contour"), creates a geoprocessing task that uses the contour lines tool
  5. Create GeoprocessingParameters and add a GeoprocessingDouble as a parameter using set interval.

    • new GeoprocessingParameters(ExecutionType), creates geoprocessing parameters
    • inputs.insert("ContourInterval", new GeoprocessingDouble(double)), creates a parameter with name ContourInterval with the interval set as its value.
    • gpParams.setInputs(inputs), sets the input with the interval value.
  6. Create and start a GeoprocessingJob using the parameters from above.

    • GeoprocessingTask::createJob(GeoprocessingParameters), creates a geoprocessing job
    • GeoprocessingJob::start(), starts the job.
  7. Add contour lines as an ArcGISMapImageLayer to map.

    • Get url from local geoprocessing service, LocalGeoprocessingService::url()
    • Get server job id of geoprocessing job, GeoprocessingJob::serverJobId()
    • Replace GPServer from url with MapServer/jobs/jobId, to get generate contour lines data
    • create a map image layer from that new url and add that layer to the map

Relevant API

  • GeoprocessingDouble
  • GeoprocessingJob
  • GeoprocessingParameter
  • GeoprocessingParameters
  • GeoprocessingTask
  • LocalGeoprocessingService
  • LocalGeoprocessingService::serviceType
  • LocalServer
  • LocalServerStatus

Offline Data

Read more about how to set up the sample's offline data here.

Link Local Location
Contour geoprocessing package <userhome>/ArcGIS/Runtime/Data/gpkx/Contour.gpkx
Raster Hillshade TPKX <userhome>/ArcGIS/Runtime/Data/tpkx/RasterHillshade.tpkx

Additional information

Local Server can be downloaded for Windows and Linux platforms. Local Server is not supported on macOS.

Tags

geoprocessing, local, offline, parameters, processing, service

Sample Code

LocalServerGeoprocessing.qmlLocalServerGeoprocessing.cppLocalServerGeoprocessing.h
                                                                                                                              
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
// [WriteFile Name=LocalServerFeatureLayer, Category=LocalServer]
// [Legal]
// Copyright 2017 Esri.

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// [Legal]

import QtQuick 2.6
import QtQuick.Controls 2.2
import Esri.Samples 1.0

LocalServerGeoprocessingSample {
    id: localServerGeoprocessingSample
    width: 800
    height: 600

    // Create MapQuickView here, and create its Map etc. in C++ code
    MapView {
        anchors.fill: parent
        objectName: "mapView"
        // set focus to enable keyboard navigation
        focus: true

        Rectangle {
            id: actionAreaRect
            anchors {
                margins: 15
                top: parent.top
                left: parent.left
            }
            width: parent.width * 0.3
            height: parent.height * 0.30
            color: isReady ? "black" : "silver"
            opacity: 0.7
            radius: 5

            Column {
                id: contentColumn
                spacing: 5
                anchors.fill: parent
                anchors.margins: 5
                visible: isReady

                Text {
                    text: qsTr("Specify the interval, or distance, between contour lines and click the 'Generate Contours' button.")
                    width: parent.width
                    wrapMode: Text.WordWrap
                    color: "white"
                    font.pixelSize: 12
                }

                Rectangle {
                    width: parent.width
                    height: 35
                    radius: 5

                    Text {
                        anchors {
                            left: parent.left
                            verticalCenter: parent.verticalCenter
                            margins: 5
                        }
                        width: 40
                        text: qsTr("Interval: ")
                        font.bold: true
                        font.pixelSize: 14
                    }

                    TextField {
                        id: intervalText
                        anchors {
                            right: parent.right
                            verticalCenter: parent.verticalCenter
                            margins: 5
                        }
                        width: 100
                        text: "200"
                        selectByMouse: true
                        validator: DoubleValidator {bottom: 100; top: 500}
                    }
                }

                Button {
                    width: parent.width
                    text: "Generate Contours"
                    height: 35
                    font.pixelSize: 14
                    font.bold: true
                    onClicked: {
                        generateContours(intervalText.text);
                    }
                }

                Button {
                    width: parent.width
                    text: "Clear Results"
                    height: 35
                    font.pixelSize: 14
                    font.bold: true
                    onClicked: {
                        clearResults();
                    }
                }

            }

            BusyIndicator {
                id: busyIndicator
                anchors.verticalCenter: parent.verticalCenter
                anchors.horizontalCenter: parent.horizontalCenter
                width: 22
                height: width
                running: !isReady
            }
        }
    }
}

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