/
qgsarcgisrestutils.cpp
1285 lines (1161 loc) · 51.5 KB
/
qgsarcgisrestutils.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/***************************************************************************
qgsarcgisrestutils.cpp
----------------------
begin : Nov 25, 2015
copyright : (C) 2015 by Sandro Mani
email : manisandro@gmail.com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgsarcgisrestutils.h"
#include "qgsfields.h"
#include "qgslogger.h"
#include "qgsnetworkaccessmanager.h"
#include "qgsrectangle.h"
#include "geometry/qgsabstractgeometry.h"
#include "geometry/qgscircularstring.h"
#include "geometry/qgscompoundcurve.h"
#include "geometry/qgscurvepolygon.h"
#include "geometry/qgslinestring.h"
#include "geometry/qgsmultipoint.h"
#include "geometry/qgsmulticurve.h"
#include "geometry/qgspolygon.h"
#include "geometry/qgspoint.h"
#include "qgsfeedback.h"
#include "qgspallabeling.h"
#include "qgssymbol.h"
#include "qgssymbollayer.h"
#include "qgsauthmanager.h"
#include "qgssettings.h"
#include "qgslinesymbollayer.h"
#include "qgsfillsymbollayer.h"
#include "qgsmarkersymbollayer.h"
#include "qgsrenderer.h"
#include "qgsrulebasedlabeling.h"
#include "qgssinglesymbolrenderer.h"
#include "qgscategorizedsymbolrenderer.h"
#include "qgsvectorlayerlabeling.h"
#include <QEventLoop>
#include <QNetworkRequest>
#include <QNetworkReply>
#include <QThread>
#include <QJsonDocument>
#include <QJsonObject>
QVariant::Type QgsArcGisRestUtils::mapEsriFieldType( const QString &esriFieldType )
{
if ( esriFieldType == QLatin1String( "esriFieldTypeInteger" ) )
return QVariant::LongLong;
if ( esriFieldType == QLatin1String( "esriFieldTypeSmallInteger" ) )
return QVariant::Int;
if ( esriFieldType == QLatin1String( "esriFieldTypeDouble" ) )
return QVariant::Double;
if ( esriFieldType == QLatin1String( "esriFieldTypeSingle" ) )
return QVariant::Double;
if ( esriFieldType == QLatin1String( "esriFieldTypeString" ) )
return QVariant::String;
if ( esriFieldType == QLatin1String( "esriFieldTypeDate" ) )
return QVariant::Date;
if ( esriFieldType == QLatin1String( "esriFieldTypeGeometry" ) )
return QVariant::Invalid; // Geometry column should not appear as field
if ( esriFieldType == QLatin1String( "esriFieldTypeOID" ) )
return QVariant::LongLong;
if ( esriFieldType == QLatin1String( "esriFieldTypeBlob" ) )
return QVariant::ByteArray;
if ( esriFieldType == QLatin1String( "esriFieldTypeGlobalID" ) )
return QVariant::String;
if ( esriFieldType == QLatin1String( "esriFieldTypeRaster" ) )
return QVariant::ByteArray;
if ( esriFieldType == QLatin1String( "esriFieldTypeGUID" ) )
return QVariant::String;
if ( esriFieldType == QLatin1String( "esriFieldTypeXML" ) )
return QVariant::String;
return QVariant::Invalid;
}
QgsWkbTypes::Type QgsArcGisRestUtils::mapEsriGeometryType( const QString &esriGeometryType )
{
// http://resources.arcgis.com/en/help/arcobjects-cpp/componenthelp/index.html#//000w0000001p000000
if ( esriGeometryType == QLatin1String( "esriGeometryNull" ) )
return QgsWkbTypes::Unknown;
else if ( esriGeometryType == QLatin1String( "esriGeometryPoint" ) )
return QgsWkbTypes::Point;
else if ( esriGeometryType == QLatin1String( "esriGeometryMultipoint" ) )
return QgsWkbTypes::MultiPoint;
else if ( esriGeometryType == QLatin1String( "esriGeometryPolyline" ) )
return QgsWkbTypes::MultiCurve;
else if ( esriGeometryType == QLatin1String( "esriGeometryPolygon" ) )
return QgsWkbTypes::Polygon;
else if ( esriGeometryType == QLatin1String( "esriGeometryEnvelope" ) )
return QgsWkbTypes::Polygon;
// Unsupported (either by qgis, or format unspecified by the specification)
// esriGeometryCircularArc
// esriGeometryEllipticArc
// esriGeometryBezier3Curve
// esriGeometryPath
// esriGeometryRing
// esriGeometryLine
// esriGeometryAny
// esriGeometryMultiPatch
// esriGeometryTriangleStrip
// esriGeometryTriangleFan
// esriGeometryRay
// esriGeometrySphere
// esriGeometryTriangles
// esriGeometryBag
return QgsWkbTypes::Unknown;
}
static std::unique_ptr< QgsPoint > parsePoint( const QVariantList &coordList, QgsWkbTypes::Type pointType )
{
int nCoords = coordList.size();
if ( nCoords < 2 )
return nullptr;
bool xok = false, yok = false;
double x = coordList[0].toDouble( &xok );
double y = coordList[1].toDouble( &yok );
if ( !xok || !yok )
return nullptr;
double z = nCoords >= 3 ? coordList[2].toDouble() : 0;
double m = nCoords >= 4 ? coordList[3].toDouble() : 0;
return qgis::make_unique< QgsPoint >( pointType, x, y, z, m );
}
static std::unique_ptr< QgsCircularString > parseCircularString( const QVariantMap &curveData, QgsWkbTypes::Type pointType, const QgsPoint &startPoint )
{
const QVariantList coordsList = curveData[QStringLiteral( "c" )].toList();
if ( coordsList.isEmpty() )
return nullptr;
QVector<QgsPoint> points;
points.append( startPoint );
for ( const QVariant &coordData : coordsList )
{
std::unique_ptr< QgsPoint > point = parsePoint( coordData.toList(), pointType );
if ( !point )
{
return nullptr;
}
points.append( *point );
}
std::unique_ptr< QgsCircularString > curve = qgis::make_unique< QgsCircularString> ();
curve->setPoints( points );
return curve;
}
static std::unique_ptr< QgsCompoundCurve > parseCompoundCurve( const QVariantList &curvesList, QgsWkbTypes::Type pointType )
{
// [[6,3],[5,3],{"b":[[3,2],[6,1],[2,4]]},[1,2],{"c": [[3,3],[1,4]]}]
std::unique_ptr< QgsCompoundCurve > compoundCurve = qgis::make_unique< QgsCompoundCurve >();
QgsLineString *lineString = new QgsLineString();
compoundCurve->addCurve( lineString );
for ( const QVariant &curveData : curvesList )
{
if ( curveData.type() == QVariant::List )
{
std::unique_ptr< QgsPoint > point = parsePoint( curveData.toList(), pointType );
if ( !point )
{
return nullptr;
}
lineString->addVertex( *point );
}
else if ( curveData.type() == QVariant::Map )
{
// The last point of the linestring is the start point of this circular string
std::unique_ptr< QgsCircularString > circularString = parseCircularString( curveData.toMap(), pointType, lineString->endPoint() );
if ( !circularString )
{
return nullptr;
}
// If the previous curve had less than two points, remove it
if ( compoundCurve->curveAt( compoundCurve->nCurves() - 1 )->nCoordinates() < 2 )
compoundCurve->removeCurve( compoundCurve->nCurves() - 1 );
compoundCurve->addCurve( circularString.release() );
// Prepare a new line string
lineString = new QgsLineString;
compoundCurve->addCurve( lineString );
lineString->addVertex( circularString->endPoint() );
}
}
return compoundCurve;
}
static std::unique_ptr< QgsPoint > parseEsriGeometryPoint( const QVariantMap &geometryData, QgsWkbTypes::Type pointType )
{
// {"x" : <x>, "y" : <y>, "z" : <z>, "m" : <m>}
bool xok = false, yok = false;
double x = geometryData[QStringLiteral( "x" )].toDouble( &xok );
double y = geometryData[QStringLiteral( "y" )].toDouble( &yok );
if ( !xok || !yok )
return nullptr;
double z = geometryData[QStringLiteral( "z" )].toDouble();
double m = geometryData[QStringLiteral( "m" )].toDouble();
return qgis::make_unique< QgsPoint >( pointType, x, y, z, m );
}
static std::unique_ptr< QgsMultiPoint > parseEsriGeometryMultiPoint( const QVariantMap &geometryData, QgsWkbTypes::Type pointType )
{
// {"points" : [[ <x1>, <y1>, <z1>, <m1> ] , [ <x2>, <y2>, <z2>, <m2> ], ... ]}
const QVariantList coordsList = geometryData[QStringLiteral( "points" )].toList();
std::unique_ptr< QgsMultiPoint > multiPoint = qgis::make_unique< QgsMultiPoint >();
for ( const QVariant &coordData : coordsList )
{
const QVariantList coordList = coordData.toList();
std::unique_ptr< QgsPoint > p = parsePoint( coordList, pointType );
if ( !p )
{
continue;
}
multiPoint->addGeometry( p.release() );
}
// second chance -- sometimes layers are reported as multipoint but features have single
// point geometries. Silently handle this and upgrade to multipoint.
std::unique_ptr< QgsPoint > p = parseEsriGeometryPoint( geometryData, pointType );
if ( p )
multiPoint->addGeometry( p.release() );
if ( multiPoint->numGeometries() == 0 )
{
// didn't find any points, so reset geometry to null
multiPoint.reset();
}
return multiPoint;
}
static std::unique_ptr< QgsMultiCurve > parseEsriGeometryPolyline( const QVariantMap &geometryData, QgsWkbTypes::Type pointType )
{
// {"curvePaths": [[[0,0], {"c": [[3,3],[1,4]]} ]]}
QVariantList pathsList;
if ( geometryData[QStringLiteral( "paths" )].isValid() )
pathsList = geometryData[QStringLiteral( "paths" )].toList();
else if ( geometryData[QStringLiteral( "curvePaths" )].isValid() )
pathsList = geometryData[QStringLiteral( "curvePaths" )].toList();
if ( pathsList.isEmpty() )
return nullptr;
std::unique_ptr< QgsMultiCurve > multiCurve = qgis::make_unique< QgsMultiCurve >();
for ( const QVariant &pathData : qgis::as_const( pathsList ) )
{
std::unique_ptr< QgsCompoundCurve > curve = parseCompoundCurve( pathData.toList(), pointType );
if ( !curve )
{
return nullptr;
}
multiCurve->addGeometry( curve.release() );
}
return multiCurve;
}
static std::unique_ptr< QgsCurvePolygon > parseEsriGeometryPolygon( const QVariantMap &geometryData, QgsWkbTypes::Type pointType )
{
// {"curveRings": [[[0,0], {"c": [[3,3],[1,4]]} ]]}
QVariantList ringsList;
if ( geometryData[QStringLiteral( "rings" )].isValid() )
ringsList = geometryData[QStringLiteral( "rings" )].toList();
else if ( geometryData[QStringLiteral( "ringPaths" )].isValid() )
ringsList = geometryData[QStringLiteral( "ringPaths" )].toList();
if ( ringsList.isEmpty() )
return nullptr;
std::unique_ptr< QgsCurvePolygon > polygon = qgis::make_unique< QgsCurvePolygon >();
std::unique_ptr< QgsCompoundCurve > ext = parseCompoundCurve( ringsList.front().toList(), pointType );
if ( !ext )
{
return nullptr;
}
polygon->setExteriorRing( ext.release() );
for ( int i = 1, n = ringsList.size(); i < n; ++i )
{
std::unique_ptr< QgsCompoundCurve > curve = parseCompoundCurve( ringsList[i].toList(), pointType );
if ( !curve )
{
return nullptr;
}
polygon->addInteriorRing( curve.release() );
}
return polygon;
}
static std::unique_ptr< QgsPolygon > parseEsriEnvelope( const QVariantMap &geometryData )
{
// {"xmin" : -109.55, "ymin" : 25.76, "xmax" : -86.39, "ymax" : 49.94}
bool xminOk = false, yminOk = false, xmaxOk = false, ymaxOk = false;
double xmin = geometryData[QStringLiteral( "xmin" )].toDouble( &xminOk );
double ymin = geometryData[QStringLiteral( "ymin" )].toDouble( &yminOk );
double xmax = geometryData[QStringLiteral( "xmax" )].toDouble( &xmaxOk );
double ymax = geometryData[QStringLiteral( "ymax" )].toDouble( &ymaxOk );
if ( !xminOk || !yminOk || !xmaxOk || !ymaxOk )
return nullptr;
std::unique_ptr< QgsLineString > ext = qgis::make_unique< QgsLineString> ();
ext->addVertex( QgsPoint( xmin, ymin ) );
ext->addVertex( QgsPoint( xmax, ymin ) );
ext->addVertex( QgsPoint( xmax, ymax ) );
ext->addVertex( QgsPoint( xmin, ymax ) );
ext->addVertex( QgsPoint( xmin, ymin ) );
std::unique_ptr< QgsPolygon > poly = qgis::make_unique< QgsPolygon >();
poly->setExteriorRing( ext.release() );
return poly;
}
std::unique_ptr<QgsAbstractGeometry> QgsArcGisRestUtils::parseEsriGeoJSON( const QVariantMap &geometryData, const QString &esriGeometryType, bool readM, bool readZ, QgsCoordinateReferenceSystem *crs )
{
QgsWkbTypes::Type pointType = QgsWkbTypes::zmType( QgsWkbTypes::Point, readZ, readM );
if ( crs )
{
*crs = parseSpatialReference( geometryData[QStringLiteral( "spatialReference" )].toMap() );
}
// http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Geometry_Objects/02r3000000n1000000/
if ( esriGeometryType == QLatin1String( "esriGeometryNull" ) )
return nullptr;
else if ( esriGeometryType == QLatin1String( "esriGeometryPoint" ) )
return parseEsriGeometryPoint( geometryData, pointType );
else if ( esriGeometryType == QLatin1String( "esriGeometryMultipoint" ) )
return parseEsriGeometryMultiPoint( geometryData, pointType );
else if ( esriGeometryType == QLatin1String( "esriGeometryPolyline" ) )
return parseEsriGeometryPolyline( geometryData, pointType );
else if ( esriGeometryType == QLatin1String( "esriGeometryPolygon" ) )
return parseEsriGeometryPolygon( geometryData, pointType );
else if ( esriGeometryType == QLatin1String( "esriGeometryEnvelope" ) )
return parseEsriEnvelope( geometryData );
// Unsupported (either by qgis, or format unspecified by the specification)
// esriGeometryCircularArc
// esriGeometryEllipticArc
// esriGeometryBezier3Curve
// esriGeometryPath
// esriGeometryRing
// esriGeometryLine
// esriGeometryAny
// esriGeometryMultiPatch
// esriGeometryTriangleStrip
// esriGeometryTriangleFan
// esriGeometryRay
// esriGeometrySphere
// esriGeometryTriangles
// esriGeometryBag
return nullptr;
}
QgsCoordinateReferenceSystem QgsArcGisRestUtils::parseSpatialReference( const QVariantMap &spatialReferenceMap )
{
QString spatialReference = spatialReferenceMap[QStringLiteral( "latestWkid" )].toString();
if ( spatialReference.isEmpty() )
spatialReference = spatialReferenceMap[QStringLiteral( "wkid" )].toString();
if ( spatialReference.isEmpty() )
spatialReference = spatialReferenceMap[QStringLiteral( "wkt" )].toString();
else
spatialReference = QStringLiteral( "EPSG:%1" ).arg( spatialReference );
QgsCoordinateReferenceSystem crs;
crs.createFromString( spatialReference );
if ( !crs.isValid() )
{
// If not spatial reference, just use WGS84
crs.createFromString( QStringLiteral( "EPSG:4326" ) );
}
return crs;
}
QVariantMap QgsArcGisRestUtils::getServiceInfo( const QString &baseurl, const QString &authcfg, QString &errorTitle, QString &errorText )
{
// http://sampleserver5.arcgisonline.com/arcgis/rest/services/Energy/Geology/FeatureServer?f=json
QUrl queryUrl( baseurl );
queryUrl.addQueryItem( QStringLiteral( "f" ), QStringLiteral( "json" ) );
return queryServiceJSON( queryUrl, authcfg, errorTitle, errorText );
}
QVariantMap QgsArcGisRestUtils::getLayerInfo( const QString &layerurl, const QString &authcfg, QString &errorTitle, QString &errorText )
{
// http://sampleserver5.arcgisonline.com/arcgis/rest/services/Energy/Geology/FeatureServer/1?f=json
QUrl queryUrl( layerurl );
queryUrl.addQueryItem( QStringLiteral( "f" ), QStringLiteral( "json" ) );
return queryServiceJSON( queryUrl, authcfg, errorTitle, errorText );
}
QVariantMap QgsArcGisRestUtils::getObjectIds( const QString &layerurl, const QString &authcfg, const QString &objectIdFieldName, QString &errorTitle, QString &errorText, const QgsRectangle &bbox )
{
// http://sampleserver5.arcgisonline.com/arcgis/rest/services/Energy/Geology/FeatureServer/1/query?where=objectid%3Dobjectid&returnIdsOnly=true&f=json
QUrl queryUrl( layerurl + "/query" );
queryUrl.addQueryItem( QStringLiteral( "f" ), QStringLiteral( "json" ) );
queryUrl.addQueryItem( QStringLiteral( "where" ), QStringLiteral( "%1=%1" ).arg( objectIdFieldName ) );
queryUrl.addQueryItem( QStringLiteral( "returnIdsOnly" ), QStringLiteral( "true" ) );
if ( !bbox.isNull() )
{
queryUrl.addQueryItem( QStringLiteral( "geometry" ), QStringLiteral( "%1,%2,%3,%4" )
.arg( bbox.xMinimum(), 0, 'f', -1 ).arg( bbox.yMinimum(), 0, 'f', -1 )
.arg( bbox.xMaximum(), 0, 'f', -1 ).arg( bbox.yMaximum(), 0, 'f', -1 ) );
queryUrl.addQueryItem( QStringLiteral( "geometryType" ), QStringLiteral( "esriGeometryEnvelope" ) );
queryUrl.addQueryItem( QStringLiteral( "spatialRel" ), QStringLiteral( "esriSpatialRelEnvelopeIntersects" ) );
}
return queryServiceJSON( queryUrl, authcfg, errorTitle, errorText );
}
QVariantMap QgsArcGisRestUtils::getObjects( const QString &layerurl, const QString &authcfg, const QList<quint32> &objectIds, const QString &crs,
bool fetchGeometry, const QStringList &fetchAttributes,
bool fetchM, bool fetchZ,
const QgsRectangle &filterRect,
QString &errorTitle, QString &errorText, QgsFeedback *feedback )
{
QStringList ids;
for ( int id : objectIds )
{
ids.append( QString::number( id ) );
}
QUrl queryUrl( layerurl + "/query" );
queryUrl.addQueryItem( QStringLiteral( "f" ), QStringLiteral( "json" ) );
queryUrl.addQueryItem( QStringLiteral( "objectIds" ), ids.join( QStringLiteral( "," ) ) );
QString wkid = crs.indexOf( QLatin1String( ":" ) ) >= 0 ? crs.split( ':' )[1] : QString();
queryUrl.addQueryItem( QStringLiteral( "inSR" ), wkid );
queryUrl.addQueryItem( QStringLiteral( "outSR" ), wkid );
QString outFields = fetchAttributes.join( QStringLiteral( "," ) );
if ( fetchGeometry )
{
queryUrl.addQueryItem( QStringLiteral( "returnGeometry" ), QStringLiteral( "true" ) );
queryUrl.addQueryItem( QStringLiteral( "outFields" ), outFields );
}
else
{
queryUrl.addQueryItem( QStringLiteral( "returnGeometry" ), QStringLiteral( "false" ) );
queryUrl.addQueryItem( QStringLiteral( "outFields" ), outFields );
}
queryUrl.addQueryItem( QStringLiteral( "returnM" ), fetchM ? QStringLiteral( "true" ) : QStringLiteral( "false" ) );
queryUrl.addQueryItem( QStringLiteral( "returnZ" ), fetchZ ? QStringLiteral( "true" ) : QStringLiteral( "false" ) );
if ( !filterRect.isNull() )
{
queryUrl.addQueryItem( QStringLiteral( "geometry" ), QStringLiteral( "%1,%2,%3,%4" )
.arg( filterRect.xMinimum(), 0, 'f', -1 ).arg( filterRect.yMinimum(), 0, 'f', -1 )
.arg( filterRect.xMaximum(), 0, 'f', -1 ).arg( filterRect.yMaximum(), 0, 'f', -1 ) );
queryUrl.addQueryItem( QStringLiteral( "geometryType" ), QStringLiteral( "esriGeometryEnvelope" ) );
queryUrl.addQueryItem( QStringLiteral( "spatialRel" ), QStringLiteral( "esriSpatialRelEnvelopeIntersects" ) );
}
return queryServiceJSON( queryUrl, authcfg, errorTitle, errorText, feedback );
}
QList<quint32> QgsArcGisRestUtils::getObjectIdsByExtent( const QString &layerurl, const QString &objectIdField, const QgsRectangle &filterRect, QString &errorTitle, QString &errorText, const QString &authcfg, QgsFeedback *feedback )
{
QUrl queryUrl( layerurl + "/query" );
queryUrl.addQueryItem( QStringLiteral( "f" ), QStringLiteral( "json" ) );
queryUrl.addQueryItem( QStringLiteral( "where" ), QStringLiteral( "%1=%1" ).arg( objectIdField ) );
queryUrl.addQueryItem( QStringLiteral( "returnIdsOnly" ), QStringLiteral( "true" ) );
queryUrl.addQueryItem( QStringLiteral( "geometry" ), QStringLiteral( "%1,%2,%3,%4" )
.arg( filterRect.xMinimum(), 0, 'f', -1 ).arg( filterRect.yMinimum(), 0, 'f', -1 )
.arg( filterRect.xMaximum(), 0, 'f', -1 ).arg( filterRect.yMaximum(), 0, 'f', -1 ) );
queryUrl.addQueryItem( QStringLiteral( "geometryType" ), QStringLiteral( "esriGeometryEnvelope" ) );
queryUrl.addQueryItem( QStringLiteral( "spatialRel" ), QStringLiteral( "esriSpatialRelEnvelopeIntersects" ) );
const QVariantMap objectIdData = queryServiceJSON( queryUrl, authcfg, errorTitle, errorText, feedback );
if ( objectIdData.isEmpty() )
{
return QList<quint32>();
}
QList<quint32> ids;
const QVariantList objectIdsList = objectIdData[QStringLiteral( "objectIds" )].toList();
ids.reserve( objectIdsList.size() );
for ( const QVariant &objectId : objectIdsList )
{
ids << objectId.toInt();
}
return ids;
}
QByteArray QgsArcGisRestUtils::queryService( const QUrl &u, const QString &authcfg, QString &errorTitle, QString &errorText, QgsFeedback *feedback )
{
QEventLoop loop;
QUrl url = parseUrl( u );
QNetworkRequest request( url );
if ( !authcfg.isEmpty() )
{
QgsApplication::authManager()->updateNetworkRequest( request, authcfg );
}
QNetworkReply *reply = nullptr;
QgsNetworkAccessManager *nam = QgsNetworkAccessManager::instance();
// Request data, handling redirects
while ( true )
{
reply = nam->get( request );
QObject::connect( reply, &QNetworkReply::finished, &loop, &QEventLoop::quit );
if ( feedback )
{
QObject::connect( feedback, &QgsFeedback::canceled, reply, &QNetworkReply::abort );
}
loop.exec( QEventLoop::ExcludeUserInputEvents );
reply->deleteLater();
if ( feedback && feedback->isCanceled() )
return QByteArray();
// Handle network errors
if ( reply->error() != QNetworkReply::NoError )
{
QgsDebugMsg( QStringLiteral( "Network error: %1" ).arg( reply->errorString() ) );
errorTitle = QStringLiteral( "Network error" );
errorText = reply->errorString();
return QByteArray();
}
// Handle HTTP redirects
QVariant redirect = reply->attribute( QNetworkRequest::RedirectionTargetAttribute );
if ( redirect.isNull() )
{
break;
}
QgsDebugMsg( "redirecting to " + redirect.toUrl().toString() );
request.setUrl( redirect.toUrl() );
}
QByteArray result = reply->readAll();
return result;
}
QVariantMap QgsArcGisRestUtils::queryServiceJSON( const QUrl &url, const QString &authcfg, QString &errorTitle, QString &errorText, QgsFeedback *feedback )
{
QByteArray reply = queryService( url, authcfg, errorTitle, errorText, feedback );
if ( !errorTitle.isEmpty() )
{
return QVariantMap();
}
if ( feedback && feedback->isCanceled() )
return QVariantMap();
// Parse data
QJsonParseError err;
QJsonDocument doc = QJsonDocument::fromJson( reply, &err );
if ( doc.isNull() )
{
errorTitle = QStringLiteral( "Parsing error" );
errorText = err.errorString();
QgsDebugMsg( QStringLiteral( "Parsing error: %1" ).arg( err.errorString() ) );
return QVariantMap();
}
const QVariantMap res = doc.object().toVariantMap();
if ( res.contains( QStringLiteral( "error" ) ) )
{
const QVariantMap error = res.value( QStringLiteral( "error" ) ).toMap();
errorText = error.value( QStringLiteral( "message" ) ).toString();
errorTitle = QObject::tr( "Error %1" ).arg( error.value( QStringLiteral( "code" ) ).toString() );
return QVariantMap();
}
return res;
}
std::unique_ptr<QgsSymbol> QgsArcGisRestUtils::parseEsriSymbolJson( const QVariantMap &symbolData )
{
const QString type = symbolData.value( QStringLiteral( "type" ) ).toString();
if ( type == QLatin1String( "esriSMS" ) )
{
// marker symbol
return parseEsriMarkerSymbolJson( symbolData );
}
else if ( type == QLatin1String( "esriSLS" ) )
{
// line symbol
return parseEsriLineSymbolJson( symbolData );
}
else if ( type == QLatin1String( "esriSFS" ) )
{
// fill symbol
return parseEsriFillSymbolJson( symbolData );
}
else if ( type == QLatin1String( "esriPFS" ) )
{
return parseEsriPictureFillSymbolJson( symbolData );
}
else if ( type == QLatin1String( "esriPMS" ) )
{
// picture marker
return parseEsriPictureMarkerSymbolJson( symbolData );
}
else if ( type == QLatin1String( "esriTS" ) )
{
// text symbol - not supported
return nullptr;
}
return nullptr;
}
std::unique_ptr<QgsLineSymbol> QgsArcGisRestUtils::parseEsriLineSymbolJson( const QVariantMap &symbolData )
{
QColor lineColor = parseEsriColorJson( symbolData.value( QStringLiteral( "color" ) ) );
if ( !lineColor.isValid() )
return nullptr;
bool ok = false;
double widthInPoints = symbolData.value( QStringLiteral( "width" ) ).toDouble( &ok );
if ( !ok )
return nullptr;
QgsSymbolLayerList layers;
Qt::PenStyle penStyle = parseEsriLineStyle( symbolData.value( QStringLiteral( "style" ) ).toString() );
std::unique_ptr< QgsSimpleLineSymbolLayer > lineLayer = qgis::make_unique< QgsSimpleLineSymbolLayer >( lineColor, widthInPoints, penStyle );
lineLayer->setWidthUnit( QgsUnitTypes::RenderPoints );
layers.append( lineLayer.release() );
std::unique_ptr< QgsLineSymbol > symbol = qgis::make_unique< QgsLineSymbol >( layers );
return symbol;
}
std::unique_ptr<QgsFillSymbol> QgsArcGisRestUtils::parseEsriFillSymbolJson( const QVariantMap &symbolData )
{
QColor fillColor = parseEsriColorJson( symbolData.value( QStringLiteral( "color" ) ) );
Qt::BrushStyle brushStyle = parseEsriFillStyle( symbolData.value( QStringLiteral( "style" ) ).toString() );
const QVariantMap outlineData = symbolData.value( QStringLiteral( "outline" ) ).toMap();
QColor lineColor = parseEsriColorJson( outlineData.value( QStringLiteral( "color" ) ) );
Qt::PenStyle penStyle = parseEsriLineStyle( outlineData.value( QStringLiteral( "style" ) ).toString() );
bool ok = false;
double penWidthInPoints = outlineData.value( QStringLiteral( "width" ) ).toDouble( &ok );
QgsSymbolLayerList layers;
std::unique_ptr< QgsSimpleFillSymbolLayer > fillLayer = qgis::make_unique< QgsSimpleFillSymbolLayer >( fillColor, brushStyle, lineColor, penStyle, penWidthInPoints );
fillLayer->setStrokeWidthUnit( QgsUnitTypes::RenderPoints );
layers.append( fillLayer.release() );
std::unique_ptr< QgsFillSymbol > symbol = qgis::make_unique< QgsFillSymbol >( layers );
return symbol;
}
std::unique_ptr<QgsFillSymbol> QgsArcGisRestUtils::parseEsriPictureFillSymbolJson( const QVariantMap &symbolData )
{
bool ok = false;
double widthInPixels = symbolData.value( QStringLiteral( "width" ) ).toInt( &ok );
if ( !ok )
return nullptr;
const double xScale = symbolData.value( QStringLiteral( "xscale" ) ).toDouble( &ok );
if ( !qgsDoubleNear( xScale, 0.0 ) )
widthInPixels *= xScale;
const double angleCCW = symbolData.value( QStringLiteral( "angle" ) ).toDouble( &ok );
double angleCW = 0;
if ( ok )
angleCW = -angleCCW;
const double xOffset = symbolData.value( QStringLiteral( "xoffset" ) ).toDouble();
const double yOffset = symbolData.value( QStringLiteral( "yoffset" ) ).toDouble();
QString symbolPath( symbolData.value( QStringLiteral( "imageData" ) ).toString() );
symbolPath.prepend( QLatin1String( "base64:" ) );
QgsSymbolLayerList layers;
std::unique_ptr< QgsRasterFillSymbolLayer > fillLayer = qgis::make_unique< QgsRasterFillSymbolLayer >( symbolPath );
fillLayer->setWidth( widthInPixels );
fillLayer->setAngle( angleCW );
fillLayer->setWidthUnit( QgsUnitTypes::RenderPoints );
fillLayer->setOffset( QPointF( xOffset, yOffset ) );
fillLayer->setOffsetUnit( QgsUnitTypes::RenderPoints );
layers.append( fillLayer.release() );
const QVariantMap outlineData = symbolData.value( QStringLiteral( "outline" ) ).toMap();
QColor lineColor = parseEsriColorJson( outlineData.value( QStringLiteral( "color" ) ) );
Qt::PenStyle penStyle = parseEsriLineStyle( outlineData.value( QStringLiteral( "style" ) ).toString() );
double penWidthInPoints = outlineData.value( QStringLiteral( "width" ) ).toDouble( &ok );
std::unique_ptr< QgsSimpleLineSymbolLayer > lineLayer = qgis::make_unique< QgsSimpleLineSymbolLayer >( lineColor, penWidthInPoints, penStyle );
lineLayer->setWidthUnit( QgsUnitTypes::RenderPoints );
layers.append( lineLayer.release() );
std::unique_ptr< QgsFillSymbol > symbol = qgis::make_unique< QgsFillSymbol >( layers );
return symbol;
}
QgsSimpleMarkerSymbolLayerBase::Shape parseEsriMarkerShape( const QString &style )
{
if ( style == QLatin1String( "esriSMSCircle" ) )
return QgsSimpleMarkerSymbolLayerBase::Circle;
else if ( style == QLatin1String( "esriSMSCross" ) )
return QgsSimpleMarkerSymbolLayerBase::Cross;
else if ( style == QLatin1String( "esriSMSDiamond" ) )
return QgsSimpleMarkerSymbolLayerBase::Diamond;
else if ( style == QLatin1String( "esriSMSSquare" ) )
return QgsSimpleMarkerSymbolLayerBase::Square;
else if ( style == QLatin1String( "esriSMSX" ) )
return QgsSimpleMarkerSymbolLayerBase::Cross2;
else if ( style == QLatin1String( "esriSMSTriangle" ) )
return QgsSimpleMarkerSymbolLayerBase::Triangle;
else
return QgsSimpleMarkerSymbolLayerBase::Circle;
}
std::unique_ptr<QgsMarkerSymbol> QgsArcGisRestUtils::parseEsriMarkerSymbolJson( const QVariantMap &symbolData )
{
QColor fillColor = parseEsriColorJson( symbolData.value( QStringLiteral( "color" ) ) );
bool ok = false;
const double sizeInPoints = symbolData.value( QStringLiteral( "size" ) ).toDouble( &ok );
if ( !ok )
return nullptr;
const double angleCCW = symbolData.value( QStringLiteral( "angle" ) ).toDouble( &ok );
double angleCW = 0;
if ( ok )
angleCW = -angleCCW;
QgsSimpleMarkerSymbolLayerBase::Shape shape = parseEsriMarkerShape( symbolData.value( QStringLiteral( "style" ) ).toString() );
const double xOffset = symbolData.value( QStringLiteral( "xoffset" ) ).toDouble();
const double yOffset = symbolData.value( QStringLiteral( "yoffset" ) ).toDouble();
const QVariantMap outlineData = symbolData.value( QStringLiteral( "outline" ) ).toMap();
QColor lineColor = parseEsriColorJson( outlineData.value( QStringLiteral( "color" ) ) );
Qt::PenStyle penStyle = parseEsriLineStyle( outlineData.value( QStringLiteral( "style" ) ).toString() );
double penWidthInPoints = outlineData.value( QStringLiteral( "width" ) ).toDouble( &ok );
QgsSymbolLayerList layers;
std::unique_ptr< QgsSimpleMarkerSymbolLayer > markerLayer = qgis::make_unique< QgsSimpleMarkerSymbolLayer >( shape, sizeInPoints, angleCW, QgsSymbol::ScaleArea, fillColor, lineColor );
markerLayer->setSizeUnit( QgsUnitTypes::RenderPoints );
markerLayer->setStrokeWidthUnit( QgsUnitTypes::RenderPoints );
markerLayer->setStrokeStyle( penStyle );
markerLayer->setStrokeWidth( penWidthInPoints );
markerLayer->setOffset( QPointF( xOffset, yOffset ) );
markerLayer->setOffsetUnit( QgsUnitTypes::RenderPoints );
layers.append( markerLayer.release() );
std::unique_ptr< QgsMarkerSymbol > symbol = qgis::make_unique< QgsMarkerSymbol >( layers );
return symbol;
}
std::unique_ptr<QgsMarkerSymbol> QgsArcGisRestUtils::parseEsriPictureMarkerSymbolJson( const QVariantMap &symbolData )
{
bool ok = false;
const double widthInPixels = symbolData.value( QStringLiteral( "width" ) ).toInt( &ok );
if ( !ok )
return nullptr;
const double heightInPixels = symbolData.value( QStringLiteral( "height" ) ).toInt( &ok );
if ( !ok )
return nullptr;
const double angleCCW = symbolData.value( QStringLiteral( "angle" ) ).toDouble( &ok );
double angleCW = 0;
if ( ok )
angleCW = -angleCCW;
const double xOffset = symbolData.value( QStringLiteral( "xoffset" ) ).toDouble();
const double yOffset = symbolData.value( QStringLiteral( "yoffset" ) ).toDouble();
//const QString contentType = symbolData.value( QStringLiteral( "contentType" ) ).toString();
QString symbolPath( symbolData.value( QStringLiteral( "imageData" ) ).toString() );
symbolPath.prepend( QLatin1String( "base64:" ) );
QgsSymbolLayerList layers;
std::unique_ptr< QgsRasterMarkerSymbolLayer > markerLayer = qgis::make_unique< QgsRasterMarkerSymbolLayer >( symbolPath, widthInPixels, angleCW, QgsSymbol::ScaleArea );
markerLayer->setSizeUnit( QgsUnitTypes::RenderPoints );
// only change the default aspect ratio if the server height setting requires this
if ( !qgsDoubleNear( static_cast< double >( heightInPixels ) / widthInPixels, markerLayer->defaultAspectRatio() ) )
markerLayer->setFixedAspectRatio( static_cast< double >( heightInPixels ) / widthInPixels );
markerLayer->setOffset( QPointF( xOffset, yOffset ) );
markerLayer->setOffsetUnit( QgsUnitTypes::RenderPoints );
layers.append( markerLayer.release() );
std::unique_ptr< QgsMarkerSymbol > symbol = qgis::make_unique< QgsMarkerSymbol >( layers );
return symbol;
}
QgsAbstractVectorLayerLabeling *QgsArcGisRestUtils::parseEsriLabeling( const QVariantList &labelingData )
{
if ( labelingData.empty() )
return nullptr;
QgsRuleBasedLabeling::Rule *root = new QgsRuleBasedLabeling::Rule( new QgsPalLayerSettings(), 0, 0, QString(), QString(), false );
root->setActive( true );
int i = 1;
for ( const QVariant &lbl : labelingData )
{
const QVariantMap labeling = lbl.toMap();
QgsPalLayerSettings *settings = new QgsPalLayerSettings();
QgsTextFormat format;
const QString placement = labeling.value( QStringLiteral( "labelPlacement" ) ).toString();
if ( placement == QLatin1String( "esriServerPointLabelPlacementAboveCenter" ) )
{
settings->placement = QgsPalLayerSettings::OverPoint;
settings->quadOffset = QgsPalLayerSettings::QuadrantAbove;
}
else if ( placement == QLatin1String( "esriServerPointLabelPlacementBelowCenter" ) )
{
settings->placement = QgsPalLayerSettings::OverPoint;
settings->quadOffset = QgsPalLayerSettings::QuadrantBelow;
}
else if ( placement == QLatin1String( "esriServerPointLabelPlacementCenterCenter" ) )
{
settings->placement = QgsPalLayerSettings::OverPoint;
settings->quadOffset = QgsPalLayerSettings::QuadrantOver;
}
else if ( placement == QLatin1String( "esriServerPointLabelPlacementAboveLeft" ) )
{
settings->placement = QgsPalLayerSettings::OverPoint;
settings->quadOffset = QgsPalLayerSettings::QuadrantAboveLeft;
}
else if ( placement == QLatin1String( "esriServerPointLabelPlacementBelowLeft" ) )
{
settings->placement = QgsPalLayerSettings::OverPoint;
settings->quadOffset = QgsPalLayerSettings::QuadrantBelowLeft;
}
else if ( placement == QLatin1String( "esriServerPointLabelPlacementCenterLeft" ) )
{
settings->placement = QgsPalLayerSettings::OverPoint;
settings->quadOffset = QgsPalLayerSettings::QuadrantLeft;
}
else if ( placement == QLatin1String( "esriServerPointLabelPlacementAboveRight" ) )
{
settings->placement = QgsPalLayerSettings::OverPoint;
settings->quadOffset = QgsPalLayerSettings::QuadrantAboveRight;
}
else if ( placement == QLatin1String( "esriServerPointLabelPlacementBelowRight" ) )
{
settings->placement = QgsPalLayerSettings::OverPoint;
settings->quadOffset = QgsPalLayerSettings::QuadrantBelowRight;
}
else if ( placement == QLatin1String( "esriServerPointLabelPlacementCenterRight" ) )
{
settings->placement = QgsPalLayerSettings::OverPoint;
settings->quadOffset = QgsPalLayerSettings::QuadrantRight;
}
else if ( placement == QLatin1String( "esriServerLinePlacementAboveAfter" ) ||
placement == QLatin1String( "esriServerLinePlacementAboveStart" ) ||
placement == QLatin1String( "esriServerLinePlacementAboveAlong" ) )
{
settings->placement = QgsPalLayerSettings::Line;
settings->placementFlags = QgsPalLayerSettings::AboveLine | QgsPalLayerSettings::MapOrientation;
}
else if ( placement == QLatin1String( "esriServerLinePlacementBelowAfter" ) ||
placement == QLatin1String( "esriServerLinePlacementBelowStart" ) ||
placement == QLatin1String( "esriServerLinePlacementBelowAlong" ) )
{
settings->placement = QgsPalLayerSettings::Line;
settings->placementFlags = QgsPalLayerSettings::BelowLine | QgsPalLayerSettings::MapOrientation;
}
else if ( placement == QLatin1String( "esriServerLinePlacementCenterAfter" ) ||
placement == QLatin1String( "esriServerLinePlacementCenterStart" ) ||
placement == QLatin1String( "esriServerLinePlacementCenterAlong" ) )
{
settings->placement = QgsPalLayerSettings::Line;
settings->placementFlags = QgsPalLayerSettings::OnLine | QgsPalLayerSettings::MapOrientation;
}
else if ( placement == QLatin1String( "esriServerPolygonPlacementAlwaysHorizontal" ) )
{
settings->placement = QgsPalLayerSettings::Horizontal;
}
const double minScale = labeling.value( QStringLiteral( "minScale" ) ).toDouble();
const double maxScale = labeling.value( QStringLiteral( "maxScale" ) ).toDouble();
QVariantMap symbol = labeling.value( QStringLiteral( "symbol" ) ).toMap();
format.setColor( parseEsriColorJson( symbol.value( QStringLiteral( "color" ) ) ) );
const double haloSize = symbol.value( QStringLiteral( "haloSize" ) ).toDouble();
if ( !qgsDoubleNear( haloSize, 0.0 ) )
{
QgsTextBufferSettings buffer;
buffer.setEnabled( true );
buffer.setSize( haloSize );
buffer.setSizeUnit( QgsUnitTypes::RenderPoints );
buffer.setColor( parseEsriColorJson( symbol.value( QStringLiteral( "haloColor" ) ) ) );
format.setBuffer( buffer );
}
const QString fontFamily = symbol.value( QStringLiteral( "font" ) ).toMap().value( QStringLiteral( "family" ) ).toString();
const QString fontStyle = symbol.value( QStringLiteral( "font" ) ).toMap().value( QStringLiteral( "style" ) ).toString();
const QString fontWeight = symbol.value( QStringLiteral( "font" ) ).toMap().value( QStringLiteral( "weight" ) ).toString();
const int fontSize = symbol.value( QStringLiteral( "font" ) ).toMap().value( QStringLiteral( "size" ) ).toInt();
QFont font( fontFamily, fontSize );
font.setStyleName( fontStyle );
font.setWeight( fontWeight == QLatin1String( "bold" ) ? QFont::Bold : QFont::Normal );
format.setFont( font );
format.setSize( fontSize );
format.setSizeUnit( QgsUnitTypes::RenderPoints );
settings->setFormat( format );
QString where = labeling.value( QStringLiteral( "where" ) ).toString();
QgsExpression exp( where );
// If the where clause isn't parsed as valid, don't use its
if ( !exp.isValid() )
where.clear();
QString expression = labeling.value( QStringLiteral( "labelExpression" ) ).toString();
settings->fieldName = expression.replace( '[', '"' ).replace( ']', '"' );
settings->isExpression = true;
QgsRuleBasedLabeling::Rule *child = new QgsRuleBasedLabeling::Rule( settings, maxScale, minScale, where, QObject::tr( "ASF label %1" ).arg( i++ ), false );
child->setActive( true );
root->appendChild( child );
}
return new QgsRuleBasedLabeling( root );
}
QgsFeatureRenderer *QgsArcGisRestUtils::parseEsriRenderer( const QVariantMap &rendererData )
{
const QString type = rendererData.value( QStringLiteral( "type" ) ).toString();
if ( type == QLatin1String( "simple" ) )
{
const QVariantMap symbolProps = rendererData.value( QStringLiteral( "symbol" ) ).toMap();
std::unique_ptr< QgsSymbol > symbol = parseEsriSymbolJson( symbolProps );
if ( symbol )
return new QgsSingleSymbolRenderer( symbol.release() );
else
return nullptr;
}
else if ( type == QLatin1String( "uniqueValue" ) )
{
const QString attribute = rendererData.value( QStringLiteral( "field1" ) ).toString();
// TODO - handle field2, field3
const QVariantList categories = rendererData.value( QStringLiteral( "uniqueValueInfos" ) ).toList();
QgsCategoryList categoryList;
for ( const QVariant &category : categories )
{
const QVariantMap categoryData = category.toMap();
const QString value = categoryData.value( QStringLiteral( "value" ) ).toString();
const QString label = categoryData.value( QStringLiteral( "label" ) ).toString();
std::unique_ptr< QgsSymbol > symbol = QgsArcGisRestUtils::parseEsriSymbolJson( categoryData.value( QStringLiteral( "symbol" ) ).toMap() );
if ( symbol )
{
categoryList.append( QgsRendererCategory( value, symbol.release(), label ) );
}
}
std::unique_ptr< QgsSymbol > defaultSymbol = parseEsriSymbolJson( rendererData.value( QStringLiteral( "defaultSymbol" ) ).toMap() );
if ( defaultSymbol )
{
categoryList.append( QgsRendererCategory( QVariant(), defaultSymbol.release(), rendererData.value( QStringLiteral( "defaultLabel" ) ).toString() ) );
}
if ( categoryList.empty() )
return nullptr;
return new QgsCategorizedSymbolRenderer( attribute, categoryList );
}
else if ( type == QLatin1String( "classBreaks" ) )
{
// currently unsupported
return nullptr;
}
else if ( type == QLatin1String( "heatmap" ) )
{
// currently unsupported
return nullptr;
}
else if ( type == QLatin1String( "vectorField" ) )
{
// currently unsupported
return nullptr;
}
return nullptr;
}
QColor QgsArcGisRestUtils::parseEsriColorJson( const QVariant &colorData )
{
const QVariantList colorParts = colorData.toList();
if ( colorParts.count() < 4 )
return QColor();
int red = colorParts.at( 0 ).toInt();
int green = colorParts.at( 1 ).toInt();
int blue = colorParts.at( 2 ).toInt();
int alpha = colorParts.at( 3 ).toInt();
return QColor( red, green, blue, alpha );
}
Qt::PenStyle QgsArcGisRestUtils::parseEsriLineStyle( const QString &style )
{
if ( style == QLatin1String( "esriSLSSolid" ) )
return Qt::SolidLine;
else if ( style == QLatin1String( "esriSLSDash" ) )
return Qt::DashLine;
else if ( style == QLatin1String( "esriSLSDashDot" ) )
return Qt::DashDotLine;
else if ( style == QLatin1String( "esriSLSDashDotDot" ) )
return Qt::DashDotDotLine;
else if ( style == QLatin1String( "esriSLSDot" ) )
return Qt::DotLine;
else if ( style == QLatin1String( "esriSLSNull" ) )
return Qt::NoPen;
else
return Qt::SolidLine;
}
Qt::BrushStyle QgsArcGisRestUtils::parseEsriFillStyle( const QString &style )
{
if ( style == QLatin1String( "esriSFSBackwardDiagonal" ) )