Debian Codegraph @

ogr/ogrsf_frmts/ngw/ogrngwdriver.cpp

raw symbols SCIP
1 /*******************************************************************************
2 * Project: NextGIS Web Driver
3 * Purpose: Implements NextGIS Web Driver
4 * Author: Dmitry Baryshnikov, [email protected]
5 * Language: C++
6 *******************************************************************************
7 * The MIT License (MIT)
8 *
9 * Copyright (c) 2018-2025, NextGIS <[email protected]>
10 *
11 * SPDX-License-Identifier: MIT
12 *******************************************************************************/
13
14 #include "ogr_ngw.h"cxx . . $ `<file>/ogr/ogrsf_frmts/ngw/ogr_ngw.h`/
15
16 // #include <gdalsubdatasetinfo.h>
17
18 /*
19 * GetHeaders()
20 */
21 static CPLStringList GetHeaderscxx . . $ GetHeaders(fb7086751aed8ae6).(const stdcxx . . $ std/::string &osUserPwdIn = "",
22 const stdcxx . . $ std/::string &osConnectTimeout = "",
23 const stdcxx . . $ std/::string &osTimeout = "",
24 const stdcxx . . $ std/::string &osRetryCount = "",
25 const stdcxx . . $ std/::string &osRetryDelay = "")
26 {
27 CPLStringList aosHTTPOptions;
28 aosHTTPOptions.AddString("HEADERS=Accept: */*");
29 if (!osUserPwdIn.empty())
30 {
31 aosHTTPOptions.AddString("HTTPAUTH=BASIC");
32 stdcxx . . $ std/::string osUserPwdOption("USERPWD=");
33 osUserPwdOption += osUserPwdIn;
34 aosHTTPOptions.AddString(osUserPwdOption.c_str());
35 }
36
37 if (!osConnectTimeout.empty())
38 {
39 aosHTTPOptions.AddNameValue("CONNECTTIMEOUT", osConnectTimeout.c_str());
40 }
41
42 if (!osTimeout.empty())
43 {
44 aosHTTPOptions.AddNameValue("TIMEOUT", osTimeout.c_str());
45 }
46
47 if (!osRetryCount.empty())
48 {
49 aosHTTPOptions.AddNameValue("MAX_RETRY", osRetryCount.c_str());
50 }
51 if (!osRetryDelay.empty())
52 {
53 aosHTTPOptions.AddNameValue("RETRY_DELAY", osRetryDelay.c_str());
54 }
55 return aosHTTPOptions;
56 }
57
58 /*
59 * OGRNGWDriverIdentify()
60 */
61
62 static int OGRNGWDriverIdentifycxx . . $ OGRNGWDriverIdentify(48f695ac6b30cd84).(GDALOpenInfocxx . . $ GDALOpenInfo# *poOpenInfo)
63 {
64 return STARTS_WITH_CIcxx . . $ `port/cpl_port.h:543:9`!(poOpenInfo->pszFilename, "NGW:");
65 }
66
67 /*
68 * OGRNGWDriverOpen()
69 */
70
71 static GDALDatasetcxx . . $ GDALDataset# *OGRNGWDriverOpencxx . . $ OGRNGWDriverOpen(905b7966ba8c1649).(GDALOpenInfocxx . . $ GDALOpenInfo# *poOpenInfo)
72 {
73 if (OGRNGWDriverIdentifycxx . . $ OGRNGWDriverIdentify(48f695ac6b30cd84).(poOpenInfo) == 0)
74 {
75 return nullptr;
76 }
77
78 OGRNGWDatasetcxx . . $ OGRNGWDataset# *poDS = new OGRNGWDatasetcxx . . $ OGRNGWDataset#OGRNGWDataset(49f6e7a06ebc5aa8).();
79 if (!poDS->Opencxx . . $ OGRNGWDataset#Open(acf79a1d5b584828).(poOpenInfo->pszFilenamecxx . . $ GDALOpenInfo#pszFilename., poOpenInfo->papszOpenOptionscxx . . $ GDALOpenInfo#papszOpenOptions.,
80 poOpenInfo->eAccesscxx . . $ GDALOpenInfo#eAccess. == GA_Update, poOpenInfo->nOpenFlagscxx . . $ GDALOpenInfo#nOpenFlags.))
81 {
82 delete poDS;
83 poDS = nullptr;
84 }
85
86 return poDS;
87 }
88
89 /*
90 * OGRNGWDriverCreate()
91 *
92 * Add new datasource name at the end of URL:
93 * NGW:http://some.nextgis.com/resource/0/new_name
94 * NGW:http://some.nextgis.com:8000/test/resource/0/new_name
95 */
96
97 static GDALDatasetcxx . . $ GDALDataset# *
98 OGRNGWDriverCreatecxx . . $ OGRNGWDriverCreate(2a509bdc7a404bec).(const char *pszName, CPL_UNUSEDcxx . . $ `port/cpl_port.h:1040:9`! int nBands,
99 CPL_UNUSEDcxx . . $ `port/cpl_port.h:1040:9`! int nXSize, CPL_UNUSEDcxx . . $ `port/cpl_port.h:1040:9`! int nYSize,
100 CPL_UNUSEDcxx . . $ `port/cpl_port.h:1040:9`! GDALDataType eDT, CSLConstListcxx . . $ CSLConstList# papszOptions)
101
102 {
103 NGWAPIcxx . . $ NGWAPI/::Uricxx . . $ NGWAPI/Uri# stUri = NGWAPIcxx . . $ NGWAPI/::ParseUricxx . . $ NGWAPI/ParseUri(5befab2a859ccef).(pszName);
104 CPLErrorReset();
105 if (stUri.osPrefixcxx . . $ NGWAPI/Uri#osPrefix. != "NGW")
106 {
107 CPLError(CE_Failure, CPLE_NotSupportedcxx . . $ `port/cpl_error.h:118:9`!, "Unsupported name %s", pszName);
108 return nullptr;
109 }
110
111 CPLDebug("NGW", "Parse uri result. URL: %s, ID: %s, New name: %s",
112 stUri.osAddresscxx . . $ NGWAPI/Uri#osAddress..c_str(), stUri.osResourceIdcxx . . $ NGWAPI/Uri#osResourceId..c_str(),
113 stUri.osNewResourceNamecxx . . $ NGWAPI/Uri#osNewResourceName..c_str());
114
115 stdcxx . . $ std/::string osKey = CSLFetchNameValueDef(papszOptions, "KEY", "");
116 stdcxx . . $ std/::string osDesc = CSLFetchNameValueDef(papszOptions, "DESCRIPTION", "");
117 stdcxx . . $ std/::string osUserPwd = CSLFetchNameValueDef(
118 papszOptions, "USERPWD", CPLGetConfigOption("NGW_USERPWD", ""));
119
120 CPLJSONObjectcxx . . $ CPLJSONObject# oPayloadcxx . . $ CPLJSONObject#CPLJSONObject(49f6e7a06ebc5aa8).;
121 CPLJSONObjectcxx . . $ CPLJSONObject# oResourcecxx . . $ CPLJSONObject#CPLJSONObject(2303eda281a0fa9b).("resource", oPayload);
122 oResource.Addcxx . . $ CPLJSONObject#Add(32373b8560f77290).("cls", "resource_group");
123 oResource.Addcxx . . $ CPLJSONObject#Add(c3ca1c130ce09c52).("display_name", stUri.osNewResourceNamecxx . . $ NGWAPI/Uri#osNewResourceName.);
124 if (!osKey.empty())
125 {
126 oResource.Addcxx . . $ CPLJSONObject#Add(c3ca1c130ce09c52).("keyname", osKey);
127 }
128
129 if (!osDesc.empty())
130 {
131 oResource.Addcxx . . $ CPLJSONObject#Add(c3ca1c130ce09c52).("description", osDesc);
132 }
133
134 CPLJSONObjectcxx . . $ CPLJSONObject# oParentcxx . . $ CPLJSONObject#CPLJSONObject(2303eda281a0fa9b).("parent", oResource);
135 oParent.Addcxx . . $ CPLJSONObject#Add(412d11940ded42ad).("id", atoicxx . . $ atoi(f5ecf3191ed0cd93).(stUri.osResourceIdcxx . . $ NGWAPI/Uri#osResourceId..c_str()));
136
137 stdcxx . . $ std/::string osConnectTimeout =
138 CSLFetchNameValueDef(papszOptions, "CONNECTTIMEOUT",
139 CPLGetConfigOption("NGW_CONNECTTIMEOUT", ""));
140 stdcxx . . $ std/::string osTimeout = CSLFetchNameValueDef(
141 papszOptions, "TIMEOUT", CPLGetConfigOption("NGW_TIMEOUT", ""));
142
143 stdcxx . . $ std/::string osNewResourceId = NGWAPIcxx . . $ NGWAPI/::CreateResourcecxx . . $ NGWAPI/CreateResource(78a24f53bf4760fc).(
144 stUri.osAddresscxx . . $ NGWAPI/Uri#osAddress., oPayload.Formatcxx . . $ CPLJSONObject#Format(97b6c23b733e4099).(CPLJSONObjectcxx . . $ CPLJSONObject#::PrettyFormatcxx . . $ CPLJSONObject#PrettyFormat#::Plaincxx . . $ CPLJSONObject#PrettyFormat#Plain.),
145 GetHeaderscxx . . $ GetHeaders(fb7086751aed8ae6).(osUserPwd, osConnectTimeout, osTimeout));
146 if (osNewResourceId == "-1")
147 {
148 return nullptr;
149 }
150
151 OGRNGWDatasetcxx . . $ OGRNGWDataset# *poDS = new OGRNGWDatasetcxx . . $ OGRNGWDataset#OGRNGWDataset(49f6e7a06ebc5aa8).();
152
153 if (!poDS->Opencxx . . $ OGRNGWDataset#Open(80ee0aecd9a12254).(stUri.osAddresscxx . . $ NGWAPI/Uri#osAddress., osNewResourceId, papszOptions, true,
154 GDAL_OF_RASTERcxx . . $ `gcore/gdal.h:1125:9`! | GDAL_OF_VECTORcxx . . $ `gcore/gdal.h:1130:9`!)) // TODO: GDAL_OF_GNM
155 {
156 delete poDS;
157 poDS = nullptr;
158 }
159
160 return poDS;
161 }
162
163 /*
164 * OGRNGWDriverDelete()
165 */
166 static CPLErr OGRNGWDriverDeletecxx . . $ OGRNGWDriverDelete(80d06f1dc84b2c8f).(const char *pszName)
167 {
168 NGWAPIcxx . . $ NGWAPI/::Uricxx . . $ NGWAPI/Uri# stUri = NGWAPIcxx . . $ NGWAPI/::ParseUricxx . . $ NGWAPI/ParseUri(5befab2a859ccef).(pszName);
169 CPLErrorReset();
170
171 if (stUri.osPrefixcxx . . $ NGWAPI/Uri#osPrefix. != "NGW")
172 {
173 CPLError(CE_Failure, CPLE_NotSupportedcxx . . $ `port/cpl_error.h:118:9`!, "Unsupported name %s", pszName);
174 return CE_Failure;
175 }
176
177 if (!stUri.osNewResourceNamecxx . . $ NGWAPI/Uri#osNewResourceName..empty())
178 {
179 CPLError(CE_Warning, CPLE_NotSupportedcxx . . $ `port/cpl_error.h:118:9`!,
180 "Cannot delete new resource with name %s", pszName);
181 return CE_Failure;
182 }
183
184 if (stUri.osResourceIdcxx . . $ NGWAPI/Uri#osResourceId. == "0")
185 {
186 CPLError(CE_Failure, CPLE_NotSupportedcxx . . $ `port/cpl_error.h:118:9`!, "Cannot delete resource 0");
187 return CE_Failure;
188 }
189
190 stdcxx . . $ std/::string osUserPwd = CPLGetConfigOption("NGW_USERPWD", "");
191 stdcxx . . $ std/::string osConnectTimeout = CPLGetConfigOption("NGW_CONNECTTIMEOUT", "");
192 stdcxx . . $ std/::string osTimeout = CPLGetConfigOption("NGW_TIMEOUT", "");
193 stdcxx . . $ std/::string osRetryCount = CPLGetConfigOption("NGW_MAX_RETRY", "");
194 stdcxx . . $ std/::string osRetryDelay = CPLGetConfigOption("NGW_RETRY_DELAY", "");
195
196 auto aosHTTPOptions = GetHeaderscxx . . $ GetHeaders(fb7086751aed8ae6).(osUserPwd, osConnectTimeout, osTimeout,
197 osRetryCount, osRetryDelay);
198
199 return NGWAPIcxx . . $ NGWAPI/::DeleteResourcecxx . . $ NGWAPI/DeleteResource(4b13e6de7953d082).(stUri.osAddresscxx . . $ NGWAPI/Uri#osAddress., stUri.osResourceIdcxx . . $ NGWAPI/Uri#osResourceId.,
200 aosHTTPOptions)
201 ? CE_None
202 : CE_Failure;
203 }
204
205 /*
206 * OGRNGWDriverRename()
207 */
208 static CPLErr OGRNGWDriverRenamecxx . . $ OGRNGWDriverRename(d109fabb5fb87841).(const char *pszNewName, const char *pszOldName)
209 {
210 NGWAPIcxx . . $ NGWAPI/::Uricxx . . $ NGWAPI/Uri# stUri = NGWAPIcxx . . $ NGWAPI/::ParseUricxx . . $ NGWAPI/ParseUri(5befab2a859ccef).(pszOldName);
211 CPLErrorReset();
212 if (stUri.osPrefixcxx . . $ NGWAPI/Uri#osPrefix. != "NGW")
213 {
214 CPLError(CE_Failure, CPLE_NotSupportedcxx . . $ `port/cpl_error.h:118:9`!, "Unsupported name %s",
215 pszOldName);
216 return CE_Failure;
217 }
218 CPLDebug("NGW", "Parse uri result. URL: %s, ID: %s, New name: %s",
219 stUri.osAddresscxx . . $ NGWAPI/Uri#osAddress..c_str(), stUri.osResourceIdcxx . . $ NGWAPI/Uri#osResourceId..c_str(), pszNewName);
220
221 stdcxx . . $ std/::string osUserPwd = CPLGetConfigOption("NGW_USERPWD", "");
222 stdcxx . . $ std/::string osConnectTimeout = CPLGetConfigOption("NGW_CONNECTTIMEOUT", "");
223 stdcxx . . $ std/::string osTimeout = CPLGetConfigOption("NGW_TIMEOUT", "");
224 stdcxx . . $ std/::string osRetryCount = CPLGetConfigOption("NGW_MAX_RETRY", "");
225 stdcxx . . $ std/::string osRetryDelay = CPLGetConfigOption("NGW_RETRY_DELAY", "");
226
227 auto aosHTTPOptions = GetHeaderscxx . . $ GetHeaders(fb7086751aed8ae6).(osUserPwd, osConnectTimeout, osTimeout,
228 osRetryCount, osRetryDelay);
229
230 return NGWAPIcxx . . $ NGWAPI/::RenameResourcecxx . . $ NGWAPI/RenameResource(e3b81046716d3e73).(stUri.osAddresscxx . . $ NGWAPI/Uri#osAddress., stUri.osResourceIdcxx . . $ NGWAPI/Uri#osResourceId.,
231 pszNewName, aosHTTPOptions)
232 ? CE_None
233 : CE_Failure;
234 }
235
236 /*
237 * OGRNGWDriverCreateCopy()
238 */
239 static GDALDatasetcxx . . $ GDALDataset# *OGRNGWDriverCreateCopycxx . . $ OGRNGWDriverCreateCopy(8d8ece3624d4575).(const char *pszFilename,
240 GDALDatasetcxx . . $ GDALDataset# *poSrcDS, int bStrict,
241 CSLConstListcxx . . $ CSLConstList# papszOptions,
242 GDALProgressFunc pfnProgress,
243 void *pProgressData)
244 {
245 // Check destination dataset,
246 NGWAPIcxx . . $ NGWAPI/::Uricxx . . $ NGWAPI/Uri# stUri = NGWAPIcxx . . $ NGWAPI/::ParseUricxx . . $ NGWAPI/ParseUri(5befab2a859ccef).(pszFilename);
247 CPLErrorReset();
248 if (stUri.osPrefixcxx . . $ NGWAPI/Uri#osPrefix. != "NGW")
249 {
250 CPLError(CE_Failure, CPLE_NotSupportedcxx . . $ `port/cpl_error.h:118:9`!, "Unsupported name %s",
251 pszFilename);
252 return nullptr;
253 }
254
255 bool bCloseDS = false;
256 stdcxx . . $ std/::string osFilename;
257
258 // Check if source GDALDataset is tiff.
259 if (EQUALcxx . . $ `port/cpl_port.h:532:9`!(poSrcDS->GetDriverName(), "GTiff") == FALSEcxx . . $ `port/cpl_port.h:1180:9`!)
260 {
261 GDALDrivercxx . . $ GDALDriver# *poDriver = GetGDALDriverManager()->GetDriverByNamecxx . . $ GDALDriverManager#GetDriverByName(715d9ac900aae6d5).("GTiff");
262 // Compress to minimize network transfer.
263 const char *apszOptions[] = {"COMPRESS=LZW", "NUM_THREADS=ALL_CPUS",
264 nullptr};
265 stdcxx . . $ std/::string osTempFilename = CPLGenerateTempFilenameSafe("ngw_tmp");
266 osTempFilename += ".tif";
267 GDALDatasetcxx . . $ GDALDataset# *poTmpDS = poDriver->CreateCopycxx . . $ GDALDriver#CreateCopy(8d8ece3624d4575).(
268 osTempFilename.c_str(), poSrcDS, bStrict,
269 const_cast<char **>(apszOptions), pfnProgress, pProgressData);
270
271 if (poTmpDS != nullptr)
272 {
273 bCloseDS = true;
274 osFilename = stdcxx . . $ std/::move(osTempFilename);
275 poSrcDS = poTmpDS;
276 }
277 else
278 {
279 CPLError(CE_Failure, CPLE_NotSupportedcxx . . $ `port/cpl_error.h:118:9`!,
280 "NGW driver doesn't support %s source raster.",
281 poSrcDS->GetDriverNamecxx . . $ GDALDataset#GetDriverName(a9f41ea0e82d88cf).());
282 return nullptr;
283 }
284 }
285
286 if (osFilename.empty())
287 {
288 // Check if source tiff is local file.
289 CPLStringList oaFiles(poSrcDS->GetFileListcxx . . $ GDALDataset#GetFileList(de5739791ae7584).());
290 for (int i = 0; i < oaFiles.size(); ++i)
291 {
292 // Check extension tif
293 const stdcxx . . $ std/::string osExt = CPLGetExtensionSafe(oaFiles[i]);
294 if (EQUALNcxx . . $ `port/cpl_port.h:530:9`!(osExt.c_str(), "tif", 3))
295 {
296 osFilename = oaFiles[i];
297 break;
298 }
299 }
300 }
301
302 // Check bands count.
303 auto nBands = poSrcDS->GetRasterCountcxx . . $ GDALDataset#GetRasterCount(455f465bc33b4cdf).();
304 auto nDataType = poSrcDS->GetRasterBandcxx . . $ GDALDataset#GetRasterBand(b7317453d4fdb323).(1)->GetRasterDataTypecxx . . $ GDALRasterBand#GetRasterDataType(67b7c31f6dead7f).();
305
306 if (bCloseDS)
307 {
308 delete poSrcDS;
309 }
310
311 stdcxx . . $ std/::string osKey = CSLFetchNameValueDef(papszOptions, "KEY", "");
312 stdcxx . . $ std/::string osDesc = CSLFetchNameValueDef(papszOptions, "DESCRIPTION", "");
313 stdcxx . . $ std/::string osUserPwd = CSLFetchNameValueDef(
314 papszOptions, "USERPWD", CPLGetConfigOption("NGW_USERPWD", ""));
315 stdcxx . . $ std/::string osStyleName =
316 CSLFetchNameValueDef(papszOptions, "RASTER_STYLE_NAME", "");
317
318 stdcxx . . $ std/::string osConnectTimeout =
319 CSLFetchNameValueDef(papszOptions, "CONNECTTIMEOUT",
320 CPLGetConfigOption("NGW_CONNECTTIMEOUT", ""));
321 stdcxx . . $ std/::string osTimeout = CSLFetchNameValueDef(
322 papszOptions, "TIMEOUT", CPLGetConfigOption("NGW_TIMEOUT", ""));
323 stdcxx . . $ std/::string osRetryCount = CSLFetchNameValueDef(
324 papszOptions, "MAX_RETRY", CPLGetConfigOption("NGW_MAX_RETRY", ""));
325 stdcxx . . $ std/::string osRetryDelay = CSLFetchNameValueDef(
326 papszOptions, "RETRY_DELAY", CPLGetConfigOption("NGW_RETRY_DELAY", ""));
327
328 // Send file
329 auto aosHTTPOptions = GetHeaderscxx . . $ GetHeaders(fb7086751aed8ae6).(osUserPwd, osConnectTimeout, osTimeout,
330 osRetryCount, osRetryDelay);
331 CPLJSONObjectcxx . . $ CPLJSONObject# oFileJson =
332 NGWAPIcxx . . $ NGWAPI/::UploadFilecxx . . $ NGWAPI/UploadFile(758a07fc57bd43bf).(stUri.osAddresscxx . . $ NGWAPI/Uri#osAddress., osFilename, aosHTTPOptions,
333 pfnProgress, pProgressData);
334
335 if (bCloseDS) // Delete temp tiff file.
336 {
337 VSIUnlink(osFilename.c_str());
338 }
339
340 if (!oFileJson.IsValidcxx . . $ CPLJSONObject#IsValid(50ce9a9e25b4a850).())
341 {
342 return nullptr;
343 }
344
345 CPLJSONArraycxx . . $ CPLJSONArray# oUploadMeta = oFileJson.GetArraycxx . . $ CPLJSONObject#GetArray(e4e991b8a8b784ce).("upload_meta");
346 if (!oUploadMeta.IsValidcxx . . $ CPLJSONObject#IsValid(50ce9a9e25b4a850).() || oUploadMeta.Sizecxx . . $ CPLJSONArray#Size(455f465bc33b4cdf).() == 0)
347 {
348 CPLError(CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "Get unexpected response: %s.",
349 oFileJson.Formatcxx . . $ CPLJSONObject#Format(97b6c23b733e4099).(CPLJSONObjectcxx . . $ CPLJSONObject#::PrettyFormatcxx . . $ CPLJSONObject#PrettyFormat#::Plaincxx . . $ CPLJSONObject#PrettyFormat#Plain.).c_str());
350 return nullptr;
351 }
352
353 // Create raster layer
354 // Create payload
355 CPLJSONObjectcxx . . $ CPLJSONObject# oPayloadRastercxx . . $ CPLJSONObject#CPLJSONObject(49f6e7a06ebc5aa8).;
356 CPLJSONObjectcxx . . $ CPLJSONObject# oResourcecxx . . $ CPLJSONObject#CPLJSONObject(2303eda281a0fa9b).("resource", oPayloadRaster);
357 oResource.Addcxx . . $ CPLJSONObject#Add(32373b8560f77290).("cls", "raster_layer");
358 oResource.Addcxx . . $ CPLJSONObject#Add(c3ca1c130ce09c52).("display_name", stUri.osNewResourceNamecxx . . $ NGWAPI/Uri#osNewResourceName.);
359 if (!osKey.empty())
360 {
361 oResource.Addcxx . . $ CPLJSONObject#Add(c3ca1c130ce09c52).("keyname", osKey);
362 }
363
364 if (!osDesc.empty())
365 {
366 oResource.Addcxx . . $ CPLJSONObject#Add(c3ca1c130ce09c52).("description", osDesc);
367 }
368
369 CPLJSONObjectcxx . . $ CPLJSONObject# oParentcxx . . $ CPLJSONObject#CPLJSONObject(2303eda281a0fa9b).("parent", oResource);
370 oParent.Addcxx . . $ CPLJSONObject#Add(412d11940ded42ad).("id", atoicxx . . $ atoi(f5ecf3191ed0cd93).(stUri.osResourceIdcxx . . $ NGWAPI/Uri#osResourceId..c_str()));
371
372 CPLJSONObjectcxx . . $ CPLJSONObject# oRasterLayercxx . . $ CPLJSONObject#CPLJSONObject(2303eda281a0fa9b).("raster_layer", oPayloadRaster);
373 oRasterLayer.Addcxx . . $ CPLJSONObject#Add(2303eda281a0fa9b).("source", oUploadMeta[cxx . . $ CPLJSONArray#`operator[]`(94ae901e802de848).0]);
374
375 CPLJSONObjectcxx . . $ CPLJSONObject# oSrscxx . . $ CPLJSONObject#CPLJSONObject(2303eda281a0fa9b).("srs", oRasterLayer);
376 oSrs.Addcxx . . $ CPLJSONObject#Add(412d11940ded42ad).("id", 3857); // Now only Web Mercator supported.
377
378 auto osRasterResourceId = NGWAPIcxx . . $ NGWAPI/::CreateResourcecxx . . $ NGWAPI/CreateResource(78a24f53bf4760fc).(
379 stUri.osAddresscxx . . $ NGWAPI/Uri#osAddress.,
380 oPayloadRaster.Formatcxx . . $ CPLJSONObject#Format(97b6c23b733e4099).(CPLJSONObjectcxx . . $ CPLJSONObject#::PrettyFormatcxx . . $ CPLJSONObject#PrettyFormat#::Plaincxx . . $ CPLJSONObject#PrettyFormat#Plain.),
381 aosHTTPOptions);
382 if (osRasterResourceId == "-1")
383 {
384 return nullptr;
385 }
386
387 // Create raster style
388 CPLJSONObjectcxx . . $ CPLJSONObject# oPayloadRasterStylecxx . . $ CPLJSONObject#CPLJSONObject(49f6e7a06ebc5aa8).;
389 CPLJSONObjectcxx . . $ CPLJSONObject# oResourceStylecxx . . $ CPLJSONObject#CPLJSONObject(2303eda281a0fa9b).("resource", oPayloadRasterStyle);
390
391 // NGW v3.1 supported different raster types: 1 band and 16/32 bit, RGB/RGBA
392 // rasters and etc.
393 // For RGB/RGBA rasters we can create default raster_style.
394 // For other types - qml style file path is mandatory.
395 stdcxx . . $ std/::string osQMLPath =
396 CSLFetchNameValueDef(papszOptions, "RASTER_QML_PATH", "");
397
398 bool bCreateStyle = true;
399 if (osQMLPath.empty())
400 {
401 if ((nBands == 3 || nBands == 4) && nDataType == GDT_UInt8)
402 {
403 oResourceStyle.Addcxx . . $ CPLJSONObject#Add(32373b8560f77290).("cls", "raster_style");
404 }
405 else
406 {
407 CPLError(CE_Warning, CPLE_NotSupportedcxx . . $ `port/cpl_error.h:118:9`!,
408 "Default NGW raster style supports only 3 (RGB) or 4 "
409 "(RGBA) and 8 "
410 "bit byte bands. Raster has %d bands and data type %s",
411 nBands, GDALGetDataTypeName(nDataType));
412 bCreateStyle = false;
413 }
414 }
415 else
416 {
417 oResourceStyle.Addcxx . . $ CPLJSONObject#Add(32373b8560f77290).("cls", "qgis_raster_style");
418
419 // Upload QML file
420 oFileJson =cxx . . $ CPLJSONObject#`operator=`(13e40416bd67c8f8).
421 NGWAPIcxx . . $ NGWAPI/::UploadFilecxx . . $ NGWAPI/UploadFile(758a07fc57bd43bf).(stUri.osAddresscxx . . $ NGWAPI/Uri#osAddress., osQMLPath, aosHTTPOptions,
422 pfnProgress, pProgressData);
423 oUploadMeta =cxx . . $ CPLJSONArray#`operator=`(e2a533dd4439fd59). oFileJson.GetArraycxx . . $ CPLJSONObject#GetArray(e4e991b8a8b784ce).("upload_meta");
424 if (!oUploadMeta.IsValidcxx . . $ CPLJSONObject#IsValid(50ce9a9e25b4a850).() || oUploadMeta.Sizecxx . . $ CPLJSONArray#Size(455f465bc33b4cdf).() == 0)
425 {
426 CPLError(
427 CE_Failure, CPLE_AppDefinedcxx . . $ `port/cpl_error.h:108:9`!, "Get unexpected response: %s.",
428 oFileJson.Formatcxx . . $ CPLJSONObject#Format(97b6c23b733e4099).(CPLJSONObjectcxx . . $ CPLJSONObject#::PrettyFormatcxx . . $ CPLJSONObject#PrettyFormat#::Plaincxx . . $ CPLJSONObject#PrettyFormat#Plain.).c_str());
429 return nullptr;
430 }
431 CPLJSONObjectcxx . . $ CPLJSONObject# oQGISRasterStylecxx . . $ CPLJSONObject#CPLJSONObject(2303eda281a0fa9b).("qgis_raster_style",
432 oPayloadRasterStyle);
433 oQGISRasterStyle.Addcxx . . $ CPLJSONObject#Add(2303eda281a0fa9b).("file_upload", oUploadMeta[cxx . . $ CPLJSONArray#`operator[]`(94ae901e802de848).0]);
434 }
435
436 if (bCreateStyle)
437 {
438 if (osStyleName.empty())
439 {
440 osStyleName = stUri.osNewResourceNamecxx . . $ NGWAPI/Uri#osNewResourceName.;
441 }
442 oResourceStyle.Addcxx . . $ CPLJSONObject#Add(c3ca1c130ce09c52).("display_name", osStyleName);
443 CPLJSONObjectcxx . . $ CPLJSONObject# oParentRastercxx . . $ CPLJSONObject#CPLJSONObject(2303eda281a0fa9b).("parent", oResourceStyle);
444 oParentRaster.Addcxx . . $ CPLJSONObject#Add(412d11940ded42ad).("id", atoicxx . . $ atoi(f5ecf3191ed0cd93).(osRasterResourceId.c_str()));
445
446 auto osStyleResourceId = NGWAPIcxx . . $ NGWAPI/::CreateResourcecxx . . $ NGWAPI/CreateResource(78a24f53bf4760fc).(
447 stUri.osAddresscxx . . $ NGWAPI/Uri#osAddress.,
448 oPayloadRasterStyle.Formatcxx . . $ CPLJSONObject#Format(97b6c23b733e4099).(CPLJSONObjectcxx . . $ CPLJSONObject#::PrettyFormatcxx . . $ CPLJSONObject#PrettyFormat#::Plaincxx . . $ CPLJSONObject#PrettyFormat#Plain.),
449 aosHTTPOptions);
450 if (osStyleResourceId == "-1")
451 {
452 return nullptr;
453 }
454 }
455
456 OGRNGWDatasetcxx . . $ OGRNGWDataset# *poDS = new OGRNGWDatasetcxx . . $ OGRNGWDataset#OGRNGWDataset(49f6e7a06ebc5aa8).();
457
458 if (!poDS->Opencxx . . $ OGRNGWDataset#Open(80ee0aecd9a12254).(stUri.osAddresscxx . . $ NGWAPI/Uri#osAddress., osRasterResourceId, papszOptions, true,
459 GDAL_OF_RASTERcxx . . $ `gcore/gdal.h:1125:9`!))
460 {
461 delete poDS;
462 poDS = nullptr;
463 }
464
465 return poDS;
466 }
467
468 /*
469 * RegisterOGRNGW()
470 */
471
472 void RegisterOGRNGWcxx . . $ RegisterOGRNGW(49f6e7a06ebc5aa8).()
473 {
474 if (GDALGetDriverByName("NGW") != nullptr)
475 {
476 return;
477 }
478
479 GDALDrivercxx . . $ GDALDriver# *poDriver = new GDALDrivercxx . . $ GDALDriver#GDALDriver(49f6e7a06ebc5aa8).();
480
481 poDriver->SetDescriptioncxx . . $ GDALMajorObject#SetDescription(85c52e162fed56f9).("NGW");
482 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DMD_LONGNAMEcxx . . $ `gcore/gdal.h:443:9`!, "NextGIS Web");
483 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_RASTERcxx . . $ `gcore/gdal.h:678:9`!, "YES");
484 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_VECTORcxx . . $ `gcore/gdal.h:682:9`!, "YES");
485 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_CREATE_LAYERcxx . . $ `gcore/gdal.h:691:9`!, "YES");
486 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_DELETE_LAYERcxx . . $ `gcore/gdal.h:696:9`!, "YES");
487 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_CREATE_FIELDcxx . . $ `gcore/gdal.h:701:9`!, "YES");
488 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_DELETE_FIELDcxx . . $ `gcore/gdal.h:706:9`!, "YES");
489 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DMD_SUBDATASETScxx . . $ `gcore/gdal.h:565:9`!, "YES");
490 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DMD_HELPTOPICcxx . . $ `gcore/gdal.h:446:9`!, "drivers/vector/ngw.html");
491 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DMD_CONNECTION_PREFIXcxx . . $ `gcore/gdal.h:457:9`!, "NGW:");
492 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_Z_GEOMETRIEScxx . . $ `gcore/gdal.h:780:9`!, "YES");
493 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DMD_SUPPORTED_SQL_DIALECTScxx . . $ `gcore/gdal.h:991:9`!,
494 "NATIVE OGRSQL SQLITE");
495
496 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DMD_CREATIONDATATYPEScxx . . $ `gcore/gdal.h:513:9`!, "Byte");
497 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DMD_ALTER_FIELD_DEFN_FLAGScxx . . $ `gcore/gdal.h:732:9`!,
498 "Name AlternativeName Domain");
499 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DMD_CREATION_FIELD_DEFN_FLAGScxx . . $ `gcore/gdal.h:555:9`!,
500 "AlternativeName Domain");
501 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_CREATECOPYcxx . . $ `gcore/gdal.h:623:9`!, "YES");
502 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_FIELD_DOMAINScxx . . $ `gcore/gdal.h:848:9`!, "YES");
503
504 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(
505 GDAL_DMD_OPENOPTIONLISTcxx . . $ `gcore/gdal.h:509:9`!,
506 "<OpenOptionList>"
507 " <Option name='USERPWD' scope='raster,vector' type='string' "
508 "description='Username and password, separated by colon'/>"
509 " <Option name='PAGE_SIZE' scope='vector' type='integer' "
510 "description='Limit feature count while fetching from server. Default "
511 "value is -1 - no limit' default='-1'/>"
512 " <Option name='BATCH_SIZE' scope='vector' type='integer' "
513 "description='Size of feature insert and update operations cache "
514 "before send to server. If batch size is -1 batch mode is disabled' "
515 "default='-1'/>"
516 " <Option name='NATIVE_DATA' scope='vector' type='boolean' "
517 "description='Whether to store the native Json representation of "
518 "extensions key. If EXTENSIONS not set or empty, NATIVE_DATA defaults "
519 "to NO' default='NO'/>"
520 " <Option name='CACHE_EXPIRES' scope='raster' type='integer' "
521 "description='Time in seconds cached files will stay valid. If cached "
522 "file expires it is deleted when maximum size of cache is reached. "
523 "Also expired file can be overwritten by the new one from web' "
524 "default='604800'/>"
525 " <Option name='CACHE_MAX_SIZE' scope='raster' type='integer' "
526 "description='The cache maximum size in bytes. If cache reached "
527 "maximum size, expired cached files will be deleted' "
528 "default='67108864'/>"
529 " <Option name='JSON_DEPTH' scope='raster,vector' type='integer' "
530 "description='The depth of json response that can be parsed. If depth "
531 "is greater than this value, parse error occurs' default='32'/>"
532 " <Option name='EXTENSIONS' scope='vector' type='string' "
533 "description='Comma separated extensions list. Available are "
534 "description and attachment' default=''/>"
535 " <Option name='CONNECTTIMEOUT' scope='raster,vector' type='integer' "
536 "description='Maximum delay for the connection to be established "
537 "before "
538 "being aborted in seconds'/>"
539 " <Option name='TIMEOUT' scope='raster,vector' type='integer' "
540 "description='Maximum delay for the whole request to complete before "
541 "being aborted in seconds'/>"
542 " <Option name='MAX_RETRY' scope='raster,vector' type='integer' "
543 "description='Maximum number of retry attempts if a 429, 502, 503 or "
544 "504 "
545 "HTTP error occurs'/>"
546 " <Option name='RETRY_DELAY' scope='raster,vector' type='integer' "
547 "description='Number of seconds between retry attempts'/>"
548 "</OpenOptionList>");
549
550 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(
551 GDAL_DMD_CREATIONOPTIONLISTcxx . . $ `gcore/gdal.h:464:9`!,
552 "<CreationOptionList>"
553 " <Option name='KEY' scope='raster,vector' type='string' "
554 "description='Key value. Must be unique in whole NextGIS Web "
555 "instance'/>"
556 " <Option name='DESCRIPTION' scope='raster,vector' type='string' "
557 "description='Resource description'/>"
558 " <Option name='RASTER_STYLE_NAME' scope='raster' type='string' "
559 "description='Raster layer style name'/>"
560 " <Option name='USERPWD' scope='raster,vector' type='string' "
561 "description='Username and password, separated by colon'/>"
562 " <Option name='PAGE_SIZE' scope='vector' type='integer' "
563 "description='Limit feature count while fetching from server. Default "
564 "value is -1 - no limit' default='-1'/>"
565 " <Option name='BATCH_SIZE' scope='vector' type='integer' "
566 "description='Size of feature insert and update operations cache "
567 "before send to server. If batch size is -1 batch mode is disabled' "
568 "default='-1'/>"
569 " <Option name='NATIVE_DATA' scope='vector' type='boolean' "
570 "description='Whether to store the native Json representation of "
571 "extensions key. If EXTENSIONS not set or empty, NATIVE_DATA defaults "
572 "to NO' default='NO'/>"
573 " <Option name='CACHE_EXPIRES' scope='raster' type='integer' "
574 "description='Time in seconds cached files will stay valid. If cached "
575 "file expires it is deleted when maximum size of cache is reached. "
576 "Also expired file can be overwritten by the new one from web' "
577 "default='604800'/>"
578 " <Option name='CACHE_MAX_SIZE' scope='raster' type='integer' "
579 "description='The cache maximum size in bytes. If cache reached "
580 "maximum size, expired cached files will be deleted' "
581 "default='67108864'/>"
582 " <Option name='JSON_DEPTH' scope='raster,vector' type='integer' "
583 "description='The depth of json response that can be parsed. If depth "
584 "is greater than this value, parse error occurs' default='32'/>"
585 " <Option name='RASTER_QML_PATH' scope='raster' type='string' "
586 "description='Raster QMS style path'/>"
587 " <Option name='EXTENSIONS' scope='vector' type='string' "
588 "description='Comma separated extensions list. Available are "
589 "description and attachment' default=''/>"
590 " <Option name='CONNECTTIMEOUT' scope='raster,vector' type='integer' "
591 "description='Maximum delay for the connection to be established "
592 "before "
593 "being aborted in seconds'/>"
594 " <Option name='TIMEOUT' scope='raster,vector' type='integer' "
595 "description='Maximum delay for the whole request to complete before "
596 "being aborted in seconds'/>"
597 " <Option name='MAX_RETRY' scope='raster,vector' type='integer' "
598 "description='Maximum number of retry attempts if a 429, 502, 503 or "
599 "504 "
600 "HTTP error occurs'/>"
601 " <Option name='RETRY_DELAY' scope='raster,vector' type='integer' "
602 "description='Number of seconds between retry attempts'/>"
603 "</CreationOptionList>");
604
605 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(
606 GDAL_DS_LAYER_CREATIONOPTIONLISTcxx . . $ `gcore/gdal.h:1330:9`!,
607 "<LayerCreationOptionList>"
608 " <Option name='OVERWRITE' type='boolean' description='Whether to "
609 "overwrite an existing table with the layer name to be created' "
610 "default='NO'/>"
611 " <Option name='KEY' type='string' description='Key value. Must be "
612 "unique in whole NextGIS Web instance'/>"
613 " <Option name='DESCRIPTION' type='string' description='Resource "
614 "description'/>"
615 "</LayerCreationOptionList>");
616
617 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(
618 GDAL_DMD_CREATIONFIELDDATATYPEScxx . . $ `gcore/gdal.h:518:9`!,
619 "Integer Integer64 Real String Date DateTime Time");
620 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DMD_CREATION_FIELD_DEFN_FLAGScxx . . $ `gcore/gdal.h:555:9`!,
621 "AlternativeName");
622 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_NOTNULL_GEOMFIELDScxx . . $ `gcore/gdal.h:757:9`!, "YES");
623 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_MULTIPLE_VECTOR_LAYERScxx . . $ `gcore/gdal.h:831:9`!, "YES");
624 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DCAP_RENAME_LAYERScxx . . $ `gcore/gdal.h:940:9`!, "YES");
625 poDriver->SetMetadataItemcxx . . $ GDALDriver#SetMetadataItem(216fc8eb9053a851).(GDAL_DMD_CREATION_FIELD_DOMAIN_TYPEScxx . . $ `gcore/gdal.h:951:9`!, "Coded");
626
627 poDriver->pfnOpencxx . . $ GDALDriver#pfnOpen. = OGRNGWDriverOpencxx . . $ OGRNGWDriverOpen(905b7966ba8c1649).;
628 poDriver->pfnIdentifycxx . . $ GDALDriver#pfnIdentify. = OGRNGWDriverIdentifycxx . . $ OGRNGWDriverIdentify(48f695ac6b30cd84).;
629 poDriver->pfnCreatecxx . . $ GDALDriver#pfnCreate. = OGRNGWDriverCreatecxx . . $ OGRNGWDriverCreate(2a509bdc7a404bec).;
630 poDriver->pfnCreateCopycxx . . $ GDALDriver#pfnCreateCopy. = OGRNGWDriverCreateCopycxx . . $ OGRNGWDriverCreateCopy(8d8ece3624d4575).;
631 poDriver->pfnDeletecxx . . $ GDALDriver#pfnDelete. = OGRNGWDriverDeletecxx . . $ OGRNGWDriverDelete(80d06f1dc84b2c8f).;
632 poDriver->pfnRenamecxx . . $ GDALDriver#pfnRename. = OGRNGWDriverRenamecxx . . $ OGRNGWDriverRename(d109fabb5fb87841).;
633
634 GetGDALDriverManager()->RegisterDrivercxx . . $ GDALDriverManager#RegisterDriver(ed1dabcc01594d64).(poDriver);
635 }