QGIS API Documentation 4.5.0-Master (3b5d115045b)
Loading...
Searching...
No Matches
qgsarcgisrestutils.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsarcgisrestutils.cpp
3 ----------------------
4 begin : Nov 25, 2015
5 copyright : (C) 2015 by Sandro Mani
6 email : manisandro@gmail.com
7***************************************************************************
8* *
9* This program is free software; you can redistribute it and/or modify *
10* it under the terms of the GNU General Public License as published by *
11* the Free Software Foundation; either version 2 of the License, or *
12* (at your option) any later version. *
13* *
14***************************************************************************/
15
16#include "qgsarcgisrestutils.h"
17
19#include "qgscircularstring.h"
26#include "qgscolorrampimpl.h"
27#include "qgscurve.h"
29#include "qgsfields.h"
30#include "qgsgeometryengine.h"
32#include "qgslinestring.h"
33#include "qgslinesymbollayer.h"
34#include "qgslogger.h"
35#include "qgsmulticurve.h"
36#include "qgsmultilinestring.h"
37#include "qgsmultipoint.h"
38#include "qgsmultipolygon.h"
39#include "qgsmultisurface.h"
40#include "qgspallabeling.h"
41#include "qgspolygon.h"
43#include "qgsrectangle.h"
44#include "qgsrenderer.h"
47#include "qgssymbol.h"
49#include "qgssymbollayer.h"
50#include "qgsvariantutils.h"
52
53#include <QRegularExpression>
54#include <QString>
55#include <QUrl>
56
57#include "moc_qgsarcgisrestutils.cpp"
58
59using namespace Qt::StringLiterals;
60
61QMetaType::Type QgsArcGisRestUtils::convertFieldType( const QString &esriFieldType )
62{
63 if ( esriFieldType == "esriFieldTypeInteger"_L1 )
64 return QMetaType::Type::LongLong;
65 if ( esriFieldType == "esriFieldTypeSmallInteger"_L1 )
66 return QMetaType::Type::Int;
67 if ( esriFieldType == "esriFieldTypeDouble"_L1 )
68 return QMetaType::Type::Double;
69 if ( esriFieldType == "esriFieldTypeSingle"_L1 )
70 return QMetaType::Type::Double;
71 if ( esriFieldType == "esriFieldTypeString"_L1 )
72 return QMetaType::Type::QString;
73 if ( esriFieldType == "esriFieldTypeDate"_L1 )
74 return QMetaType::Type::QDateTime;
75 if ( esriFieldType == "esriFieldTypeGeometry"_L1 )
76 return QMetaType::Type::UnknownType; // Geometry column should not appear as field
77 if ( esriFieldType == "esriFieldTypeOID"_L1 )
78 return QMetaType::Type::LongLong;
79 if ( esriFieldType == "esriFieldTypeBlob"_L1 )
80 return QMetaType::Type::QByteArray;
81 if ( esriFieldType == "esriFieldTypeGlobalID"_L1 )
82 return QMetaType::Type::QString;
83 if ( esriFieldType == "esriFieldTypeRaster"_L1 )
84 return QMetaType::Type::QByteArray;
85 if ( esriFieldType == "esriFieldTypeGUID"_L1 )
86 return QMetaType::Type::QString;
87 if ( esriFieldType == "esriFieldTypeXML"_L1 )
88 return QMetaType::Type::QString;
89 return QMetaType::Type::UnknownType;
90}
91
93{
94 // http://resources.arcgis.com/en/help/arcobjects-cpp/componenthelp/index.html#//000w0000001p000000
95 if ( esriGeometryType == "esriGeometryNull"_L1 )
97 else if ( esriGeometryType == "esriGeometryPoint"_L1 )
99 else if ( esriGeometryType == "esriGeometryMultipoint"_L1 )
101 else if ( esriGeometryType == "esriGeometryPolyline"_L1 )
103 else if ( esriGeometryType == "esriGeometryPolygon"_L1 )
105 else if ( esriGeometryType == "esriGeometryEnvelope"_L1 )
107 // Unsupported (either by qgis, or format unspecified by the specification)
108 // esriGeometryCircularArc
109 // esriGeometryEllipticArc
110 // esriGeometryBezier3Curve
111 // esriGeometryPath
112 // esriGeometryRing
113 // esriGeometryLine
114 // esriGeometryAny
115 // esriGeometryMultiPatch
116 // esriGeometryTriangleStrip
117 // esriGeometryTriangleFan
118 // esriGeometryRay
119 // esriGeometrySphere
120 // esriGeometryTriangles
121 // esriGeometryBag
123}
124
125std::unique_ptr< QgsPoint > QgsArcGisRestUtils::convertPoint( const QVariantList &coordList, Qgis::WkbType pointType )
126{
127 const int nCoords = static_cast< int >( coordList.size() );
128 if ( nCoords < 2 )
129 return nullptr;
130 bool xok = false, yok = false;
131 const double x = coordList[0].toDouble( &xok );
132 const double y = coordList[1].toDouble( &yok );
133 if ( !xok || !yok )
134 return nullptr;
135 const bool hasZ = QgsWkbTypes::hasZ( pointType );
136 const double z = hasZ && nCoords >= 3 ? coordList[2].toDouble() : std::numeric_limits< double >::quiet_NaN();
137
138 // if point has just M but not Z, then the point dimension list will only have X, Y, M, otherwise it will have X, Y, Z, M
139 const double m = QgsWkbTypes::hasM( pointType ) && ( ( hasZ && nCoords >= 4 ) || ( !hasZ && nCoords >= 3 ) ) ? coordList[hasZ ? 3 : 2].toDouble() : std::numeric_limits< double >::quiet_NaN();
140 return std::make_unique< QgsPoint >( pointType, x, y, z, m );
141}
142
143std::unique_ptr< QgsCircularString > QgsArcGisRestUtils::convertCircularString( const QVariantMap &curveData, Qgis::WkbType pointType, const QgsPoint &startPoint )
144{
145 const QVariantList coordsList = curveData[u"c"_s].toList();
146 if ( coordsList.isEmpty() )
147 return nullptr;
148 const int coordsListSize = static_cast< int >( coordsList.size() );
149
150 QVector<QgsPoint> points;
151 points.reserve( coordsListSize + 1 );
152 points.append( startPoint );
153
154 for ( int i = 0; i < coordsListSize - 1; )
155 {
156 // first point is end point, second is point on curve
157 // i.e. the opposite to what QGIS requires!
158 std::unique_ptr< QgsPoint > endPoint( convertPoint( coordsList.at( i ).toList(), pointType ) );
159 if ( !endPoint )
160 return nullptr;
161 i++;
162 std::unique_ptr< QgsPoint > interiorPoint( convertPoint( coordsList.at( i ).toList(), pointType ) );
163 if ( !interiorPoint )
164 return nullptr;
165 i++;
166 points << *interiorPoint;
167 points << *endPoint;
168 }
169 auto curve = std::make_unique< QgsCircularString>();
170 curve->setPoints( points );
171 return curve;
172}
173
174std::unique_ptr< QgsCurve > QgsArcGisRestUtils::convertCompoundCurve( const QVariantList &curvesList, Qgis::WkbType pointType )
175{
176 // [[6,3],[5,3],{"b":[[3,2],[6,1],[2,4]]},[1,2],{"c": [[3,3],[1,4]]}]
177 auto compoundCurve = std::make_unique< QgsCompoundCurve >();
178
179 QVector< double > lineX;
180 QVector< double > lineY;
181 QVector< double > lineZ;
182 QVector< double > lineM;
183 const int maxCurveListSize = static_cast< int >( curvesList.size() );
184 lineX.resize( maxCurveListSize );
185 lineY.resize( maxCurveListSize );
186
187 const bool hasZ = QgsWkbTypes::hasZ( pointType );
188 if ( hasZ )
189 lineZ.resize( maxCurveListSize );
190 const bool hasM = QgsWkbTypes::hasM( pointType );
191 if ( hasM )
192 lineM.resize( maxCurveListSize );
193
194 double *outLineX = lineX.data();
195 double *outLineY = lineY.data();
196 double *outLineZ = lineZ.data();
197 double *outLineM = lineM.data();
198 int actualLineSize = 0;
199
200 bool xok = false;
201 bool yok = false;
202
203 int curveListIndex = 0;
204 for ( const QVariant &curveData : curvesList )
205 {
206 if ( curveData.userType() == QMetaType::Type::QVariantList )
207 {
208 const QVariantList coordList = curveData.toList();
209 const int nCoords = static_cast< int >( coordList.size() );
210 if ( nCoords < 2 )
211 return nullptr;
212
213 const double x = coordList[0].toDouble( &xok );
214 const double y = coordList[1].toDouble( &yok );
215 if ( !xok || !yok )
216 return nullptr;
217
218 actualLineSize++;
219 *outLineX++ = x;
220 *outLineY++ = y;
221 if ( hasZ )
222 {
223 *outLineZ++ = nCoords >= 3 ? coordList[2].toDouble() : std::numeric_limits< double >::quiet_NaN();
224 }
225
226 if ( hasM )
227 {
228 // if point has just M but not Z, then the point dimension list will only have X, Y, M, otherwise it will have X, Y, Z, M
229 *outLineM++ = ( ( hasZ && nCoords >= 4 ) || ( !hasZ && nCoords >= 3 ) ) ? coordList[hasZ ? 3 : 2].toDouble() : std::numeric_limits< double >::quiet_NaN();
230 }
231 }
232 else if ( curveData.userType() == QMetaType::Type::QVariantMap )
233 {
234 // The last point of the linestring is the start point of this circular string
235 QgsPoint lastLineStringPoint;
236 if ( actualLineSize > 0 )
237 {
238 lastLineStringPoint
239 = QgsPoint( lineX.at( actualLineSize - 1 ), lineY.at( actualLineSize - 1 ), hasZ ? lineZ.at( actualLineSize - 1 ) : std::numeric_limits< double >::quiet_NaN(), hasM ? lineM.at( actualLineSize - 1 ) : std::numeric_limits< double >::quiet_NaN() );
240 }
241 std::unique_ptr< QgsCircularString > circularString( convertCircularString( curveData.toMap(), pointType, lastLineStringPoint ) );
242 if ( !circularString )
243 {
244 return nullptr;
245 }
246
247 if ( actualLineSize > 0 )
248 {
249 lineX.resize( actualLineSize );
250 lineY.resize( actualLineSize );
251 if ( hasZ )
252 lineZ.resize( actualLineSize );
253 if ( hasM )
254 lineM.resize( actualLineSize );
255
256 compoundCurve->addCurve( new QgsLineString( lineX, lineY, lineZ, lineM ) );
257 lineX.resize( maxCurveListSize - curveListIndex );
258 lineY.resize( maxCurveListSize - curveListIndex );
259 if ( hasZ )
260 lineZ.resize( maxCurveListSize - curveListIndex );
261 if ( hasM )
262 lineM.resize( maxCurveListSize - curveListIndex );
263 outLineX = lineX.data();
264 outLineY = lineY.data();
265 outLineZ = lineZ.data();
266 outLineM = lineM.data();
267 }
268
269 // If the previous curve had less than two points, remove it
270 if ( compoundCurve->curveAt( compoundCurve->nCurves() - 1 )->nCoordinates() < 2 )
271 compoundCurve->removeCurve( compoundCurve->nCurves() - 1 );
272
273 const QgsPoint endPointCircularString = circularString->endPoint();
274 compoundCurve->addCurve( circularString.release() );
275
276 // Prepare a new line string
277 actualLineSize = 1;
278 *outLineX++ = endPointCircularString.x();
279 *outLineY++ = endPointCircularString.y();
280 if ( hasZ )
281 *outLineZ++ = endPointCircularString.z();
282 if ( hasM )
283 *outLineM++ = endPointCircularString.m();
284 }
285 curveListIndex++;
286 }
287
288 if ( actualLineSize == 1 && compoundCurve->nCurves() > 0 )
289 {
290 const QgsCurve *finalCurve = compoundCurve->curveAt( compoundCurve->nCurves() - 1 );
291 const QgsPoint finalCurveEndPoint = finalCurve->endPoint();
292 if ( qgsDoubleNear( finalCurveEndPoint.x(), lineX.at( 0 ) )
293 && qgsDoubleNear( finalCurveEndPoint.y(), lineY.at( 0 ) )
294 && ( !hasZ || qgsDoubleNear( finalCurveEndPoint.z(), lineZ.at( 0 ) ) )
295 && ( !hasM || qgsDoubleNear( finalCurveEndPoint.m(), lineM.at( 0 ) ) ) )
296 {
297 actualLineSize = 0; // redundant final curve containing a duplicate vertex
298 }
299 }
300
301 if ( actualLineSize > 0 )
302 {
303 lineX.resize( actualLineSize );
304 lineY.resize( actualLineSize );
305 if ( hasZ )
306 lineZ.resize( actualLineSize );
307 if ( hasM )
308 lineM.resize( actualLineSize );
309 compoundCurve->addCurve( new QgsLineString( lineX, lineY, lineZ, lineM ) );
310 }
311
312 return compoundCurve;
313}
314
315std::unique_ptr<QgsLineString> QgsArcGisRestUtils::convertLineString( const QVariantList &curvesList, Qgis::WkbType pointType )
316{
317 auto linestring = std::make_unique< QgsLineString >();
318
319 QVector< double > lineX;
320 QVector< double > lineY;
321 QVector< double > lineZ;
322 QVector< double > lineM;
323 const int maxCurveListSize = static_cast< int >( curvesList.size() );
324 lineX.resize( maxCurveListSize );
325 lineY.resize( maxCurveListSize );
326
327 const bool hasZ = QgsWkbTypes::hasZ( pointType );
328 if ( hasZ )
329 lineZ.resize( maxCurveListSize );
330 const bool hasM = QgsWkbTypes::hasM( pointType );
331 if ( hasM )
332 lineM.resize( maxCurveListSize );
333
334 double *outLineX = lineX.data();
335 double *outLineY = lineY.data();
336 double *outLineZ = lineZ.data();
337 double *outLineM = lineM.data();
338
339 bool xok = false;
340 bool yok = false;
341
342 int actualLineSize = 0;
343 for ( const QVariant &curveData : curvesList )
344 {
345 if ( curveData.userType() == QMetaType::Type::QVariantList )
346 {
347 const QVariantList coordList = curveData.toList();
348 const int nCoords = static_cast< int >( coordList.size() );
349 if ( nCoords < 2 )
350 return nullptr;
351
352 const double x = coordList[0].toDouble( &xok );
353 const double y = coordList[1].toDouble( &yok );
354 if ( !xok || !yok )
355 return nullptr;
356
357 actualLineSize++;
358 *outLineX++ = x;
359 *outLineY++ = y;
360 if ( hasZ )
361 {
362 *outLineZ++ = nCoords >= 3 ? coordList[2].toDouble() : std::numeric_limits< double >::quiet_NaN();
363 }
364
365 if ( hasM )
366 {
367 // if point has just M but not Z, then the point dimension list will only have X, Y, M, otherwise it will have X, Y, Z, M
368 *outLineM++ = ( ( hasZ && nCoords >= 4 ) || ( !hasZ && nCoords >= 3 ) ) ? coordList[hasZ ? 3 : 2].toDouble() : std::numeric_limits< double >::quiet_NaN();
369 }
370 }
371 else
372 {
373 QgsDebugError( u"Found unexpected value when parsing ESRI json line string. Expected list, got %1"_s.arg( curveData.metaType().name() ) );
374 return nullptr;
375 }
376 }
377
378 if ( actualLineSize == 0 )
379 return nullptr;
380
381 lineX.resize( actualLineSize );
382 lineY.resize( actualLineSize );
383 if ( hasZ )
384 lineZ.resize( actualLineSize );
385 if ( hasM )
386 lineM.resize( actualLineSize );
387 return std::make_unique< QgsLineString>( lineX, lineY, lineZ, lineM );
388}
389
390std::unique_ptr< QgsPoint > QgsArcGisRestUtils::convertGeometryPoint( const QVariantMap &geometryData, Qgis::WkbType pointType )
391{
392 // {"x" : <x>, "y" : <y>, "z" : <z>, "m" : <m>}
393 bool xok = false, yok = false;
394 double x = geometryData[u"x"_s].toDouble( &xok );
395 double y = geometryData[u"y"_s].toDouble( &yok );
396 if ( !xok || !yok )
397 return nullptr;
398 double z = geometryData[u"z"_s].toDouble();
399 double m = geometryData[u"m"_s].toDouble();
400 return std::make_unique< QgsPoint >( pointType, x, y, z, m );
401}
402
403std::unique_ptr< QgsMultiPoint > QgsArcGisRestUtils::convertMultiPoint( const QVariantMap &geometryData, Qgis::WkbType pointType )
404{
405 // {"points" : [[ <x1>, <y1>, <z1>, <m1> ] , [ <x2>, <y2>, <z2>, <m2> ], ... ]}
406 const QVariantList coordsList = geometryData[u"points"_s].toList();
407
408 auto multiPoint = std::make_unique< QgsMultiPoint >();
409 multiPoint->reserve( static_cast< int >( coordsList.size() ) );
410 for ( const QVariant &coordData : coordsList )
411 {
412 const QVariantList coordList = coordData.toList();
413 std::unique_ptr< QgsPoint > p = convertPoint( coordList, pointType );
414 if ( !p )
415 {
416 continue;
417 }
418 multiPoint->addGeometry( p.release() );
419 }
420
421 // second chance -- sometimes layers are reported as multipoint but features have single
422 // point geometries. Silently handle this and upgrade to multipoint.
423 std::unique_ptr< QgsPoint > p = convertGeometryPoint( geometryData, pointType );
424 if ( p )
425 multiPoint->addGeometry( p.release() );
426
427 if ( multiPoint->numGeometries() == 0 )
428 {
429 // didn't find any points, so reset geometry to null
430 multiPoint.reset();
431 }
432 return multiPoint;
433}
434
435std::unique_ptr< QgsMultiCurve > QgsArcGisRestUtils::convertGeometryPolyline( const QVariantMap &geometryData, Qgis::WkbType pointType, bool allowCurves )
436{
437 // {"curvePaths": [[[0,0], {"c": [[3,3],[1,4]]} ]]}
438 QVariantList pathsList;
439 if ( geometryData[u"paths"_s].isValid() )
440 pathsList = geometryData[u"paths"_s].toList();
441 else if ( geometryData[u"curvePaths"_s].isValid() )
442 pathsList = geometryData[u"curvePaths"_s].toList();
443 if ( pathsList.isEmpty() )
444 return nullptr;
445 std::unique_ptr< QgsMultiCurve > multiCurve = allowCurves ? std::make_unique< QgsMultiCurve >() : std::make_unique< QgsMultiLineString >();
446 multiCurve->reserve( static_cast< int >( pathsList.size() ) );
447 for ( const QVariant &pathData : std::as_const( pathsList ) )
448 {
449 std::unique_ptr< QgsCurve > curve = allowCurves ? convertCompoundCurve( pathData.toList(), pointType ) : convertLineString( pathData.toList(), pointType );
450 if ( !curve )
451 {
452 return nullptr;
453 }
454 multiCurve->addGeometry( curve.release() );
455 }
456 return multiCurve;
457}
458
459std::unique_ptr< QgsMultiSurface > QgsArcGisRestUtils::convertGeometryPolygon( const QVariantMap &geometryData, Qgis::WkbType pointType, bool allowCurves )
460{
461 // {"curveRings": [[[0,0], {"c": [[3,3],[1,4]]} ]]}
462 QVariantList ringsList;
463 if ( geometryData[u"rings"_s].isValid() )
464 ringsList = geometryData[u"rings"_s].toList();
465 else if ( geometryData[u"ringPaths"_s].isValid() )
466 ringsList = geometryData[u"ringPaths"_s].toList();
467 if ( ringsList.isEmpty() )
468 return nullptr;
469
470 QList< QgsCurve * > curves;
471 for ( int i = 0, n = static_cast< int >( ringsList.size() ); i < n; ++i )
472 {
473 std::unique_ptr< QgsCurve > curve = allowCurves ? convertCompoundCurve( ringsList[i].toList(), pointType ) : convertLineString( ringsList[i].toList(), pointType );
474 if ( !curve )
475 {
476 continue;
477 }
478 curves.append( curve.release() );
479 }
480 if ( curves.count() == 0 )
481 return nullptr;
482
483 std::unique_ptr< QgsMultiSurface > result = allowCurves ? std::make_unique< QgsMultiSurface >() : std::make_unique< QgsMultiPolygon >();
484 if ( curves.count() == 1 )
485 {
486 // shortcut for exterior ring only
487 std::unique_ptr< QgsCurvePolygon > newPolygon = allowCurves ? std::make_unique< QgsCurvePolygon >() : std::make_unique< QgsPolygon >();
488 newPolygon->setExteriorRing( curves.takeAt( 0 ) );
489 result->addGeometry( newPolygon.release() );
490 return result;
491 }
492
493 std::sort( curves.begin(), curves.end(), []( const QgsCurve *a, const QgsCurve *b ) -> bool {
494 double a_area = 0.0;
495 double b_area = 0.0;
496 a->sumUpArea( a_area );
497 b->sumUpArea( b_area );
498 return std::abs( a_area ) > std::abs( b_area );
499 } );
500 result->reserve( static_cast< int >( curves.size() ) );
501 while ( !curves.isEmpty() )
502 {
503 QgsCurve *exterior = curves.takeFirst();
504 QgsCurvePolygon *newPolygon = allowCurves ? new QgsCurvePolygon() : new QgsPolygon();
505 newPolygon->setExteriorRing( exterior );
506 std::unique_ptr<QgsGeometryEngine> engine( QgsGeometry::createGeometryEngine( newPolygon ) );
507 engine->prepareGeometry();
508
509 QMutableListIterator< QgsCurve * > it( curves );
510 while ( it.hasNext() )
511 {
512 QgsCurve *curve = it.next();
513 QgsRectangle boundingBox = newPolygon->boundingBox();
514 if ( boundingBox.intersects( curve->boundingBox() ) )
515 {
516 QgsPoint point = curve->startPoint();
517 if ( engine->contains( &point ) )
518 {
519 newPolygon->addInteriorRing( curve );
520 it.remove();
521 engine = QgsGeometry::createGeometryEngine( newPolygon );
522 engine->prepareGeometry();
523 }
524 }
525 }
526 result->addGeometry( newPolygon );
527 }
528 if ( result->numGeometries() == 0 )
529 return nullptr;
530
531 return result;
532}
533
534std::unique_ptr< QgsPolygon > QgsArcGisRestUtils::convertEnvelope( const QVariantMap &geometryData )
535{
536 // {"xmin" : -109.55, "ymin" : 25.76, "xmax" : -86.39, "ymax" : 49.94}
537 bool xminOk = false, yminOk = false, xmaxOk = false, ymaxOk = false;
538 double xmin = geometryData[u"xmin"_s].toDouble( &xminOk );
539 double ymin = geometryData[u"ymin"_s].toDouble( &yminOk );
540 double xmax = geometryData[u"xmax"_s].toDouble( &xmaxOk );
541 double ymax = geometryData[u"ymax"_s].toDouble( &ymaxOk );
542 if ( !xminOk || !yminOk || !xmaxOk || !ymaxOk )
543 return nullptr;
544 auto ext = std::make_unique< QgsLineString>();
545 ext->addVertex( QgsPoint( xmin, ymin ) );
546 ext->addVertex( QgsPoint( xmax, ymin ) );
547 ext->addVertex( QgsPoint( xmax, ymax ) );
548 ext->addVertex( QgsPoint( xmin, ymax ) );
549 ext->addVertex( QgsPoint( xmin, ymin ) );
550 auto poly = std::make_unique< QgsPolygon >();
551 poly->setExteriorRing( ext.release() );
552 return poly;
553}
554
555std::unique_ptr< QgsAbstractGeometry > QgsArcGisRestUtils::convertGeometry(
556 const QVariantMap &geometryData, const QString &esriGeometryType, bool readM, bool readZ, bool allowCurves, QgsCoordinateReferenceSystem *crs
557)
558{
559 Qgis::WkbType pointType = QgsWkbTypes::zmType( Qgis::WkbType::Point, readZ, readM );
560 if ( crs )
561 {
562 *crs = convertSpatialReference( geometryData[u"spatialReference"_s].toMap() );
563 }
564
565 // http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Geometry_Objects/02r3000000n1000000/
566 if ( esriGeometryType == "esriGeometryNull"_L1 )
567 return nullptr;
568 else if ( esriGeometryType == "esriGeometryPoint"_L1 )
569 return convertGeometryPoint( geometryData, pointType );
570 else if ( esriGeometryType == "esriGeometryMultipoint"_L1 )
571 return convertMultiPoint( geometryData, pointType );
572 else if ( esriGeometryType == "esriGeometryPolyline"_L1 )
573 return convertGeometryPolyline( geometryData, pointType, allowCurves );
574 else if ( esriGeometryType == "esriGeometryPolygon"_L1 )
575 return convertGeometryPolygon( geometryData, pointType, allowCurves );
576 else if ( esriGeometryType == "esriGeometryEnvelope"_L1 )
577 return convertEnvelope( geometryData );
578 // Unsupported (either by qgis, or format unspecified by the specification)
579 // esriGeometryCircularArc
580 // esriGeometryEllipticArc
581 // esriGeometryBezier3Curve
582 // esriGeometryPath
583 // esriGeometryRing
584 // esriGeometryLine
585 // esriGeometryAny
586 // esriGeometryMultiPatch
587 // esriGeometryTriangleStrip
588 // esriGeometryTriangleFan
589 // esriGeometryRay
590 // esriGeometrySphere
591 // esriGeometryTriangles
592 // esriGeometryBag
593 return nullptr;
594}
595
597{
599
600 QString spatialReference = spatialReferenceMap[u"latestWkid"_s].toString();
601 if ( spatialReference.isEmpty() )
602 spatialReference = spatialReferenceMap[u"wkid"_s].toString();
603
604 // prefer using authority/id wherever we can
605 if ( !spatialReference.isEmpty() )
606 {
607 crs.createFromString( u"EPSG:%1"_s.arg( spatialReference ) );
608 if ( !crs.isValid() )
609 {
610 // Try as an ESRI auth
611 crs.createFromString( u"ESRI:%1"_s.arg( spatialReference ) );
612 }
613 }
614 else if ( !spatialReferenceMap[u"wkt"_s].toString().isEmpty() )
615 {
616 // otherwise fallback to WKT
617 crs.createFromWkt( spatialReferenceMap[u"wkt"_s].toString() );
618 }
619
620 if ( !crs.isValid() )
621 {
622 // If no spatial reference, just use WGS84
623 // TODO -- this needs further investigation! Most ESRI server services default to 3857, so that would likely be
624 // a safer fallback to use...
625 crs.createFromString( u"EPSG:4326"_s );
626 }
627 return crs;
628}
629
630std::unique_ptr< QgsSymbol > QgsArcGisRestUtils::convertSymbol( const QVariantMap &symbolData, QgsSymbolConverterContext &context )
631{
632 return QgsSymbolConverterEsriRest().createSymbol( symbolData, context );
633}
634
635std::unique_ptr< QgsSymbol > QgsArcGisRestUtils::convertSymbol( const QVariantMap &symbolData )
636{
637 QgsReadWriteContext rwContext;
638 QgsSymbolConverterContext context( rwContext );
639 return convertSymbol( symbolData, context );
640}
641
642std::unique_ptr<QgsAbstractVectorLayerLabeling > QgsArcGisRestUtils::convertLabeling( const QVariantList &labelingData )
643{
644 if ( labelingData.empty() )
645 return nullptr;
646
647 QgsRuleBasedLabeling::Rule *root = new QgsRuleBasedLabeling::Rule( new QgsPalLayerSettings(), 0, 0, QString(), QString(), false );
648 root->setActive( true );
649
650 int i = 1;
651 for ( const QVariant &lbl : labelingData )
652 {
653 const QVariantMap labeling = lbl.toMap();
654
656 QgsTextFormat format;
657
658 const QString placement = labeling.value( u"labelPlacement"_s ).toString();
659 if ( placement == "esriServerPointLabelPlacementAboveCenter"_L1 )
660 {
663 }
664 else if ( placement == "esriServerPointLabelPlacementBelowCenter"_L1 )
665 {
668 }
669 else if ( placement == "esriServerPointLabelPlacementCenterCenter"_L1 )
670 {
673 }
674 else if ( placement == "esriServerPointLabelPlacementAboveLeft"_L1 )
675 {
678 }
679 else if ( placement == "esriServerPointLabelPlacementBelowLeft"_L1 )
680 {
683 }
684 else if ( placement == "esriServerPointLabelPlacementCenterLeft"_L1 )
685 {
688 }
689 else if ( placement == "esriServerPointLabelPlacementAboveRight"_L1 )
690 {
693 }
694 else if ( placement == "esriServerPointLabelPlacementBelowRight"_L1 )
695 {
698 }
699 else if ( placement == "esriServerPointLabelPlacementCenterRight"_L1 )
700 {
703 }
704 else if ( placement == "esriServerLinePlacementAboveAfter"_L1 || placement == "esriServerLinePlacementAboveStart"_L1 || placement == "esriServerLinePlacementAboveAlong"_L1 )
705 {
708 }
709 else if ( placement == "esriServerLinePlacementBelowAfter"_L1 || placement == "esriServerLinePlacementBelowStart"_L1 || placement == "esriServerLinePlacementBelowAlong"_L1 )
710 {
713 }
714 else if ( placement == "esriServerLinePlacementCenterAfter"_L1 || placement == "esriServerLinePlacementCenterStart"_L1 || placement == "esriServerLinePlacementCenterAlong"_L1 )
715 {
718 }
719 else if ( placement == "esriServerPolygonPlacementAlwaysHorizontal"_L1 )
720 {
722 }
723
724 const bool repeatLabel = labeling.value( u"repeatLabel"_s ).toBool();
725 if ( repeatLabel && settings->placement == Qgis::LabelPlacement::Line )
726 {
727 const double repeatLabelDistance = labeling.value( u"repeatLabelDistance"_s ).toDouble();
728 if ( repeatLabelDistance > 0.0 )
729 {
730 settings->repeatDistance = repeatLabelDistance;
732 }
733 }
734
735 const double minScale = labeling.value( u"minScale"_s ).toDouble();
736 const double maxScale = labeling.value( u"maxScale"_s ).toDouble();
737
738 QVariantMap symbol = labeling.value( u"symbol"_s ).toMap();
739 format.setColor( convertColor( symbol.value( u"color"_s ) ) );
740 const double haloSize = symbol.value( u"haloSize"_s ).toDouble();
741 if ( !qgsDoubleNear( haloSize, 0.0 ) )
742 {
744 buffer.setEnabled( true );
745 buffer.setSize( haloSize );
747 buffer.setColor( convertColor( symbol.value( u"haloColor"_s ) ) );
748 format.setBuffer( buffer );
749 }
750
751 const QString fontFamily = symbol.value( u"font"_s ).toMap().value( u"family"_s ).toString();
752 const QString fontStyle = symbol.value( u"font"_s ).toMap().value( u"style"_s ).toString();
753 const QString fontWeight = symbol.value( u"font"_s ).toMap().value( u"weight"_s ).toString();
754 const int fontSize = symbol.value( u"font"_s ).toMap().value( u"size"_s ).toInt();
755 QFont font( fontFamily, fontSize );
756 font.setStyleName( fontStyle );
757 font.setWeight( fontWeight == "bold"_L1 ? QFont::Bold : QFont::Normal );
758
759 format.setFont( font );
760 format.setSize( fontSize );
762
763 settings->setFormat( format );
764
765 QString where = labeling.value( u"where"_s ).toString();
766 QgsExpression exp( where );
767 // If the where clause isn't parsed as valid, don't use its
768 if ( !exp.isValid() )
769 where.clear();
770
771 settings->fieldName = convertLabelingExpression( labeling.value( u"labelExpression"_s ).toString() );
772 settings->isExpression = true;
773
774 QgsRuleBasedLabeling::Rule *child = new QgsRuleBasedLabeling::Rule( settings, maxScale, minScale, where, QObject::tr( "ASF label %1" ).arg( i++ ), false );
775 child->setActive( true );
776 root->appendChild( child );
777 }
778
779 return std::make_unique< QgsRuleBasedLabeling >( root );
780}
781
782void QgsArcGisRestUtils::applyVisualVariables( const QVariantMap &rendererData, QgsSymbol *symbol, QgsSymbolConverterContext &context )
783{
784 if ( !symbol )
785 return;
786
787 const QVariantList visualVariablesData = rendererData.value( u"visualVariables"_s ).toList();
788 for ( const QVariant &visualVariable : visualVariablesData )
789 {
790 const QVariantMap visualVariableData = visualVariable.toMap();
791 const QString variableType = visualVariableData.value( u"type"_s ).toString();
792
793 if ( variableType == "rotationInfo"_L1 )
794 {
795 const QString field = visualVariableData.value( u"field"_s ).toString();
796 if ( field.isEmpty() )
797 {
798 // Check if it was a valueExpression that we don't support yet
799 if ( !visualVariableData.value( u"valueExpression"_s ).toString().isEmpty() )
800 context.pushWarning( QObject::tr( "ESRI rotationInfo valueExpression is not yet supported" ) );
801 continue;
802 }
803
804 const QString rotationType = visualVariableData.value( u"rotationType"_s ).toString();
805
806 QgsProperty angleProperty;
807 if ( rotationType == "arithmetic"_L1 )
808 {
809 // ArcGIS arithmetic: 0° = East, counter-clockwise
810 // QGIS: 0° = North, clockwise
811 // Conversion: QGIS_angle = 90 - ArcGIS_angle
812 angleProperty = QgsProperty::fromExpression( u"90 - %1"_s.arg( QgsExpression::quotedColumnRef( field ) ) );
813 }
814 else if ( rotationType == "geographic"_L1 )
815 {
816 // ArcGIS geographic: 0° = North, clockwise (same as QGIS)
817 angleProperty = QgsProperty::fromField( field );
818 }
819 else
820 {
821 context.pushWarning( QObject::tr( "ESRI rotationInfo rotationType '%1' is not supported" ).arg( rotationType ) );
822 continue;
823 }
824
825 // Apply rotation to all symbol layers
826 for ( int layer = 0; layer < symbol->symbolLayerCount(); ++layer )
827 {
828 symbol->symbolLayer( layer )->setDataDefinedProperty( QgsSymbolLayer::Property::Angle, angleProperty );
829 }
830 }
831 else
832 {
833 context.pushWarning( QObject::tr( "ESRI visualVariable type '%1' is not currently supported" ).arg( variableType ) );
834 }
835 }
836}
837
838std::unique_ptr< QgsFeatureRenderer > QgsArcGisRestUtils::convertRenderer( const QVariantMap &rendererData, QgsSymbolConverterContext &context )
839{
840 const QString type = rendererData.value( u"type"_s ).toString();
841
842 if ( type == "simple"_L1 )
843 {
844 const QVariantMap symbolProps = rendererData.value( u"symbol"_s ).toMap();
845 std::unique_ptr< QgsSymbol > symbol( convertSymbol( symbolProps, context ) );
846 if ( symbol )
847 {
848 // Apply visual variables (e.g., rotation) to the symbol
849 applyVisualVariables( rendererData, symbol.get(), context );
850 return std::make_unique< QgsSingleSymbolRenderer >( symbol.release() );
851 }
852 else
853 return nullptr;
854 }
855 else if ( type == "uniqueValue"_L1 )
856 {
857 const QString field1 = rendererData.value( u"field1"_s ).toString();
858 const QString field2 = rendererData.value( u"field2"_s ).toString();
859 const QString field3 = rendererData.value( u"field3"_s ).toString();
860 QString attribute;
861 if ( !field2.isEmpty() || !field3.isEmpty() )
862 {
863 const QString delimiter = rendererData.value( u"fieldDelimiter"_s ).toString();
864 if ( !field3.isEmpty() )
865 {
866 attribute = u"concat(\"%1\",'%2',\"%3\",'%4',\"%5\")"_s.arg( field1, delimiter, field2, delimiter, field3 );
867 }
868 else
869 {
870 attribute = u"concat(\"%1\",'%2',\"%3\")"_s.arg( field1, delimiter, field2 );
871 }
872 }
873 else
874 {
875 attribute = field1;
876 }
877
878 const QString valueExpression = rendererData.value( u"valueExpression"_s ).toString();
879 if ( attribute.isEmpty() && !valueExpression.isEmpty() )
880 {
881 QgsEsriArcadeConverter converter( valueExpression );
883 {
884 attribute = converter.expression();
885 }
886 else
887 {
888 context.pushWarning( QObject::tr( "The Arcade valueExpression '%1' could not be converted to a QGIS expression: '%2'" ).arg( valueExpression ).arg( converter.errorMessage() ) );
889 }
890 }
891
892 const QVariantList categories = rendererData.value( u"uniqueValueInfos"_s ).toList();
893 QgsCategoryList categoryList;
894 for ( const QVariant &category : categories )
895 {
896 const QVariantMap categoryData = category.toMap();
897 const QString valueString = categoryData.value( u"value"_s ).toString();
898 // Esri uses the literal string "<Null>" to represent a NULL field value in unique value renderers.
899 const QVariant value = valueString == "<Null>"_L1 ? QVariant() : QVariant( valueString );
900 const QString label = categoryData.value( u"label"_s ).toString();
901 std::unique_ptr< QgsSymbol > symbol( QgsArcGisRestUtils::convertSymbol( categoryData.value( u"symbol"_s ).toMap(), context ) );
902 if ( symbol )
903 {
904 // Apply visual variables (e.g., rotation) to the symbol
905 applyVisualVariables( rendererData, symbol.get(), context );
906
907 categoryList.append( QgsRendererCategory( value, symbol.release(), label ) );
908 }
909 }
910
911 std::unique_ptr< QgsSymbol > defaultSymbol( convertSymbol( rendererData.value( u"defaultSymbol"_s ).toMap(), context ) );
912 if ( defaultSymbol )
913 {
914 // Apply visual variables (e.g., rotation) to the symbol
915 applyVisualVariables( rendererData, defaultSymbol.get(), context );
916 categoryList.append( QgsRendererCategory( QVariant(), defaultSymbol.release(), rendererData.value( u"defaultLabel"_s ).toString() ) );
917 }
918
919 if ( categoryList.empty() )
920 return nullptr;
921
922 auto renderer = std::make_unique< QgsCategorizedSymbolRenderer >( attribute, categoryList );
923 return renderer;
924 }
925 else if ( type == "classBreaks"_L1 )
926 {
927 const QString attrName = rendererData.value( u"field"_s ).toString();
928
929 const QVariantList classBreakInfos = rendererData.value( u"classBreakInfos"_s ).toList();
930 const QVariantMap authoringInfo = rendererData.value( u"authoringInfo"_s ).toMap();
931 QVariantMap symbolData;
932
933 QString esriMode = authoringInfo.value( u"classificationMethod"_s ).toString();
934 if ( esriMode.isEmpty() )
935 {
936 esriMode = rendererData.value( u"classificationMethod"_s ).toString();
937 }
938
939 if ( !classBreakInfos.isEmpty() )
940 {
941 symbolData = classBreakInfos.at( 0 ).toMap().value( u"symbol"_s ).toMap();
942 }
943 std::unique_ptr< QgsSymbol > symbol( QgsArcGisRestUtils::convertSymbol( symbolData, context ) );
944 if ( !symbol )
945 return nullptr;
946
947 const QVariantList visualVariablesData = rendererData.value( u"visualVariables"_s ).toList();
948
949 for ( const QVariant &visualVariable : visualVariablesData )
950 {
951 const QVariantMap visualVariableData = visualVariable.toMap();
952 const QString variableType = visualVariableData.value( u"type"_s ).toString();
953 if ( variableType == "sizeInfo"_L1 )
954 {
955 continue;
956 }
957 else if ( variableType == "colorInfo"_L1 )
958 {
959 const QVariantList stops = visualVariableData.value( u"stops"_s ).toList();
960 if ( stops.size() < 2 )
961 continue;
962
963 // layer has continuous coloring, so convert to a symbol using color ramp assistant
964 bool ok = false;
965 const double minValue = stops.front().toMap().value( u"value"_s ).toDouble( &ok );
966 if ( !ok )
967 continue;
968 const QColor minColor = convertColor( stops.front().toMap().value( u"color"_s ) );
969
970 const double maxValue = stops.back().toMap().value( u"value"_s ).toDouble( &ok );
971 if ( !ok )
972 continue;
973 const QColor maxColor = convertColor( stops.back().toMap().value( u"color"_s ) );
974
975 QgsGradientStopsList gradientStops;
976 for ( int i = 1; i < stops.size() - 1; ++i )
977 {
978 const QVariantMap stopData = stops.at( i ).toMap();
979 const double breakpoint = stopData.value( u"value"_s ).toDouble();
980 const double scaledBreakpoint = ( breakpoint - minValue ) / ( maxValue - minValue );
981 const QColor fillColor = convertColor( stopData.value( u"color"_s ) );
982
983 gradientStops.append( QgsGradientStop( scaledBreakpoint, fillColor ) );
984 }
985
986 auto colorRamp = std::make_unique< QgsGradientColorRamp >( minColor, maxColor, false, gradientStops );
987
988 QgsProperty colorProperty = QgsProperty::fromField( attrName );
989 colorProperty.setTransformer( new QgsColorRampTransformer( minValue, maxValue, colorRamp.release() ) );
990 for ( int layer = 0; layer < symbol->symbolLayerCount(); ++layer )
991 {
992 symbol->symbolLayer( layer )->setDataDefinedProperty( QgsSymbolLayer::Property::FillColor, colorProperty );
993 }
994
995 return std::make_unique< QgsSingleSymbolRenderer >( symbol.release() );
996 }
997 else if ( variableType == "rotationInfo"_L1 )
998 {
999 // Rotation will be handled below after the renderer is created
1000 continue;
1001 }
1002 else
1003 {
1004 context.pushWarning( QObject::tr( "ESRI visualVariable type '%1' is not currently supported" ).arg( variableType ) );
1005 }
1006 }
1007
1008 double lastValue = rendererData.value( u"minValue"_s ).toDouble();
1009
1010 auto graduatedRenderer = std::make_unique< QgsGraduatedSymbolRenderer >( attrName );
1011
1012 graduatedRenderer->setSourceSymbol( symbol.release() );
1013
1014 if ( esriMode == "esriClassifyDefinedInterval"_L1 )
1015 {
1017 graduatedRenderer->setClassificationMethod( method );
1018 }
1019 else if ( esriMode == "esriClassifyEqualInterval"_L1 )
1020 {
1022 graduatedRenderer->setClassificationMethod( method );
1023 }
1024 else if ( esriMode == "esriClassifyGeometricalInterval"_L1 )
1025 {
1027 graduatedRenderer->setClassificationMethod( method );
1028 }
1029 else if ( esriMode == "esriClassifyManual"_L1 )
1030 {
1032 graduatedRenderer->setClassificationMethod( method );
1033 }
1034 else if ( esriMode == "esriClassifyNaturalBreaks"_L1 )
1035 {
1037 graduatedRenderer->setClassificationMethod( method );
1038 }
1039 else if ( esriMode == "esriClassifyQuantile"_L1 )
1040 {
1042 graduatedRenderer->setClassificationMethod( method );
1043 }
1044 else if ( esriMode == "esriClassifyStandardDeviation"_L1 )
1045 {
1047 graduatedRenderer->setClassificationMethod( method );
1048 }
1049 else if ( !esriMode.isEmpty() )
1050 {
1051 context.pushWarning( QObject::tr( "ESRI classification mode '%1' is not currently supported" ).arg( esriMode ) );
1052 }
1053
1054 for ( const QVariant &classBreakInfo : classBreakInfos )
1055 {
1056 const QVariantMap symbolData = classBreakInfo.toMap().value( u"symbol"_s ).toMap();
1057 std::unique_ptr< QgsSymbol > symbol( QgsArcGisRestUtils::convertSymbol( symbolData, context ) );
1058 double classMaxValue = classBreakInfo.toMap().value( u"classMaxValue"_s ).toDouble();
1059 const QString label = classBreakInfo.toMap().value( u"label"_s ).toString();
1060
1061 // Apply visual variables (e.g., rotation) to the symbol
1062 applyVisualVariables( rendererData, symbol.get(), context );
1063
1064 QgsRendererRange range;
1065
1066 range.setLowerValue( lastValue );
1067 range.setUpperValue( classMaxValue );
1068 range.setLabel( label );
1069 range.setSymbol( symbol.release() );
1070
1071 lastValue = classMaxValue;
1072 graduatedRenderer->addClass( range );
1073 }
1074
1075 return graduatedRenderer;
1076 }
1077 else if ( type == "heatmap"_L1 )
1078 {
1079 // currently unsupported
1080 return nullptr;
1081 }
1082 else if ( type == "vectorField"_L1 )
1083 {
1084 // currently unsupported
1085 return nullptr;
1086 }
1087 return nullptr;
1088}
1089
1090std::unique_ptr< QgsFeatureRenderer > QgsArcGisRestUtils::convertRenderer( const QVariantMap &rendererData )
1091{
1092 QgsReadWriteContext rwContext;
1093 QgsSymbolConverterContext context( rwContext );
1094 return convertRenderer( rendererData, context );
1095}
1096
1098{
1099 QString expression = string;
1100
1101 // Replace a few ArcGIS token to QGIS equivalents
1102 const thread_local QRegularExpression rx1 = QRegularExpression( u"(?=([^\"\\\\]*(\\\\.|\"([^\"\\\\]*\\\\.)*[^\"\\\\]*\"))*[^\"]*$)(\\s|^)CONCAT(\\s|$)"_s );
1103 expression = expression.replace( rx1, u"\\4||\\5"_s );
1104
1105 const thread_local QRegularExpression rx2 = QRegularExpression( u"(?=([^\"\\\\]*(\\\\.|\"([^\"\\\\]*\\\\.)*[^\"\\\\]*\"))*[^\"]*$)(\\s|^)NEWLINE(\\s|$)"_s );
1106 expression = expression.replace( rx2, u"\\4'\\n'\\5"_s );
1107
1108 // ArcGIS's double quotes are single quotes in QGIS
1109 const thread_local QRegularExpression rx3 = QRegularExpression( u"\"(.*?(?<!\\\\))\""_s );
1110 expression = expression.replace( rx3, u"'\\1'"_s );
1111 const thread_local QRegularExpression rx4 = QRegularExpression( u"\\\\\""_s );
1112 expression = expression.replace( rx4, u"\""_s );
1113
1114 // ArcGIS's square brakets are double quotes in QGIS
1115 const thread_local QRegularExpression rx5 = QRegularExpression( u"\\[([^]]*)\\]"_s );
1116 expression = expression.replace( rx5, u"\"\\1\""_s );
1117
1118 return expression;
1119}
1120
1121QColor QgsArcGisRestUtils::convertColor( const QVariant &colorData )
1122{
1123 return QgsSymbolConverterEsriRest::convertColor( colorData );
1124}
1125
1126Qt::PenStyle QgsArcGisRestUtils::convertLineStyle( const QString &style )
1127{
1129}
1130
1131Qt::BrushStyle QgsArcGisRestUtils::convertFillStyle( const QString &style )
1132{
1134}
1135
1136QDateTime QgsArcGisRestUtils::convertDateTime( const QVariant &value )
1137{
1138 if ( QgsVariantUtils::isNull( value ) )
1139 return QDateTime();
1140 bool ok = false;
1141 QDateTime dt = QDateTime::fromMSecsSinceEpoch( value.toLongLong( &ok ) );
1142 if ( !ok )
1143 {
1144 QgsDebugError( u"Invalid value %1 for datetime"_s.arg( value.toString() ) );
1145 return QDateTime();
1146 }
1147 else
1148 return dt;
1149}
1150
1152{
1153 if ( QgsVariantUtils::isNull( value ) )
1154 return QgsRectangle();
1155
1156 const QVariantMap coords = value.toMap();
1157 if ( coords.isEmpty() )
1158 return QgsRectangle();
1159
1160 bool ok;
1161
1162 const double xmin = coords.value( u"xmin"_s ).toDouble( &ok );
1163 if ( !ok )
1164 return QgsRectangle();
1165
1166 const double ymin = coords.value( u"ymin"_s ).toDouble( &ok );
1167 if ( !ok )
1168 return QgsRectangle();
1169
1170 const double xmax = coords.value( u"xmax"_s ).toDouble( &ok );
1171 if ( !ok )
1172 return QgsRectangle();
1173
1174 const double ymax = coords.value( u"ymax"_s ).toDouble( &ok );
1175 if ( !ok )
1176 return QgsRectangle();
1177
1178 return QgsRectangle( xmin, ymin, xmax, ymax );
1179}
1180
1181
1183{
1184 QVariantMap res;
1185 if ( geometry.isNull() )
1186 return QVariantMap();
1187
1188 const QgsAbstractGeometry *geom = geometry.constGet()->simplifiedTypeRef();
1189 switch ( QgsWkbTypes::flatType( geom->wkbType() ) )
1190 {
1193 return QVariantMap();
1194
1196 res = pointToJson( qgsgeometry_cast< const QgsPoint * >( geom ) );
1197 break;
1198
1200 res = lineStringToJson( qgsgeometry_cast< const QgsLineString * >( geom ) );
1201 break;
1202
1205 res = curveToJson( qgsgeometry_cast< const QgsCurve * >( geom ) );
1206 break;
1207
1209 res = polygonToJson( qgsgeometry_cast< const QgsPolygon * >( geom ) );
1210 break;
1211
1213 res = multiPointToJson( qgsgeometry_cast< const QgsMultiPoint * >( geom ) );
1214 break;
1215
1217 res = multiLineStringToJson( qgsgeometry_cast< const QgsMultiLineString * >( geom ) );
1218 break;
1219
1221 res = multiCurveToJson( qgsgeometry_cast< const QgsMultiCurve * >( geom ) );
1222 break;
1223
1225 res = multiPolygonToJson( qgsgeometry_cast< const QgsMultiPolygon * >( geom ) );
1226 break;
1227
1229 res = curvePolygonToJson( qgsgeometry_cast< const QgsCurvePolygon * >( geom ) );
1230 break;
1231
1233 res = multiSurfaceToJson( qgsgeometry_cast< const QgsMultiSurface * >( geom ) );
1234 break;
1235
1237 return QVariantMap(); // not supported by REST API
1238
1240 return QVariantMap(); //not yet supported, but could be
1241
1242 default:
1243 return QVariantMap(); //unreachable
1244 }
1245
1246 if ( crs.isValid() )
1247 {
1248 // add spatialReference information
1249 res.insert( u"spatialReference"_s, crsToJson( crs ) );
1250 }
1251
1252 return res;
1253}
1254
1255QVariantMap QgsArcGisRestUtils::pointToJson( const QgsPoint *point )
1256{
1257 QVariantMap data;
1258 if ( point->isEmpty() )
1259 data[u"x"_s] = u"NaN"_s;
1260 else
1261 {
1262 data[u"x"_s] = point->x();
1263 data[u"y"_s] = point->y();
1264
1265 if ( point->is3D() )
1266 data[u"z"_s] = !std::isnan( point->z() ) ? QVariant( point->z() ) : QVariant( u"NaN"_s );
1267
1268 if ( point->isMeasure() )
1269 data[u"m"_s] = !std::isnan( point->m() ) ? QVariant( point->m() ) : QVariant( u"NaN"_s );
1270 }
1271 return data;
1272}
1273
1274QVariantMap QgsArcGisRestUtils::multiPointToJson( const QgsMultiPoint *multiPoint )
1275{
1276 QVariantMap data;
1277 const bool hasZ = multiPoint->is3D();
1278 const bool hasM = multiPoint->isMeasure();
1279 data[u"hasM"_s] = hasM;
1280 data[u"hasZ"_s] = hasZ;
1281
1282 QVariantList pointsList;
1283 const int size = multiPoint->numGeometries();
1284 pointsList.reserve( size );
1285
1286 QVariantList pointList;
1287 for ( int i = 0; i < size; ++i )
1288 {
1289 const QgsPoint *point = multiPoint->pointN( i );
1290
1291 pointList.clear();
1292 pointList.append( point->x() );
1293 pointList.append( point->y() );
1294 if ( hasZ )
1295 pointList.append( point->z() );
1296 if ( hasM && !std::isnan( point->m() ) )
1297 pointList.append( point->m() );
1298
1299 pointsList.push_back( pointList );
1300 }
1301
1302 data[u"points"_s] = pointsList;
1303 return data;
1304}
1305
1306QVariantList QgsArcGisRestUtils::lineStringToJsonPath( const QgsLineString *line )
1307{
1308 const bool hasZ = line->is3D();
1309 const bool hasM = line->isMeasure();
1310
1311 QVariantList pointsList;
1312 const int size = line->numPoints();
1313 pointsList.reserve( size );
1314
1315 QVariantList pointList;
1316 const double *xData = line->xData();
1317 const double *yData = line->yData();
1318 const double *zData = hasZ ? line->zData() : nullptr;
1319 const double *mData = hasM ? line->mData() : nullptr;
1320
1321 for ( int i = 0; i < size; ++i )
1322 {
1323 pointList.clear();
1324 pointList.append( *xData++ );
1325 pointList.append( *yData++ );
1326
1327 if ( hasZ )
1328 pointList.append( *zData++ );
1329
1330 if ( hasM && !std::isnan( *mData ) )
1331 pointList.append( *mData );
1332 if ( hasM )
1333 mData++;
1334
1335 pointsList.push_back( pointList );
1336 }
1337 return pointsList;
1338}
1339
1340QVariantList QgsArcGisRestUtils::curveToJsonCurve( const QgsCurve *curve, bool includeStart )
1341{
1342 const bool hasZ = curve->is3D();
1343 const bool hasM = curve->isMeasure();
1344
1345 auto pointToList = [hasZ, hasM]( const QgsPoint &point ) -> QVariantList {
1346 QVariantList pointList;
1347
1348 pointList.append( point.x() );
1349 pointList.append( point.y() );
1350
1351 if ( hasZ )
1352 pointList.append( point.z() );
1353
1354 if ( hasM && !std::isnan( point.m() ) )
1355 pointList.append( point.m() );
1356
1357 return pointList;
1358 };
1359
1360 QVariantList res;
1361 switch ( QgsWkbTypes::flatType( curve->wkbType() ) )
1362 {
1364 {
1365 QVariantList part = lineStringToJsonPath( qgsgeometry_cast< const QgsLineString *>( curve ) );
1366 if ( !part.isEmpty() && !includeStart )
1367 part.removeAt( 0 );
1368 res = part;
1369 break;
1370 }
1371
1373 {
1374 const QgsCircularString *circularString = qgsgeometry_cast<const QgsCircularString * >( curve );
1375 if ( includeStart && !circularString->isEmpty() )
1376 {
1377 res.push_back( pointToList( circularString->startPoint() ) );
1378 }
1379
1380 const int size = circularString->numPoints();
1381 for ( int i = 1; i + 1 < size; i += 2 )
1382 {
1383 // end point comes BEFORE interior point!
1384 QVariantMap curvePart;
1385 QVariantList curveList;
1386 curveList.push_back( pointToList( circularString->pointN( i + 1 ) ) );
1387
1388 curveList.push_back( pointToList( circularString->pointN( i ) ) );
1389
1390 curvePart.insert( u"c"_s, curveList );
1391 res.push_back( curvePart );
1392 }
1393 break;
1394 }
1395
1397 {
1398 const QgsCompoundCurve *compoundCurve = qgsgeometry_cast<const QgsCompoundCurve * >( curve );
1399
1400 const int size = compoundCurve->nCurves();
1401 for ( int i = 0; i < size; ++i )
1402 {
1403 const QgsCurve *subCurve = compoundCurve->curveAt( i );
1404 res.append( curveToJsonCurve( subCurve, i == 0 ) );
1405 }
1406 break;
1407 }
1408
1409 default:
1410 break;
1411 }
1412 return res;
1413}
1414
1415QVariantMap QgsArcGisRestUtils::lineStringToJson( const QgsLineString *line )
1416{
1417 QVariantMap data;
1418 const bool hasZ = line->is3D();
1419 const bool hasM = line->isMeasure();
1420 data[u"hasM"_s] = hasM;
1421 data[u"hasZ"_s] = hasZ;
1422
1423 const QVariantList pointsList = lineStringToJsonPath( line );
1424
1425 QVariantList pointsData = QVariantList();
1426 pointsData.push_back( pointsList );
1427 data[u"paths"_s] = pointsData;
1428
1429 return data;
1430}
1431
1432QVariantMap QgsArcGisRestUtils::curveToJson( const QgsCurve *curve )
1433{
1434 QVariantMap data;
1435 const bool hasZ = curve->is3D();
1436 const bool hasM = curve->isMeasure();
1437 data[u"hasM"_s] = hasM;
1438 data[u"hasZ"_s] = hasZ;
1439
1440 const QVariantList curveList = curveToJsonCurve( curve, true );
1441
1442 QVariantList curveData = QVariantList();
1443 curveData.push_back( curveList );
1444 data[u"curvePaths"_s] = curveData;
1445
1446 return data;
1447}
1448
1449QVariantMap QgsArcGisRestUtils::multiLineStringToJson( const QgsMultiLineString *multiLine )
1450{
1451 QVariantMap data;
1452 const bool hasZ = multiLine->is3D();
1453 const bool hasM = multiLine->isMeasure();
1454 data[u"hasM"_s] = hasM;
1455 data[u"hasZ"_s] = hasZ;
1456
1457 const int size = multiLine->numGeometries();
1458 QVariantList paths;
1459 paths.reserve( size );
1460 for ( int i = 0; i < size; ++i )
1461 {
1462 const QgsLineString *line = multiLine->lineStringN( i );
1463 paths.push_back( lineStringToJsonPath( line ) );
1464 }
1465
1466 data[u"paths"_s] = paths;
1467 return data;
1468}
1469
1470QVariantMap QgsArcGisRestUtils::multiCurveToJson( const QgsMultiCurve *multiCurve )
1471{
1472 QVariantMap data;
1473 const bool hasZ = multiCurve->is3D();
1474 const bool hasM = multiCurve->isMeasure();
1475 data[u"hasM"_s] = hasM;
1476 data[u"hasZ"_s] = hasZ;
1477
1478 const int size = multiCurve->numGeometries();
1479 QVariantList paths;
1480 paths.reserve( size );
1481 for ( int i = 0; i < size; ++i )
1482 {
1483 const QgsCurve *curve = multiCurve->curveN( i );
1484 paths.push_back( curveToJsonCurve( curve, true ) );
1485 }
1486
1487 data[u"curvePaths"_s] = paths;
1488 return data;
1489}
1490
1491QVariantList QgsArcGisRestUtils::polygonToJsonRings( const QgsPolygon *polygon )
1492{
1493 QVariantList rings;
1494 const int numInteriorRings = polygon->numInteriorRings();
1495 rings.reserve( numInteriorRings + 1 );
1496
1497 if ( const QgsLineString *exterior = qgsgeometry_cast< const QgsLineString * >( polygon->exteriorRing() ) )
1498 {
1499 // exterior ring MUST be clockwise
1500 switch ( exterior->orientation() )
1501 {
1503 rings.push_back( lineStringToJsonPath( exterior ) );
1504 break;
1505
1507 {
1508 std::unique_ptr< QgsLineString > reversed( exterior->reversed() );
1509 rings.push_back( lineStringToJsonPath( reversed.get() ) );
1510 break;
1511 }
1513 break;
1514 }
1515 }
1516
1517 for ( int i = 0; i < numInteriorRings; ++i )
1518 {
1519 const QgsLineString *ring = qgsgeometry_cast< const QgsLineString * >( polygon->interiorRing( i ) );
1520 // holes MUST be counter-clockwise
1521 switch ( ring->orientation() )
1522 {
1524 rings.push_back( lineStringToJsonPath( ring ) );
1525 break;
1526
1528 {
1529 std::unique_ptr< QgsLineString > reversed( ring->reversed() );
1530 rings.push_back( lineStringToJsonPath( reversed.get() ) );
1531 break;
1532 }
1534 break;
1535 }
1536 }
1537 return rings;
1538}
1539
1540QVariantList QgsArcGisRestUtils::curvePolygonToJsonRings( const QgsCurvePolygon *polygon )
1541{
1542 QVariantList rings;
1543 const int numInteriorRings = polygon->numInteriorRings();
1544 rings.reserve( numInteriorRings + 1 );
1545
1546 if ( const QgsCurve *exterior = qgsgeometry_cast< const QgsCurve * >( polygon->exteriorRing() ) )
1547 {
1548 // exterior ring MUST be clockwise
1549 switch ( exterior->orientation() )
1550 {
1552 rings.push_back( curveToJsonCurve( exterior, true ) );
1553 break;
1554
1556 {
1557 std::unique_ptr< QgsCurve > reversed( exterior->reversed() );
1558 rings.push_back( curveToJsonCurve( reversed.get(), true ) );
1559 break;
1560 }
1562 break;
1563 }
1564 }
1565
1566 for ( int i = 0; i < numInteriorRings; ++i )
1567 {
1568 const QgsCurve *ring = qgsgeometry_cast< const QgsCurve * >( polygon->interiorRing( i ) );
1569 // holes MUST be counter-clockwise
1570 switch ( ring->orientation() )
1571 {
1573 rings.push_back( curveToJsonCurve( ring, true ) );
1574 break;
1575
1577 {
1578 std::unique_ptr< QgsCurve > reversed( ring->reversed() );
1579 rings.push_back( curveToJsonCurve( reversed.get(), true ) );
1580 break;
1581 }
1583 break;
1584 }
1585 }
1586 return rings;
1587}
1588
1589QVariantMap QgsArcGisRestUtils::polygonToJson( const QgsPolygon *polygon )
1590{
1591 QVariantMap data;
1592 const bool hasZ = polygon->is3D();
1593 const bool hasM = polygon->isMeasure();
1594 data[u"hasM"_s] = hasM;
1595 data[u"hasZ"_s] = hasZ;
1596 data[u"rings"_s] = polygonToJsonRings( polygon );
1597 return data;
1598}
1599
1600QVariantMap QgsArcGisRestUtils::curvePolygonToJson( const QgsCurvePolygon *polygon )
1601{
1602 QVariantMap data;
1603 const bool hasZ = polygon->is3D();
1604 const bool hasM = polygon->isMeasure();
1605 data[u"hasM"_s] = hasM;
1606 data[u"hasZ"_s] = hasZ;
1607 data[u"curveRings"_s] = curvePolygonToJsonRings( polygon );
1608 return data;
1609}
1610
1611QVariantMap QgsArcGisRestUtils::multiPolygonToJson( const QgsMultiPolygon *multiPolygon )
1612{
1613 QVariantMap data;
1614 const bool hasZ = multiPolygon->is3D();
1615 const bool hasM = multiPolygon->isMeasure();
1616 data[u"hasM"_s] = hasM;
1617 data[u"hasZ"_s] = hasZ;
1618
1619 const int size = multiPolygon->numGeometries();
1620 QVariantList rings;
1621 for ( int i = 0; i < size; ++i )
1622 {
1623 const QgsPolygon *polygon = multiPolygon->polygonN( i );
1624 rings.append( polygonToJsonRings( polygon ) );
1625 }
1626
1627 data[u"rings"_s] = rings;
1628 return data;
1629}
1630
1631QVariantMap QgsArcGisRestUtils::multiSurfaceToJson( const QgsMultiSurface *multiSurface )
1632{
1633 QVariantMap data;
1634 const bool hasZ = multiSurface->is3D();
1635 const bool hasM = multiSurface->isMeasure();
1636 data[u"hasM"_s] = hasM;
1637 data[u"hasZ"_s] = hasZ;
1638
1639 const int size = multiSurface->numGeometries();
1640 QVariantList rings;
1641 for ( int i = 0; i < size; ++i )
1642 {
1643 const QgsCurvePolygon *polygon = qgsgeometry_cast< const QgsCurvePolygon * >( multiSurface->geometryN( i ) );
1644 if ( !polygon )
1645 continue;
1646
1647 rings.append( curvePolygonToJsonRings( polygon ) );
1648 }
1649
1650 data[u"curveRings"_s] = rings;
1651 return data;
1652}
1653
1655{
1656 QVariantMap res;
1657 if ( !crs.isValid() )
1658 return res;
1659
1660 const QString authid = crs.authid();
1661 if ( !authid.isEmpty() )
1662 {
1663 const thread_local QRegularExpression rxAuthid( u"(\\w+):(\\d+)"_s );
1664 const QRegularExpressionMatch match = rxAuthid.match( authid );
1665 if ( match.hasMatch() && ( ( match.captured( 1 ).compare( "EPSG"_L1, Qt::CaseInsensitive ) == 0 ) || ( match.captured( 1 ).compare( "ESRI"_L1, Qt::CaseInsensitive ) == 0 ) ) )
1666 {
1667 const QString wkid = match.captured( 2 );
1668 res.insert( u"wkid"_s, wkid );
1669 return res;
1670 }
1671 }
1672
1673 // docs don't mention the WKT version support, so let's hope for 2.0...
1674 res.insert( u"wkt"_s, crs.toWkt( Qgis::CrsWktVariant::Wkt2_2019Simplified ) );
1675
1676 return res;
1677}
1678
1680{
1681 QVariantMap res;
1682 if ( ( flags & FeatureToJsonFlag::IncludeGeometry ) && feature.hasGeometry() )
1683 {
1684 res.insert( u"geometry"_s, geometryToJson( feature.geometry(), context, crs ) );
1685 }
1686
1687 QVariantMap attributes;
1688 const QgsFields fields = feature.fields();
1689 for ( const QgsField &field : fields )
1690 {
1691 QVariant value = feature.attribute( field.name() );
1692 if ( value.userType() == qMetaTypeId< QgsUnsetAttributeValue >() )
1693 {
1694 if ( flags.testFlag( FeatureToJsonFlag::SkipUnsetAttributes ) )
1695 continue;
1696 else
1697 value = QVariant(); // reset to null, we can't store 'QgsUnsetAttributeValue' as json
1698 }
1699
1700 if ( ( flags & FeatureToJsonFlag::IncludeNonObjectIdAttributes ) || field.name() == context.objectIdFieldName() )
1701 attributes.insert( field.name(), variantToAttributeValue( value, field.type(), context ) );
1702 }
1703 if ( !attributes.isEmpty() )
1704 {
1705 res.insert( u"attributes"_s, attributes );
1706 }
1707 return res;
1708}
1709
1710QVariant QgsArcGisRestUtils::variantToAttributeValue( const QVariant &variant, QMetaType::Type expectedType, const QgsArcGisRestContext &context )
1711{
1712 if ( QgsVariantUtils::isNull( variant ) )
1713 return QVariant();
1714
1715 switch ( expectedType )
1716 {
1717 case QMetaType::Type::QString:
1718 {
1719 const QString escaped = variant.toString().replace( '\\', "\\\\"_L1 ).replace( '"', "\\\""_L1 );
1720 return QString( QUrl::toPercentEncoding( escaped, "'" ) );
1721 }
1722
1723 case QMetaType::Type::QDateTime:
1724 case QMetaType::Type::QDate:
1725 {
1726 switch ( variant.userType() )
1727 {
1728 case QMetaType::Type::QDateTime:
1729 return variant.toDateTime().toMSecsSinceEpoch();
1730
1731 case QMetaType::Type::QDate:
1732 // for date values, assume start of day -- the REST api requires datetime values only, not plain dates
1733 if ( context.timeZone().isValid() )
1734 return QDateTime( variant.toDate(), QTime( 0, 0, 0 ), context.timeZone() ).toMSecsSinceEpoch();
1735 else
1736 return QDateTime( variant.toDate(), QTime( 0, 0, 0 ) ).toMSecsSinceEpoch();
1737
1738 default:
1739 return QVariant();
1740 }
1741 }
1742
1743 default:
1744 return variant;
1745 }
1746}
1747
1749{
1750 QVariantMap res;
1751 res.insert( u"name"_s, field.name() );
1752
1753 QString fieldType;
1754 switch ( field.type() )
1755 {
1756 case QMetaType::Type::LongLong:
1757 fieldType = u"esriFieldTypeInteger"_s;
1758 break;
1759
1760 case QMetaType::Type::Int:
1761 fieldType = u"esriFieldTypeSmallInteger"_s;
1762 break;
1763
1764 case QMetaType::Type::Double:
1765 fieldType = u"esriFieldTypeDouble"_s;
1766 break;
1767
1768 case QMetaType::Type::QString:
1769 fieldType = u"esriFieldTypeString"_s;
1770 break;
1771
1772 case QMetaType::Type::QDateTime:
1773 case QMetaType::Type::QDate:
1774 fieldType = u"esriFieldTypeDate"_s;
1775 break;
1776
1777 case QMetaType::Type::QByteArray:
1778 fieldType = u"esriFieldTypeBlob"_s;
1779 break;
1780
1781 default:
1782 // fallback to string
1783 fieldType = u"esriFieldTypeString"_s;
1784 break;
1785 }
1786 res.insert( u"type"_s, fieldType );
1787
1788 if ( !field.alias().isEmpty() )
1789 res.insert( u"alias"_s, field.alias() );
1790
1791 // nullable
1793 res.insert( u"nullable"_s, !notNullable );
1794
1795 // editable
1796 res.insert( u"editable"_s, true );
1797
1798 return res;
1799}
1800
1802{
1803 if ( type.compare( "FeatureServer"_L1, Qt::CaseInsensitive ) == 0 )
1805 else if ( type.compare( "MapServer"_L1, Qt::CaseInsensitive ) == 0 )
1807 else if ( type.compare( "ImageServer"_L1, Qt::CaseInsensitive ) == 0 )
1809 else if ( type.compare( "GlobeServer"_L1, Qt::CaseInsensitive ) == 0 )
1811 else if ( type.compare( "GPServer"_L1, Qt::CaseInsensitive ) == 0 )
1813 else if ( type.compare( "GeocodeServer"_L1, Qt::CaseInsensitive ) == 0 )
1815 else if ( type.compare( "SceneServer"_L1, Qt::CaseInsensitive ) == 0 )
1817
1819}
1820
1822{
1823 const QStringList parts = capabilities.split( ',' );
1824
1826 res.setFlag( Qgis::ArcGisRestServiceCapability::Query, parts.contains( "query"_L1, Qt::CaseInsensitive ) );
1827 res.setFlag( Qgis::ArcGisRestServiceCapability::Map, parts.contains( "map"_L1, Qt::CaseInsensitive ) );
1828 res.setFlag( Qgis::ArcGisRestServiceCapability::Update, parts.contains( "update"_L1, Qt::CaseInsensitive ) );
1829 res.setFlag( Qgis::ArcGisRestServiceCapability::Delete, parts.contains( "delete"_L1, Qt::CaseInsensitive ) );
1830 res.setFlag( Qgis::ArcGisRestServiceCapability::Create, parts.contains( "create"_L1, Qt::CaseInsensitive ) );
1831 res.setFlag( Qgis::ArcGisRestServiceCapability::Image, parts.contains( "image"_L1, Qt::CaseInsensitive ) );
1832 res.setFlag( Qgis::ArcGisRestServiceCapability::TilesOnly, parts.contains( "tilesonly"_L1, Qt::CaseInsensitive ) );
1833
1834 return res;
1835}
1836
1838{
1839 if ( pixelType.compare( "U8"_L1, Qt::CaseInsensitive ) == 0
1840 || pixelType.compare( "U4"_L1, Qt::CaseInsensitive ) == 0
1841 || pixelType.compare( "U2"_L1, Qt::CaseInsensitive ) == 0
1842 || pixelType.compare( "U1"_L1, Qt::CaseInsensitive ) == 0 )
1843 {
1844 return Qgis::DataType::Byte;
1845 }
1846 else if ( pixelType.compare( "S8"_L1, Qt::CaseInsensitive ) == 0 )
1847 {
1848 return Qgis::DataType::Int8;
1849 }
1850 else if ( pixelType.compare( "U16"_L1, Qt::CaseInsensitive ) == 0 )
1851 {
1853 }
1854 else if ( pixelType.compare( "S16"_L1, Qt::CaseInsensitive ) == 0 )
1855 {
1856 return Qgis::DataType::Int16;
1857 }
1858 else if ( pixelType.compare( "U32"_L1, Qt::CaseInsensitive ) == 0 )
1859 {
1861 }
1862 else if ( pixelType.compare( "S32"_L1, Qt::CaseInsensitive ) == 0 )
1863 {
1864 return Qgis::DataType::Int32;
1865 }
1866 else if ( pixelType.compare( "F32"_L1, Qt::CaseInsensitive ) == 0 )
1867 {
1869 }
1870 else if ( pixelType.compare( "F64"_L1, Qt::CaseInsensitive ) == 0 )
1871 {
1873 }
1874 else if ( pixelType.compare( "C64"_L1, Qt::CaseInsensitive ) == 0 )
1875 {
1876 // C64 = 32-bit real + 32-bit imaginary
1878 }
1879 else if ( pixelType.compare( "C128"_L1, Qt::CaseInsensitive ) == 0 )
1880 {
1881 // C128 = 64-bit real + 64-bit imaginary
1883 }
1884 else
1885 {
1886 QgsDebugError( u"Unknown pixelType: %1"_s.arg( pixelType ) );
1887 }
1888
1890}
1891
1893{
1894 if ( pixelType.compare( "U8"_L1, Qt::CaseInsensitive ) == 0
1895 || pixelType.compare( "U4"_L1, Qt::CaseInsensitive ) == 0
1896 || pixelType.compare( "U2"_L1, Qt::CaseInsensitive ) == 0
1897 || pixelType.compare( "U1"_L1, Qt::CaseInsensitive ) == 0
1898 || pixelType.compare( "S8"_L1, Qt::CaseInsensitive ) == 0
1899 || pixelType.compare( "U16"_L1, Qt::CaseInsensitive ) == 0
1900 || pixelType.compare( "S16"_L1, Qt::CaseInsensitive ) == 0 )
1901 {
1902 return PixelTypeLimitUsefulness { true, true };
1903 }
1904 else if ( pixelType.compare( "U32"_L1, Qt::CaseInsensitive ) == 0 )
1905 {
1906 return PixelTypeLimitUsefulness { true, false };
1907 }
1908 else if ( pixelType.compare( "S32"_L1, Qt::CaseInsensitive ) == 0
1909 || pixelType.compare( "F32"_L1, Qt::CaseInsensitive ) == 0
1910 || pixelType.compare( "F64"_L1, Qt::CaseInsensitive ) == 0
1911 || pixelType.compare( "C64"_L1, Qt::CaseInsensitive ) == 0
1912 || pixelType.compare( "C128"_L1, Qt::CaseInsensitive ) == 0 )
1913 {
1914 return PixelTypeLimitUsefulness { false, false };
1915 }
1916 else
1917 {
1918 QgsDebugError( u"Unknown pixelType: %1"_s.arg( pixelType ) );
1919 }
1920
1921 return PixelTypeLimitUsefulness { false, false };
1922}
1923
1924std::optional<std::pair<double, double> > QgsArcGisRestUtils::rangeForPixelType( const QString &pixelType )
1925{
1926 if ( pixelType.compare( "U8"_L1, Qt::CaseInsensitive ) == 0 )
1927 {
1928 return std::make_pair( 0.0, 255.0 );
1929 }
1930 else if ( pixelType.compare( "U4"_L1, Qt::CaseInsensitive ) == 0 )
1931 {
1932 return std::make_pair( 0.0, 15.0 );
1933 }
1934 else if ( pixelType.compare( "U2"_L1, Qt::CaseInsensitive ) == 0 )
1935 {
1936 return std::make_pair( 0.0, 3.0 );
1937 }
1938 else if ( pixelType.compare( "U1"_L1, Qt::CaseInsensitive ) == 0 )
1939 {
1940 return std::make_pair( 0.0, 1.0 );
1941 }
1942 else if ( pixelType.compare( "S8"_L1, Qt::CaseInsensitive ) == 0 )
1943 {
1944 return std::make_pair( -128.0, 127.0 );
1945 }
1946 else if ( pixelType.compare( "U16"_L1, Qt::CaseInsensitive ) == 0 )
1947 {
1948 return std::make_pair( 0.0, 65535.0 );
1949 }
1950 else if ( pixelType.compare( "S16"_L1, Qt::CaseInsensitive ) == 0 )
1951 {
1952 return std::make_pair( -32768.0, 32767.0 );
1953 }
1954 else if ( pixelType.compare( "U32"_L1, Qt::CaseInsensitive ) == 0 )
1955 {
1956 return std::make_pair( 0.0, static_cast<double>( std::numeric_limits<uint32_t>::max() ) );
1957 }
1958 else if ( pixelType.compare( "S32"_L1, Qt::CaseInsensitive ) == 0 )
1959 {
1960 return std::make_pair( static_cast<double>( std::numeric_limits<int32_t>::lowest() ), static_cast<double>( std::numeric_limits<int32_t>::max() ) );
1961 }
1962 else if ( pixelType.compare( "F32"_L1, Qt::CaseInsensitive ) == 0 )
1963 {
1964 return std::make_pair( static_cast<double>( std::numeric_limits<float>::lowest() ), static_cast<double>( std::numeric_limits<float>::max() ) );
1965 }
1966 else if ( pixelType.compare( "F64"_L1, Qt::CaseInsensitive ) == 0 )
1967 {
1968 return std::make_pair( std::numeric_limits<double>::lowest(), std::numeric_limits<double>::max() );
1969 }
1970 else if ( pixelType.compare( "C64"_L1, Qt::CaseInsensitive ) == 0 )
1971 {
1972 // C64 = 32-bit real + 32-bit imaginary
1973 return std::make_pair( static_cast<double>( std::numeric_limits<float>::lowest() ), static_cast<double>( std::numeric_limits<float>::max() ) );
1974 }
1975 else if ( pixelType.compare( "C128"_L1, Qt::CaseInsensitive ) == 0 )
1976 {
1977 // C128 = 64-bit real + 64-bit imaginary
1978 return std::make_pair( std::numeric_limits<double>::lowest(), std::numeric_limits<double>::max() );
1979 }
1980 else
1981 {
1982 QgsDebugError( u"Unknown pixelType: %1"_s.arg( pixelType ) );
1983 }
1984
1985 return std::nullopt;
1986}
1987
1989{
1990 if ( bandName.isEmpty() )
1991 {
1993 }
1994
1995 if ( bandName.compare( "Red"_L1, Qt::CaseInsensitive ) == 0 )
1997 else if ( bandName.compare( "Green"_L1, Qt::CaseInsensitive ) == 0 )
1999 else if ( bandName.compare( "Blue"_L1, Qt::CaseInsensitive ) == 0 )
2001 else if ( bandName.compare( "Alpha"_L1, Qt::CaseInsensitive ) == 0 )
2003 else if ( bandName.compare( "NIR"_L1, Qt::CaseInsensitive ) == 0
2004 || bandName.compare( "NearInfrared"_L1, Qt::CaseInsensitive ) == 0
2005 || bandName.compare( "NearIR"_L1, Qt::CaseInsensitive ) == 0
2006 || bandName.compare( "NarrowNIR"_L1, Qt::CaseInsensitive ) == 0 )
2008 else if ( bandName.startsWith( "SWIR"_L1, Qt::CaseInsensitive ) )
2010 else if ( bandName.startsWith( "VRE"_L1, Qt::CaseInsensitive ) || bandName.compare( "RedEdge"_L1, Qt::CaseInsensitive ) == 0 )
2012 else if ( bandName.startsWith( "Coastal"_L1, Qt::CaseInsensitive ) )
2014 else if ( bandName.startsWith( "Pan"_L1, Qt::CaseInsensitive ) )
2016 else if ( bandName.startsWith( "Thermal"_L1, Qt::CaseInsensitive ) || bandName.startsWith( "TIR"_L1, Qt::CaseInsensitive ) )
2018 else if ( bandName.compare( "Gray"_L1, Qt::CaseInsensitive ) == 0 || bandName.compare( "Grey"_L1, Qt::CaseInsensitive ) == 0 )
2020 else if ( bandName.compare( "Cyan"_L1, Qt::CaseInsensitive ) == 0 )
2022 else if ( bandName.compare( "Magenta"_L1, Qt::CaseInsensitive ) == 0 )
2024 else if ( bandName.compare( "Yellow"_L1, Qt::CaseInsensitive ) == 0 )
2026 else if ( bandName.compare( "Black"_L1, Qt::CaseInsensitive ) == 0 )
2028 else if ( bandName.compare( "Hue"_L1, Qt::CaseInsensitive ) == 0 )
2030 else if ( bandName.compare( "Saturation"_L1, Qt::CaseInsensitive ) == 0 )
2032 else if ( bandName.compare( "Lightness"_L1, Qt::CaseInsensitive ) == 0 )
2034
2035 // we don't log failures here -- a lot of bands will have non-interpretable names,
2036 // eg "Band 1"
2038}
2039
2041{
2042 ok = false;
2043 switch ( type )
2044 {
2046 return 0;
2047
2049 ok = true;
2050 return std::numeric_limits<quint8>::max();
2051
2053 ok = true;
2054 return std::numeric_limits<qint8>::lowest();
2055
2057 ok = true;
2058 return std::numeric_limits<quint16>::max();
2059
2061 ok = true;
2062 return std::numeric_limits<qint16>::lowest();
2063
2065 ok = true;
2066 return std::numeric_limits<quint32>::max();
2067
2069 ok = true;
2070 return std::numeric_limits<qint32>::lowest();
2071
2073 ok = true;
2074 return std::numeric_limits<float>::quiet_NaN();
2075
2077 ok = true;
2078 return std::numeric_limits<double>::quiet_NaN();
2079
2086 return 0;
2087 }
2089}
@ BelowLine
Labels can be placed below a line feature. Unless MapOrientation is also specified this mode respects...
Definition qgis.h:1419
@ MapOrientation
Signifies that the AboveLine and BelowLine flags should respect the map's orientation rather than the...
Definition qgis.h:1420
@ OnLine
Labels can be placed directly over a line feature.
Definition qgis.h:1417
@ AboveLine
Labels can be placed above a line feature. Unless MapOrientation is also specified this mode respects...
Definition qgis.h:1418
@ NoOrientation
Unknown orientation or sentinel value.
Definition qgis.h:3700
@ CounterClockwise
Counter-clockwise direction.
Definition qgis.h:3699
@ Clockwise
Clockwise direction.
Definition qgis.h:3698
@ OverPoint
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point....
Definition qgis.h:1310
@ Line
Arranges candidates parallel to a generalised line representing the feature or parallel to a polygon'...
Definition qgis.h:1311
@ Horizontal
Arranges horizontal candidates scattered throughout a polygon feature or along a line feature....
Definition qgis.h:1313
ArcGisRestServiceType
Available ArcGIS REST service types.
Definition qgis.h:4870
@ GeocodeServer
GeocodeServer.
Definition qgis.h:4876
@ SceneServer
SceneServer.
Definition qgis.h:4878
@ Unknown
Other unknown/unsupported type.
Definition qgis.h:4877
@ GlobeServer
GlobeServer.
Definition qgis.h:4874
@ ImageServer
ImageServer.
Definition qgis.h:4873
@ FeatureServer
FeatureServer.
Definition qgis.h:4871
@ AboveRight
Above right.
Definition qgis.h:1399
@ BelowLeft
Below left.
Definition qgis.h:1403
@ Above
Above center.
Definition qgis.h:1398
@ BelowRight
Below right.
Definition qgis.h:1405
@ Right
Right middle.
Definition qgis.h:1402
@ AboveLeft
Above left.
Definition qgis.h:1397
@ Below
Below center.
Definition qgis.h:1404
@ Over
Center middle.
Definition qgis.h:1401
DataType
Raster data types.
Definition qgis.h:413
@ CInt32
Complex Int32.
Definition qgis.h:424
@ Float32
Thirty two bit floating point (float).
Definition qgis.h:421
@ CFloat64
Complex Float64.
Definition qgis.h:426
@ Int16
Sixteen bit signed integer (qint16).
Definition qgis.h:418
@ ARGB32_Premultiplied
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32_Premultiplied.
Definition qgis.h:428
@ Int8
Eight bit signed integer (qint8) (added in QGIS 3.30).
Definition qgis.h:416
@ UInt16
Sixteen bit unsigned integer (quint16).
Definition qgis.h:417
@ Byte
Eight bit unsigned integer (quint8).
Definition qgis.h:415
@ UnknownDataType
Unknown or unspecified type.
Definition qgis.h:414
@ ARGB32
Color, alpha, red, green, blue, 4 bytes the same as QImage::Format_ARGB32.
Definition qgis.h:427
@ Int32
Thirty two bit signed integer (qint32).
Definition qgis.h:420
@ Float64
Sixty four bit floating point (double).
Definition qgis.h:422
@ CFloat32
Complex Float32.
Definition qgis.h:425
@ CInt16
Complex Int16.
Definition qgis.h:423
@ UInt32
Thirty two bit unsigned integer (quint32).
Definition qgis.h:419
@ Points
Points (e.g., for font sizes).
Definition qgis.h:5790
QFlags< ArcGisRestServiceCapability > ArcGisRestServiceCapabilities
Available ArcGIS REST service capabilities.
Definition qgis.h:4907
@ Update
Update features.
Definition qgis.h:4894
@ Create
Create features.
Definition qgis.h:4896
@ TilesOnly
Service supports tiled image requests only.
Definition qgis.h:4898
@ Image
Image capabilities.
Definition qgis.h:4897
@ Delete
Delete features.
Definition qgis.h:4895
RasterColorInterpretation
Raster color interpretation.
Definition qgis.h:5294
@ NIRBand
Near-InfraRed (NIR) band [0.75 - 1.40 um].
Definition qgis.h:5320
@ GreenBand
Green band of RGBA image, or green spectral band [0.51 - 0.60 um].
Definition qgis.h:5299
@ SaturationBand
Saturation band of HLS image.
Definition qgis.h:5303
@ MagentaBand
Magenta band of CMYK image.
Definition qgis.h:5306
@ BlackBand
Black band of CMLY image.
Definition qgis.h:5308
@ AlphaBand
Alpha (0=transparent, 255=opaque).
Definition qgis.h:5301
@ SWIRBand
Short-Wavelength InfraRed (SWIR) band [1.40 - 3.00 um].
Definition qgis.h:5321
@ BlueBand
Blue band of RGBA image, or blue spectral band [0.45 - 0.53 um].
Definition qgis.h:5300
@ RedEdgeBand
Red-edge band [0.69 - 0.79 um].
Definition qgis.h:5319
@ YellowBand
Yellow band of CMYK image, or yellow spectral band [0.58 - 0.62 um].
Definition qgis.h:5307
@ CyanBand
Cyan band of CMYK image.
Definition qgis.h:5305
@ LightnessBand
Lightness band of HLS image.
Definition qgis.h:5304
@ CoastalBand
Coastal band [0.40 - 0.45 um].
Definition qgis.h:5318
@ HueBand
Hue band of HLS image.
Definition qgis.h:5302
@ TIRBand
Thermal InfraRed (TIR) band (MWIR or LWIR) [3 - 15 um].
Definition qgis.h:5324
@ RedBand
Red band of RGBA image, or red spectral band [0.62 - 0.69 um].
Definition qgis.h:5298
@ PanBand
Panchromatic band [0.40 - 1.00 um].
Definition qgis.h:5317
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:314
@ CompoundCurve
CompoundCurve.
Definition qgis.h:325
@ Point
Point.
Definition qgis.h:316
@ LineString
LineString.
Definition qgis.h:317
@ MultiPoint
MultiPoint.
Definition qgis.h:320
@ Polygon
Polygon.
Definition qgis.h:318
@ MultiPolygon
MultiPolygon.
Definition qgis.h:322
@ Triangle
Triangle.
Definition qgis.h:319
@ NoGeometry
No geometry.
Definition qgis.h:332
@ MultiLineString
MultiLineString.
Definition qgis.h:321
@ Unknown
Unknown.
Definition qgis.h:315
@ CircularString
CircularString.
Definition qgis.h:324
@ GeometryCollection
GeometryCollection.
Definition qgis.h:323
@ MultiCurve
MultiCurve.
Definition qgis.h:327
@ CurvePolygon
CurvePolygon.
Definition qgis.h:326
@ MultiSurface
MultiSurface.
Definition qgis.h:328
@ Wkt2_2019Simplified
WKT2_2019 with the simplification rule of WKT2_SIMPLIFIED.
Definition qgis.h:2645
Abstract base class for all geometries.
virtual const QgsAbstractGeometry * simplifiedTypeRef() const
Returns a reference to the simplest lossless representation of this geometry, e.g.
bool isMeasure() const
Returns true if the geometry contains m values.
bool is3D() const
Returns true if the geometry is 3D and contains a z-value.
Qgis::WkbType wkbType() const
Returns the WKB type of the geometry.
Contains the context of a ArcGIS REST service operation.
QTimeZone timeZone() const
Returns the time zone for datetime values.
QString objectIdFieldName() const
Returns the name of the objectId field.
static std::unique_ptr< QgsAbstractGeometry > convertGeometry(const QVariantMap &geometry, const QString &esriGeometryType, bool hasM, bool hasZ, bool allowCurves=true, QgsCoordinateReferenceSystem *crs=nullptr)
Converts an ESRI REST geometry JSON definition to a QgsAbstractGeometry.
static QVariantMap fieldDefinitionToJson(const QgsField &field)
Converts a field's definition to an ArcGIS REST JSON representation.
static QgsCoordinateReferenceSystem convertSpatialReference(const QVariantMap &spatialReferenceMap)
Converts a spatial reference JSON definition to a QgsCoordinateReferenceSystem value.
static QDateTime convertDateTime(const QVariant &value)
Converts a date time value to a QDateTime.
static Qgis::WkbType convertGeometryType(const QString &type)
Converts an ESRI REST geometry type to a WKB type.
static QString convertLabelingExpression(const QString &string)
Converts an ESRI labeling expression to a QGIS expression string.
static QVariantMap geometryToJson(const QgsGeometry &geometry, const QgsArcGisRestContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem())
Converts a geometry to an ArcGIS REST JSON representation.
static double defaultNoDataForDataType(Qgis::DataType type, bool &ok)
Returns a sensible no-data value to use for the specified data type.
static PixelTypeLimitUsefulness pixelTypeLimitUsefulness(const QString &pixelType)
Returns whether the theoretical minimum and maximum values for a given ESRI pixelType are practically...
static Qgis::ArcGisRestServiceType serviceTypeFromString(const QString &type)
Converts a string value to a REST service type.
static QVariant variantToAttributeValue(const QVariant &variant, QMetaType::Type expectedType, const QgsArcGisRestContext &context)
Converts a variant to a REST attribute value.
static QVariantMap featureToJson(const QgsFeature &feature, const QgsArcGisRestContext &context, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem(), QgsArcGisRestUtils::FeatureToJsonFlags flags=QgsArcGisRestUtils::FeatureToJsonFlags(static_cast< int >(QgsArcGisRestUtils::FeatureToJsonFlag::IncludeGeometry)|static_cast< int >(QgsArcGisRestUtils::FeatureToJsonFlag::IncludeNonObjectIdAttributes)))
Converts a feature to an ArcGIS REST JSON representation.
static Qt::PenStyle convertLineStyle(const QString &style)
Converts an ESRI line style to a Qt pen style.
@ IncludeGeometry
Whether to include the geometry definition.
@ IncludeNonObjectIdAttributes
Whether to include any non-objectId attributes.
static Qgis::ArcGisRestServiceCapabilities serviceCapabilitiesFromString(const QString &capabilities)
Parses a capabilities string to known values.
static std::optional< std::pair< double, double > > rangeForPixelType(const QString &pixelType)
Returns the valid data range given an ESRI pixelType string.
static QMetaType::Type convertFieldType(const QString &type)
Converts an ESRI REST field type to a QVariant type.
static Qt::BrushStyle convertFillStyle(const QString &style)
Converts an ESRI fill style to a Qt brush style.
static std::unique_ptr< QgsFeatureRenderer > convertRenderer(const QVariantMap &rendererData, QgsSymbolConverterContext &context)
Converts renderer JSON data to an equivalent QgsFeatureRenderer.
static Qgis::RasterColorInterpretation colorInterpretationFromBandName(const QString &bandName)
Attempts to match arbitrary band name strings to a QGIS raster color interpretation.
static QVariantMap crsToJson(const QgsCoordinateReferenceSystem &crs)
Converts a crs to an ArcGIS REST JSON representation.
static std::unique_ptr< QgsAbstractVectorLayerLabeling > convertLabeling(const QVariantList &data)
Converts labeling JSON data to an equivalent QGIS vector labeling.
QFlags< FeatureToJsonFlag > FeatureToJsonFlags
Flags which control the behavior of converting features to JSON.
static Qgis::DataType dataTypeFromString(const QString &pixelType)
Returns the raster data type corresponding to an ESRI pixelType string.
static std::unique_ptr< QgsSymbol > convertSymbol(const QVariantMap &definition, QgsSymbolConverterContext &context)
Converts a symbol JSON definition to a QgsSymbol.
static QColor convertColor(const QVariant &data)
Converts ESRI JSON color data to a QColor object.
static QgsRectangle convertRectangle(const QVariant &value)
Converts a rectangle value to a QgsRectangle.
A dummy implementation class method which does not compute any breaks.
A classification method which uses equal width intervals.
Implementation of a fixed interval classification.
A classification method for natural breaks, based on Jenks method.
A classification method which creates classes based on quantiles.
A classification method which classifies based on standard deviation of values.
QgsPropertyTransformer subclass for transforming a numeric value into a color from a color ramp.
int nCurves() const
Returns the number of curves in the geometry.
const QgsCurve * curveAt(int i) const
Returns the curve at the specified index.
Represents a coordinate reference system (CRS).
bool isValid() const
Returns whether this CRS is correctly initialized and usable.
bool createFromWkt(const QString &wkt)
Sets this CRS using a WKT definition.
bool createFromString(const QString &definition)
Set up this CRS from a string definition.
QString toWkt(Qgis::CrsWktVariant variant=Qgis::CrsWktVariant::Wkt1Gdal, bool multiline=false, int indentationWidth=4) const
Returns a WKT representation of this CRS.
Curve polygon geometry type.
int numInteriorRings() const
Returns the number of interior rings contained with the curve polygon.
const QgsCurve * exteriorRing() const
Returns the curve polygon's exterior ring.
const QgsCurve * interiorRing(int i) const
Retrieves an interior ring from the curve polygon.
Abstract base class for curved geometry type.
Definition qgscurve.h:36
Qgis::AngularDirection orientation() const
Returns the curve's orientation, e.g.
Definition qgscurve.cpp:291
virtual QgsCurve * reversed() const =0
Returns a reversed copy of the curve, where the direction of the curve has been flipped.
virtual QgsPoint endPoint() const =0
Returns the end point of the curve.
Converts an Esri Arcade script to a QgsExpression.
Result result() const
Returns the result of converting the script.
QString errorMessage() const
Returns the descriptive error message, if an error was obtained while converting the script.
QString expression() const
Returns the QGIS expression equivalent of the Arcade script, if conversion was successful.
@ Success
Script was successfully converted.
Handles parsing and evaluation of expressions (formerly called "search strings").
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes).
bool isValid() const
Checks if this expression is valid.
The feature class encapsulates a single feature including its unique ID, geometry and a list of field...
Definition qgsfeature.h:60
QgsFields fields
Definition qgsfeature.h:65
QgsGeometry geometry
Definition qgsfeature.h:66
bool hasGeometry() const
Returns true if the feature has an associated geometry.
Q_INVOKABLE QVariant attribute(const QString &name) const
Lookup attribute value by attribute name.
@ ConstraintNotNull
Field may not be null.
Encapsulate a field in an attribute table or data source.
Definition qgsfield.h:56
QMetaType::Type type
Definition qgsfield.h:63
QString name
Definition qgsfield.h:65
QString alias
Definition qgsfield.h:66
QgsFieldConstraints constraints
Definition qgsfield.h:68
Container of fields for a vector layer.
Definition qgsfields.h:45
int numGeometries() const
Returns the number of geometries within the collection.
const QgsAbstractGeometry * geometryN(int n) const
Returns a const reference to a geometry from within the collection.
A geometry is the spatial representation of a feature.
const QgsAbstractGeometry * constGet() const
Returns a non-modifiable (const) reference to the underlying abstract geometry primitive.
Represents a color stop within a QgsGradientColorRamp color ramp.
void setPlacementFlags(Qgis::LabelLinePlacementFlags flags)
Returns the line placement flags, which dictate how line labels can be placed above or below the line...
void setQuadrant(Qgis::LabelQuadrantPosition quadrant)
Sets the quadrant in which to offset labels from the point.
Line string geometry type, with support for z-dimension and m-values.
QgsLineString * reversed() const override
Returns a reversed copy of the curve, where the direction of the curve has been flipped.
Multi curve geometry collection.
QgsCurve * curveN(int index)
Returns the curve with the specified index.
Multi line string geometry collection.
QgsLineString * lineStringN(int index)
Returns the line string with the specified index.
Multi point geometry collection.
QgsPoint * pointN(int index)
Returns the point with the specified index.
Multi polygon geometry collection.
QgsPolygon * polygonN(int index)
Returns the polygon with the specified index.
Multi surface geometry collection.
Contains settings for how a map layer will be labeled.
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
Qgis::LabelPlacement placement
Label placement mode.
double repeatDistance
Distance for repeating labels for a single feature.
bool isExpression
true if this label is made from a expression string, e.g., FieldName || 'mm'
const QgsLabelLineSettings & lineSettings() const
Returns the label line settings, which contain settings related to how the label engine places and fo...
Qgis::RenderUnit repeatDistanceUnit
Units for repeating labels for a single feature.
QString fieldName
Name of field (or an expression) to use for label text.
const QgsLabelPointSettings & pointSettings() const
Returns the label point settings, which contain settings related to how the label engine places and f...
Point geometry type, with support for z-dimension and m-values.
Definition qgspoint.h:53
void clear() override
Clears the geometry, ie reset it to a null geometry.
Definition qgspoint.cpp:395
double z
Definition qgspoint.h:58
double x
Definition qgspoint.h:56
bool isEmpty() const override
Returns true if the geometry is empty.
Definition qgspoint.cpp:775
double m
Definition qgspoint.h:59
double y
Definition qgspoint.h:57
Polygon geometry type.
Definition qgspolygon.h:37
A store for object properties.
void setTransformer(QgsPropertyTransformer *transformer)
Sets an optional transformer to use for manipulating the calculated values for the property.
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
static QgsProperty fromField(const QString &fieldName, bool isActive=true)
Returns a new FieldBasedProperty created from the specified field name.
A container for the context for various read/write operations on objects.
A rectangle specified with double values.
Represents an individual category (class) from a QgsCategorizedSymbolRenderer.
Represents a value range for a QgsGraduatedSymbolRenderer.
void setUpperValue(double upperValue)
Sets the upper bound of the range.
void setSymbol(QgsSymbol *s)
Sets the symbol used for the range.
void setLabel(const QString &label)
Sets the label used for the range.
void setLowerValue(double lowerValue)
Sets the lower bound of the range.
A child rule for QgsRuleBasedLabeling.
void setActive(bool state)
Sets if this rule is active.
void appendChild(QgsRuleBasedLabeling::Rule *rule)
add child rule, take ownership, sets this as parent
int numPoints() const override
Returns the number of points in the curve.
bool isEmpty() const override
Returns true if the geometry is empty.
const double * mData() const
Returns a const pointer to the m vertex data, or nullptr if the simple curve does not have m values.
const double * yData() const
Returns a const pointer to the y vertex data.
QgsPoint startPoint() const override
Returns the starting point of the curve.
QgsPoint pointN(int i) const
Returns the specified point from inside the simple curve.
const double * xData() const
Returns a const pointer to the x vertex data.
const double * zData() const
Returns a const pointer to the z vertex data, or nullptr if the simple curve does not have z values.
Represents the context in which a QgsSymbolConverter conversion occurs.
void pushWarning(const QString &warning)
Pushes a warning message generated during the conversion.
A symbol converter for converting ESRI REST JSON symbols.
static Qt::PenStyle convertLineStyle(const QString &style)
Converts an ESRI line style to a Qt pen style.
std::unique_ptr< QgsSymbol > createSymbol(const QVariant &variant, QgsSymbolConverterContext &context) const override
Creates a new QgsSymbol from a QVariant representation.
static Qt::BrushStyle convertFillStyle(const QString &style)
Converts an ESRI fill style to a Qt brush style.
static QColor convertColor(const QVariant &data)
Converts ESRI JSON color data to a QColor object.
virtual void setDataDefinedProperty(Property key, const QgsProperty &property)
Sets a data defined property for the layer.
Abstract base class for all rendered symbols.
Definition qgssymbol.h:227
QgsSymbolLayer * symbolLayer(int layer)
Returns the symbol layer at the specified index.
int symbolLayerCount() const
Returns the total number of symbol layers contained in the symbol.
Definition qgssymbol.h:357
Container for settings relating to a text buffer.
void setColor(const QColor &color)
Sets the color for the buffer.
void setSizeUnit(Qgis::RenderUnit unit)
Sets the units used for the buffer size.
void setEnabled(bool enabled)
Sets whether the text buffer will be drawn.
void setSize(double size)
Sets the size of the buffer.
Container for all settings relating to text rendering.
void setColor(const QColor &color)
Sets the color that text will be rendered in.
void setSize(double size)
Sets the size for rendered text.
void setFont(const QFont &font)
Sets the font used for rendering text.
void setSizeUnit(Qgis::RenderUnit unit)
Sets the units for the size of rendered text.
void setBuffer(const QgsTextBufferSettings &bufferSettings)
Sets the text's buffer settings.
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.
static Qgis::WkbType zmType(Qgis::WkbType type, bool hasZ, bool hasM)
Returns the modified input geometry type according to hasZ / hasM.
static Q_INVOKABLE bool hasZ(Qgis::WkbType type)
Tests whether a WKB type contains the z-dimension.
static Q_INVOKABLE bool hasM(Qgis::WkbType type)
Tests whether a WKB type contains m values.
static Qgis::WkbType flatType(Qgis::WkbType type)
Returns the flat type for a WKB type.
#define BUILTIN_UNREACHABLE
Definition qgis.h:8498
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
Definition qgis.h:7826
T qgsgeometry_cast(QgsAbstractGeometry *geom)
QList< QgsRendererCategory > QgsCategoryList
QList< QgsGradientStop > QgsGradientStopsList
List of gradient stops.
#define QgsDebugError(str)
Definition qgslogger.h:71
Struct representing whether the theoretical limits of a pixel type are useful for describing actual d...