View on GitHub Sample viewer app
Create contour lines from local raster data using a local geoprocessing package .gpkx
and the contour geoprocessing tool.
Use case
For executing offline geoprocessing tasks in your apps via an offline (local) server.
How to use the sampleContour Line Controls (Top Left):
ArcGISTiledLayer
.LocalServer::instance
creates the Local Server.LocalServer::start()
starts the server asynchronously.LocalServerStatus::Started
state.
LocalServer::statusChanged()
fires whenever the running status of the Local Server changes.LocalGeoprocessingService
and run a GeoprocessingTask
new LocalGeoprocessingService(Url, ServiceType)
, creates a local geoprocessing serviceLocalGeoprocessingService::start()
starts the service asynchronously.new GeoprocessingTask(LocalGeoprocessingService.url() + "/Contour")
, creates a geoprocessing task that uses the contour lines toolGeoprocessingParameters
and add a GeoprocessingDouble
as a parameter using set interval.
new GeoprocessingParameters(ExecutionType)
, creates geoprocessing parametersinputs.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.GeoprocessingJob
using the parameters from above.
GeoprocessingTask::createJob(GeoprocessingParameters)
, creates a geoprocessing jobGeoprocessingJob::start()
, starts the job.ArcGISMapImageLayer
to map.
LocalGeoprocessingService::url()
GeoprocessingJob::serverJobId()
GPServer
from url with MapServer/jobs/jobId
, to get generate contour lines dataRead more about how to set up the sample's offline data here.
Additional informationLocal Server can be downloaded for Windows and Linux platforms. Local Server is not supported on macOS.
geoprocessing, local, offline, parameters, processing, service
Sample CodeLocalServerGeoprocessing.cpp LocalServerGeoprocessing.cpp LocalServerGeoprocessing.h LocalServerGeoprocessing.qml
Use dark colors for code blocks Copy
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
// [WriteFile Name=LocalServerGeoprocessing, 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]
#ifdef PCH_BUILD
#include "pch.hpp"
#endif // PCH_BUILD
// sample headers
#include "LocalServerGeoprocessing.h"
// ArcGIS Maps SDK headers
#include "ArcGISMapImageLayer.h"
#include "ArcGISTiledLayer.h"
#include "Basemap.h"
#include "Envelope.h"
#include "GeoprocessingDouble.h"
#include "GeoprocessingJob.h"
#include "GeoprocessingParameter.h"
#include "GeoprocessingParameters.h"
#include "GeoprocessingTask.h"
#include "GeoprocessingTypes.h"
#include "LayerListModel.h"
#include "LocalGeoprocessingService.h"
#include "LocalServer.h"
#include "LocalServerTypes.h"
#include "Map.h"
#include "MapQuickView.h"
#include "MapTypes.h"
#include "MapViewTypes.h"
#include "TaskTypes.h"
#include "TileCache.h"
#include "Viewpoint.h"
// Qt headers
#include <QDir>
#include <QFuture>
#include <QTemporaryDir>
using namespace Esri::ArcGISRuntime;
// constructor
LocalServerGeoprocessing::LocalServerGeoprocessing(QQuickItem* parent) :
QQuickItem(parent)
{
// Create a temporary directory for the local server if one has not already been created
if (!LocalServer::appDataPath().isEmpty() && !LocalServer::tempDataPath().isEmpty())
return;
// create temp/data path
const QString tempPath = LocalServerGeoprocessing::shortestTempPath() + "/EsriQtTemp";
// create the directory
m_tempDir = std::make_unique<QTemporaryDir>(tempPath);
// set the temp & app data path for the local server
LocalServer::instance()->setTempDataPath(m_tempDir->path());
LocalServer::instance()->setAppDataPath(m_tempDir->path());
}
// destructor
LocalServerGeoprocessing::~LocalServerGeoprocessing() = default;
void LocalServerGeoprocessing::init()
{
qmlRegisterType<MapQuickView>("Esri.Samples", 1, 0, "MapView");
qmlRegisterType<LocalServerGeoprocessing>("Esri.Samples", 1, 0, "LocalServerGeoprocessingSample");
}
void LocalServerGeoprocessing::componentComplete()
{
QQuickItem::componentComplete();
QString dataPath = QDir::homePath() + "/ArcGIS/Runtime/Data";
// find QML MapView component
m_mapView = findChild<MapQuickView*>("mapView");
m_mapView->setWrapAroundMode(WrapAroundMode::Disabled);
// Create a map using the topographic BaseMap
m_map = new Map(BasemapStyle::ArcGISLightGray, this);
// Set map to map view
m_mapView->setMap(m_map);
TileCache* tileCache = new TileCache(dataPath + "/tpkx/RasterHillshade.tpkx", this);
m_tiledLayer = new ArcGISTiledLayer(tileCache, this);
m_map->operationalLayers()->append(m_tiledLayer);
// create a gp service
m_localGPService = new LocalGeoprocessingService(dataPath + "/gpkx/Contour.gpkx", this);
m_localGPService->setServiceType(GeoprocessingServiceType::AsynchronousSubmitWithMapServerResult);
if (LocalServer::instance()->isInstallValid())
{
connectSignals();
if (LocalServer::instance()->status() == LocalServerStatus::Started)
m_localGPService->start();
else
LocalServer::start();
}
}
void LocalServerGeoprocessing::connectSignals()
{
connect (m_tiledLayer, &ArcGISTiledLayer::loadStatusChanged, this, [this](LoadStatus status)
{
if (status == LoadStatus::Loaded)
{
m_mapView->setViewpointAsync(Viewpoint(m_tiledLayer->fullExtent()));
}
});
// start the gp service once local server has started
connect(LocalServer::instance(), &LocalServer::statusChanged, this, [this]()
{
if (LocalServer::status() == LocalServerStatus::Started)
{
// start the service
m_localGPService->start();
m_isReady = false;
emit isReadyChanged();
}
});
// local gp service status
connect(m_localGPService, &LocalGeoprocessingService::statusChanged, this, [this]()
{
if (m_localGPService->status() == LocalServerStatus::Started)
{
m_gpTask = new GeoprocessingTask(QUrl(m_localGPService->url().toString() + "/Contour"), this);
m_isReady = true;
emit isReadyChanged();
}
});
}
void LocalServerGeoprocessing::generateContours(double interval)
{
m_isReady = false;
emit isReadyChanged();
GeoprocessingParameters gpParams(GeoprocessingExecutionType::AsynchronousSubmit);
QMap<QString, GeoprocessingParameter*> inputs = gpParams.inputs();
inputs.insert("ContourInterval", new GeoprocessingDouble(interval, this));
gpParams.setInputs(inputs);
GeoprocessingJob* gpJob = m_gpTask->createJob(gpParams);
connect(gpJob, &GeoprocessingJob::statusChanged, this, [this, gpJob](JobStatus jobStatus)
{
if (jobStatus == JobStatus::Succeeded)
{
QString url = m_localGPService->url().toString().replace("GPServer", "MapServer/jobs/" + gpJob->serverJobId());
ArcGISMapImageLayer* mapImageLayer = new ArcGISMapImageLayer(QUrl(url), this);
m_map->operationalLayers()->append(mapImageLayer);
m_isReady = true;
emit isReadyChanged();
}
});
gpJob->start();
}
void LocalServerGeoprocessing::clearResults()
{
if (m_mapView->map()->operationalLayers()->size() > 1)
m_mapView->map()->operationalLayers()->removeAt(1);
}
QString LocalServerGeoprocessing::shortestTempPath()
{
// get tmp and home paths
const QString tmpPath = QDir::tempPath();
const QString homePath = QDir::homePath();
// return whichever is shorter, temp or home path
if (homePath.length() > tmpPath.length())
return tmpPath;
else
return homePath;
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4