/
qgswmscapabilities.h
1175 lines (966 loc) · 33.5 KB
/
qgswmscapabilities.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
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
/***************************************************************************
qgswmscapabilities.h
---------------------
begin : January 2014
copyright : (C) 2014 by Martin Dobias
email : wonder dot sk at gmail dot 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. *
* *
***************************************************************************/
#ifndef QGSWMSCAPABILITIES_H
#define QGSWMSCAPABILITIES_H
#include <QHash>
#include <QMap>
#include <QNetworkRequest>
#include <QStringList>
#include <QVector>
#include "qgsauthmanager.h"
#include "qgsraster.h"
#include "qgsrectangle.h"
#include "qgsrasteriterator.h"
#include "qgsapplication.h"
#include "qgsdataprovider.h"
#include "qgsinterval.h"
class QNetworkReply;
/*
* The following structs reflect the WMS XML schema,
* as illustrated in Appendix E of the Web Map Service standard, version 1.3, 2004-08-02.
*/
//! OnlineResource Attribute structure
// TODO: Fill to WMS specifications
struct QgsWmsOnlineResourceAttribute
{
QString xlinkHref;
};
//! Gets Property structure
// TODO: Fill to WMS specifications
struct QgsWmsGetProperty
{
QgsWmsOnlineResourceAttribute onlineResource;
};
//! Post Property structure
// TODO: Fill to WMS specifications
struct QgsWmsPostProperty
{
QgsWmsOnlineResourceAttribute onlineResource;
};
//! HTTP Property structure
// TODO: Fill to WMS specifications
struct QgsWmsHttpProperty
{
QgsWmsGetProperty get;
QgsWmsPostProperty post; // can be null
};
//! DCP Type Property structure
// TODO: Fill to WMS specifications
struct QgsWmsDcpTypeProperty
{
QgsWmsHttpProperty http;
};
//! Operation Type structure (for GetMap and GetFeatureInfo)
// TODO: Fill to WMS specifications
struct QgsWmsOperationType
{
QStringList format;
QVector<QgsWmsDcpTypeProperty> dcpType;
QStringList allowedEncodings;
};
//! Request Property structure
// TODO: Fill to WMS specifications
struct QgsWmsRequestProperty
{
// QgsWmsGetCapabilitiesProperty ...
// -- don't include since if we can get the capabilities,
// we already know what's in this part.
QgsWmsOperationType getMap;
QgsWmsOperationType getFeatureInfo;
QgsWmsOperationType getTile;
QgsWmsOperationType getLegendGraphic;
};
//! Exception Property structure
// TODO: Fill to WMS specifications
struct QgsWmsExceptionProperty
{
QStringList format; // text formats supported.
};
//! Primary Contact Person Property structure
struct QgsWmsContactPersonPrimaryProperty
{
QString contactPerson;
QString contactOrganization;
};
//! Contact Address Property structure
struct QgsWmsContactAddressProperty
{
QString addressType;
QString address;
QString city;
QString stateOrProvince;
QString postCode;
QString country;
};
//! Contact Information Property structure
struct QgsWmsContactInformationProperty
{
QgsWmsContactPersonPrimaryProperty contactPersonPrimary;
QString contactPosition;
QgsWmsContactAddressProperty contactAddress;
QString contactVoiceTelephone;
QString contactFacsimileTelephone;
QString contactElectronicMailAddress;
};
//! Service Property structure
// TODO: Fill to WMS specifications
struct QgsWmsServiceProperty
{
QString title;
QString abstract;
QStringList keywordList;
QgsWmsOnlineResourceAttribute onlineResource;
QgsWmsContactInformationProperty contactInformation;
QString fees;
QString accessConstraints;
uint layerLimit = 0;
uint maxWidth = 0;
uint maxHeight = 0;
};
//! Bounding Box Property structure
// TODO: Fill to WMS specifications
struct QgsWmsBoundingBoxProperty
{
QString crs;
QgsRectangle box; // consumes minx, miny, maxx, maxy.
};
/**
* \brief Dimension Property structure.
*
* Contains the optional dimension element,
* the element can be present in Service or Layer metadata
*/
struct QgsWmsDimensionProperty
{
//! Name of the dimensional axis eg. time
QString name;
//! Units of the dimensional axis, defined from UCUM. Can be null.
QString units;
//! Optional, unit symbol a 7-bit ASCII character string also defined from UCUM.
QString unitSymbol;
//! Optional, default value to be used in GetMap request
QString defaultValue; // plain "default" is a reserved word
//! Text containing available value(s) for the dimension
QString extent;
//! Optional, determines whether multiple values of the dimension can be requested
bool multipleValues = false;
//! Optional, whether nearest value of the dimension will be returned, if requested.
bool nearestValue = false;
//! Optional, valid only for temporal exents, determines whether data are normally kept current.
bool current = false;
//! Parse the dimension extent to QgsDateTimeRange instance
QgsDateTimeRange parseExtent() const
{
if ( extent.contains( '/' ) )
{
QStringList extentContent = extent.split( '/' );
int extentSize = extentContent.size();
QDateTime start = QDateTime::fromString( extentContent.at( 0 ), Qt::ISODateWithMs );
QDateTime end = QDateTime::fromString( extentContent.at( extentSize - 2 ), Qt::ISODateWithMs );
if ( start.isValid() & end.isValid() )
return QgsDateTimeRange( start, end );
}
return QgsDateTimeRange();
}
bool operator== ( const QgsWmsDimensionProperty &other ) const
{
return name == other.name && units == other.units &&
unitSymbol == other.unitSymbol && defaultValue == other.defaultValue &&
extent == other.extent && multipleValues == other.multipleValues &&
nearestValue == other.nearestValue && current == other.current;
}
};
//! Logo URL Property structure
// TODO: Fill to WMS specifications
struct QgsWmsLogoUrlProperty
{
QString format;
QgsWmsOnlineResourceAttribute onlineResource;
int width;
int height;
};
//! Attribution Property structure
// TODO: Fill to WMS specifications
struct QgsWmsAttributionProperty
{
QString title;
QgsWmsOnlineResourceAttribute onlineResource;
QgsWmsLogoUrlProperty logoUrl;
};
//! Legend URL Property structure
// TODO: Fill to WMS specifications
struct QgsWmsLegendUrlProperty
{
QString format;
QgsWmsOnlineResourceAttribute onlineResource;
int width;
int height;
};
//! StyleSheet URL Property structure
// TODO: Fill to WMS specifications
struct QgsWmsStyleSheetUrlProperty
{
QString format;
QgsWmsOnlineResourceAttribute onlineResource;
};
//! Style URL Property structure
// TODO: Fill to WMS specifications
struct QgsWmsStyleUrlProperty
{
QString format;
QgsWmsOnlineResourceAttribute onlineResource;
};
//! Style Property structure
// TODO: Fill to WMS specifications
struct QgsWmsStyleProperty
{
QString name;
QString title;
QString abstract;
QVector<QgsWmsLegendUrlProperty> legendUrl;
QgsWmsStyleSheetUrlProperty styleSheetUrl;
QgsWmsStyleUrlProperty styleUrl;
};
//! Authority URL Property structure
// TODO: Fill to WMS specifications
struct QgsWmsAuthorityUrlProperty
{
QgsWmsOnlineResourceAttribute onlineResource;
QString name; // XML "NMTOKEN" type
};
//! Identifier Property structure
// TODO: Fill to WMS specifications
struct QgsWmsIdentifierProperty
{
QString authority;
};
//! Metadata URL Property structure
// TODO: Fill to WMS specifications
struct QgsWmsMetadataUrlProperty
{
QString format;
QgsWmsOnlineResourceAttribute onlineResource;
QString type; // XML "NMTOKEN" type
};
//! Data List URL Property structure
// TODO: Fill to WMS specifications
struct QgsWmsDataListUrlProperty
{
QString format;
QgsWmsOnlineResourceAttribute onlineResource;
};
//! Feature List URL Property structure
// TODO: Fill to WMS specifications
struct QgsWmsFeatureListUrlProperty
{
QString format;
QgsWmsOnlineResourceAttribute onlineResource;
};
//! Layer Property structure
// TODO: Fill to WMS specifications
struct QgsWmsLayerProperty
{
// WMS layer properties
int orderId;
QString name;
QString title;
QString abstract;
QStringList keywordList;
QStringList crs; // coord ref sys
QgsRectangle ex_GeographicBoundingBox;
QVector<QgsWmsBoundingBoxProperty> boundingBoxes;
QgsWmsAttributionProperty attribution;
QVector<QgsWmsAuthorityUrlProperty> authorityUrl;
QVector<QgsWmsIdentifierProperty> identifier;
QVector<QgsWmsDimensionProperty> dimensions;
QVector<QgsWmsMetadataUrlProperty> metadataUrl;
QVector<QgsWmsDataListUrlProperty> dataListUrl;
QVector<QgsWmsFeatureListUrlProperty> featureListUrl;
QVector<QgsWmsStyleProperty> style;
double minimumScaleDenominator;
double maximumScaleDenominator;
QVector<QgsWmsLayerProperty> layer; // nested layers
// WMS layer attributes
bool queryable;
int cascaded;
bool opaque;
bool noSubsets;
int fixedWidth;
int fixedHeight;
// TODO need to expand this to cover more of layer properties
bool equal( const QgsWmsLayerProperty &layerProperty )
{
if ( !( name == layerProperty.name ) )
return false;
if ( !( title == layerProperty.title ) )
return false;
if ( !( abstract == layerProperty.abstract ) )
return false;
if ( !( dimensions == layerProperty.dimensions ) )
return false;
return true;
}
/**
* Returns true if it the struct has the dimension with the passed name
*/
bool hasDimension( QString dimensionName ) const
{
if ( dimensions.isEmpty() )
return false;
for ( const QgsWmsDimensionProperty &dimension : qgis::as_const( dimensions ) )
{
if ( dimension.name == dimensionName )
return true;
}
return false;
}
/**
* Attempts to return a preferred CRS from the list of available CRS definitions.
*
* Prioritizes the first listed CRS, unless it's a block listed value.
*/
QString preferredAvailableCrs() const
{
static QSet< QString > sSkipList { QStringLiteral( "EPSG:900913" ) };
for ( const QString &candidate : crs )
{
if ( sSkipList.contains( candidate ) )
continue;
return candidate;
}
return crs.value( 0 );
}
};
/**
* Stores the dates parts from the WMS-T dimension extent.
*
*/
struct QgsWmstDates
{
QgsWmstDates( QList< QDateTime > dates )
{
dateTimes = dates;
}
QgsWmstDates()
{
}
bool operator== ( const QgsWmstDates &other )
{
return dateTimes == other.dateTimes;
}
QList< QDateTime > dateTimes;
};
/**
* Stores resolution part of the WMS-T dimension extent.
*
* If resolution does not exist, active() will return false;
*/
struct QgsWmstResolution
{
int year = -1;
int month = -1;
int day = -1;
int hour = -1;
int minutes = -1;
int seconds = -1;
long long interval() const
{
long long secs = 0.0;
if ( year != -1 )
secs += year * QgsInterval::YEARS ;
if ( month != -1 )
secs += month * QgsInterval::MONTHS;
if ( day != -1 )
secs += day * QgsInterval::DAY;
if ( hour != -1 )
secs += hour * QgsInterval::HOUR;
if ( minutes != -1 )
secs += minutes * QgsInterval::MINUTE;
if ( seconds != -1 )
secs += seconds;
return secs;
}
bool active() const
{
return year != -1 || month != -1 || day != -1 ||
hour != -1 || minutes != -1 || seconds != -1;
}
QString text() const
{
QString text( "P" );
if ( year != -1 )
{
text.append( QString::number( year ) );
text.append( 'Y' );
}
if ( month != -1 )
{
text.append( QString::number( month ) );
text.append( 'M' );
}
if ( day != -1 )
{
text.append( QString::number( day ) );
text.append( 'D' );
}
if ( hour != -1 )
{
if ( !text.contains( 'T' ) )
text.append( 'T' );
text.append( QString::number( hour ) );
text.append( 'H' );
}
if ( minutes != -1 )
{
if ( !text.contains( 'T' ) )
text.append( 'T' );
text.append( QString::number( minutes ) );
text.append( 'M' );
}
if ( seconds != -1 )
{
if ( !text.contains( 'T' ) )
text.append( 'T' );
text.append( QString::number( seconds ) );
text.append( 'S' );
}
return text;
}
bool operator==( const QgsWmstResolution &other ) const
{
return year == other.year && month == other.month &&
day == other.day && hour == other.hour &&
minutes == other.minutes && seconds == other.seconds;
}
};
/**
* Stores dates and resolution structure pair.
*/
struct QgsWmstExtentPair
{
QgsWmstExtentPair()
{
}
QgsWmstExtentPair( QgsWmstDates otherDates, QgsWmstResolution otherResolution )
{
dates = otherDates;
resolution = otherResolution;
}
bool operator ==( const QgsWmstExtentPair &other )
{
return dates == other.dates &&
resolution == other.resolution;
}
QgsWmstDates dates;
QgsWmstResolution resolution;
};
/**
* Stores the WMS-T dimension extent.
*/
struct QgsWmstDimensionExtent
{
QList <QgsWmstExtentPair> datesResolutionList;
};
struct QgsWmtsTheme
{
QString identifier;
QString title, abstract;
QStringList keywords;
QgsWmtsTheme *subTheme = nullptr;
QStringList layerRefs;
QgsWmtsTheme() = default;
~QgsWmtsTheme() { delete subTheme; }
};
struct QgsWmtsTileMatrixLimits;
struct QgsWmtsTileMatrix
{
QString identifier;
QString title, abstract;
QStringList keywords;
double scaleDenom = 0;
QgsPointXY topLeft; //!< Top-left corner of the tile matrix in map units
int tileWidth; //!< Width of a tile in pixels
int tileHeight; //!< Height of a tile in pixels
int matrixWidth; //!< Number of tiles horizontally
int matrixHeight; //!< Number of tiles vertically
double tres; //!< Pixel span in map units
/**
* Returns extent of a tile in map coordinates.
* (same function as tileBBox() but returns QRectF instead of QgsRectangle)
*/
QRectF tileRect( int col, int row ) const;
/**
* Returns extent of a tile in map coordinates
* (same function as tileRect() but returns QgsRectangle instead of QRectF)
*/
QgsRectangle tileBBox( int col, int row ) const;
/**
* Returns range of tiles that intersects with the view extent
* (\a tml may be NULLPTR)
*/
void viewExtentIntersection( const QgsRectangle &viewExtent, const QgsWmtsTileMatrixLimits *tml, int &col0, int &row0, int &col1, int &row1 ) const;
};
struct QgsWmtsTileMatrixSet
{
QString identifier; //!< Tile matrix set identifier
QString title; //!< Human readable tile matrix set name
QString abstract; //!< Brief description of the tile matrix set
QStringList keywords; //!< List of words/phrases to describe the dataset
QString crs; //!< CRS of the tile matrix set
QString wkScaleSet; //!< Optional reference to a well-known scale set
//! available tile matrixes (key = pixel span in map units)
QMap<double, QgsWmtsTileMatrix> tileMatrices;
//! Returns closest tile resolution to the requested one. (resolution = width [map units] / with [pixels])
const QgsWmtsTileMatrix *findNearestResolution( double vres ) const;
//! Returns the tile matrix for other near resolution from given tres (positive offset = lower resolution tiles)
const QgsWmtsTileMatrix *findOtherResolution( double tres, int offset ) const;
};
enum QgsTileMode { WMTS, WMSC, XYZ };
struct QgsWmtsTileMatrixLimits
{
QString tileMatrix;
int minTileRow, maxTileRow;
int minTileCol, maxTileCol;
};
struct QgsWmtsTileMatrixSetLink
{
QString tileMatrixSet;
QHash<QString, QgsWmtsTileMatrixLimits> limits;
};
struct QgsWmtsLegendURL
{
QString format;
double minScale, maxScale;
QString href;
int width, height;
};
struct QgsWmtsStyle
{
QString identifier;
QString title, abstract;
QStringList keywords;
bool isDefault = false;
QList<QgsWmtsLegendURL> legendURLs;
};
/**
* In case of multi-dimensional data, the service metadata can describe their multi-
* dimensionality and tiles can be requested at specific values in these dimensions.
* Examples of dimensions are Time, Elevation and Band.
*/
struct QgsWmtsDimension
{
QString identifier; //!< Name of the dimensional axis
QString title; //!< Human readable name
QString abstract; //!< Brief description of the dimension
QStringList keywords; //!< List of words/phrases to describe the dataset
QString UOM; //!< Units of measure of dimensional axis
QString unitSymbol; //!< Symbol of the units
QString defaultValue; //!< Default value to be used if value is not specified in request
bool current; //!< Indicates whether temporal data are normally kept current
QStringList values; //!< Available values for this dimension
};
struct QgsWmtsTileLayer
{
enum QgsTileMode tileMode;
QString identifier;
QString title, abstract;
QStringList keywords;
QVector<QgsWmsBoundingBoxProperty> boundingBoxes;
QStringList formats;
QStringList infoFormats;
QString defaultStyle;
int dpi = -1; //!< DPI of the tile layer (-1 for unknown DPI)
//! available dimensions (optional, for multi-dimensional data)
QHash<QString, QgsWmtsDimension> dimensions;
QHash<QString, QgsWmtsStyle> styles;
QHash<QString, QgsWmtsTileMatrixSetLink> setLinks;
QHash<QString, QString> getTileURLs;
QHash<QString, QString> getFeatureInfoURLs;
};
//! Capability Property structure
// TODO: Fill to WMS specifications
struct QgsWmsCapabilityProperty
{
QgsWmsRequestProperty request;
QgsWmsExceptionProperty exception;
// Top level layer should normally be present max once
// <element name="Capability">
// <element ref="wms:Layer" minOccurs="0"/> - default maxOccurs=1
// but there are a few non conformant capabilities around (#13762)
QList<QgsWmsLayerProperty> layers;
QList<QgsWmtsTileLayer> tileLayers;
QHash<QString, QgsWmtsTileMatrixSet> tileMatrixSets;
};
//! Capabilities Property structure
// TODO: Fill to WMS specifications
struct QgsWmsCapabilitiesProperty
{
QgsWmsServiceProperty service;
QgsWmsCapabilityProperty capability;
QString version;
};
//! Formats supported by QImageReader
struct QgsWmsSupportedFormat
{
QString format;
QString label;
};
enum QgsWmsTileAttribute
{
TileReqNo = QNetworkRequest::User + 0,
TileIndex = QNetworkRequest::User + 1,
TileRect = QNetworkRequest::User + 2,
TileRetry = QNetworkRequest::User + 3,
};
enum QgsWmsDpiMode
{
DpiNone = 0,
DpiQGIS = 1,
DpiUMN = 2,
DpiGeoServer = 4,
DpiAll = DpiQGIS | DpiUMN | DpiGeoServer,
};
struct QgsWmsParserSettings
{
QgsWmsParserSettings( bool ignAxis = false, bool invAxis = false )
: ignoreAxisOrientation( ignAxis )
, invertAxisOrientation( invAxis )
{}
bool ignoreAxisOrientation;
bool invertAxisOrientation;
};
struct QgsWmsAuthorization
{
QgsWmsAuthorization( const QString &userName = QString(), const QString &password = QString(), const QString &referer = QString(), const QString &authcfg = QString() )
: mUserName( userName )
, mPassword( password )
, mReferer( referer )
, mAuthCfg( authcfg )
{}
bool setAuthorization( QNetworkRequest &request ) const
{
if ( !mAuthCfg.isEmpty() )
{
return QgsApplication::authManager()->updateNetworkRequest( request, mAuthCfg );
}
else if ( !mUserName.isEmpty() || !mPassword.isEmpty() )
{
request.setRawHeader( "Authorization", "Basic " + QStringLiteral( "%1:%2" ).arg( mUserName, mPassword ).toUtf8().toBase64() );
}
if ( !mReferer.isEmpty() )
{
request.setRawHeader( "Referer", mReferer.toLatin1() );
}
return true;
}
//! Sets authorization reply
bool setAuthorizationReply( QNetworkReply *reply ) const
{
if ( !mAuthCfg.isEmpty() )
{
return QgsApplication::authManager()->updateNetworkReply( reply, mAuthCfg );
}
return true;
}
//! Username for basic http authentication
QString mUserName;
//! Password for basic http authentication
QString mPassword;
//! Referer for http requests
QString mReferer;
//! Authentication configuration ID
QString mAuthCfg;
};
//! URI that gets passed to provider
class QgsWmsSettings
{
public:
bool parseUri( const QString &uriString );
QString baseUrl() const { return mBaseUrl; }
QgsWmsAuthorization authorization() const { return mAuth; }
QgsWmsParserSettings parserSettings() const { return mParserSettings; }
/**
* Parse the given string extent into a well defined dates and resolution structures.
* The string extent comes from WMS-T dimension capabilities.
*
* \since QGIS 3.14
*/
QgsWmstDimensionExtent parseTemporalExtent( const QString &extent );
/**
* Sets the dimension extent property
*
* \see timeDimensionExtent()
* \since QGIS 3.14
*/
void setTimeDimensionExtent( const QgsWmstDimensionExtent &timeDimensionExtent );
/**
* Returns the dimension extent property.
*
* \see setTimeDimensionExtent()
* \since QGIS 3.14
*/
QgsWmstDimensionExtent timeDimensionExtent() const;
/**
* Parse the given string item into a resolution structure.
*
* \since QGIS 3.14
*/
QgsWmstResolution parseWmstResolution( const QString &item );
/**
* Parse the given string item into QDateTime instant.
*
* \since QGIS 3.14
*/
QDateTime parseWmstDateTimes( const QString &item );
/**
* Returns the datetime with the sum of passed \a dateTime and the \a resolution time.
*
* \since QGIS 3.14
*/
QDateTime addTime( const QDateTime &dateTime, const QgsWmstResolution &resolution );
/**
* Finds the least closest datetime from list of available dimension temporal ranges
* with the given \a dateTime.
*
* \note It works with wms-t capabilities that provide time dimension with temporal ranges only.
*
* \since QGIS 3.14
*/
QDateTime findLeastClosestDateTime( const QDateTime &dateTime, bool dateOnly = false ) const;
protected:
QgsWmsParserSettings mParserSettings;
//! layer is tiled, tile layer and active matrix set
bool mTiled;
//! whether we actually work with XYZ tiles instead of WMS / WMTS
bool mXyz;
//! Whether we are dealing with WMS-T
bool mIsTemporal = false;
//! Whether we are dealing bi-temporal dimensional WMS-T
bool mIsBiTemporal = false;
//! Temporal extent from dimension property in WMS-T
QString mTemporalExtent;
//! Fixed temporal range for the data provider
QgsDateTimeRange mFixedRange;
//! Fixed reference temporal range for the data provider
QgsDateTimeRange mFixedReferenceRange;
//! Stores WMS-T time dimension extent dates
QgsWmstDimensionExtent mTimeDimensionExtent;
//! Stores WMS-T reference dimension extent dates
QgsWmstDimensionExtent mReferenceTimeDimensionExtent;
//! whether we are dealing with MBTiles file rather than using network-based tiles
bool mIsMBTiles = false;
//! chosen values for dimensions in case of multi-dimensional data (key=dim id, value=dim value)
QHash<QString, QString> mTileDimensionValues;
//! name of the chosen tile matrix set
QString mTileMatrixSetId;
/**
* Maximum width and height of getmap requests
*/
int mMaxWidth;
int mMaxHeight;
/**
* Step size when iterating the layer
*/
int mStepWidth = QgsRasterIterator::DEFAULT_MAXIMUM_TILE_WIDTH;
int mStepHeight = QgsRasterIterator::DEFAULT_MAXIMUM_TILE_HEIGHT;
//! Data source URI of the WMS for this layer
QString mHttpUri;
//! URL part of URI (httpuri)
QString mBaseUrl;
QgsWmsAuthorization mAuth;
bool mIgnoreGetMapUrl;
bool mIgnoreGetFeatureInfoUrl;
bool mIgnoreReportedLayerExtents = false;
bool mSmoothPixmapTransform;
enum QgsWmsDpiMode mDpiMode;
/**
* Active sublayers managed by this provider in a draw function, in order from bottom to top
* (some may not be visible in a draw function, cf. activeSubLayerVisibility)
*/
QStringList mActiveSubLayers;
QStringList mActiveSubStyles;
//! Opacities for wms layers. Same ordering as mActiveSubLayers/mActiveSubStyles
QStringList mOpacities;
/**
* Visibility status of the given active sublayer
*/
QMap<QString, bool> mActiveSubLayerVisibility;
//! FEATURE_COUNT for GetFeatureInfo
int mFeatureCount;
/**
* MIME type of the image encoding used from the WMS server
*/
QString mImageMimeType;
QString mCrsId;
bool mEnableContextualLegend;
friend class QgsWmsProvider;
};
//! Keeps information about capabilities of particular URI
class QgsWmsCapabilities
{
public:
/**
* Constructs a QgsWmsCapabilities object with the given \a coordinateTransformContext
*/
QgsWmsCapabilities( const QgsCoordinateTransformContext &coordinateTransformContext = QgsCoordinateTransformContext(), const QString &baseUrl = QString() );
bool isValid() const { return mValid; }
bool parseResponse( const QByteArray &response, QgsWmsParserSettings settings );
QString lastError() const { return mError; }
QString lastErrorFormat() const { return mErrorFormat; }
QgsWmsCapabilitiesProperty capabilitiesProperty() { return mCapabilities; }
/**
* \brief Returns a list of the supported layers of the WMS server
*
* \returns The list of layers will be placed here.
*
* \todo Document this better
*/
QVector<QgsWmsLayerProperty> supportedLayers() const { return mLayersSupported; }
//! Gets raster image encodings supported by the WMS, expressed as MIME types
QStringList supportedImageEncodings() const { return mCapabilities.capability.request.getMap.format; }
/**
* \brief Returns a map for the hierarchy of layers
*/
void layerParents( QMap<int, int> &parents, QMap<int, QStringList> &parentNames ) const { parents = mLayerParents; parentNames = mLayerParentNames; }
/**
* \brief Returns a list of the supported tile layers of the WMS server
*
* \returns The list of tile sets will be placed here.
*/