QGIS API Documentation 3.27.0-Master (75dc696944)
qgsowssourcewidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsowssourcewidget.cpp
3 --------------------------------------
4 Date : November 2021
5 Copyright : (C) 2021 by Samweli Mwakisambwe
6 Email : samweli at kartoza dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#include "qgsowssourcewidget.h"
19#include "qgsproviderregistry.h"
20#include "qgsmapcanvas.h"
21
22#include <QNetworkRequest>
23
24
25QgsOWSSourceWidget::QgsOWSSourceWidget( const QString &providerKey, QWidget *parent )
26 : QgsProviderSourceWidget( parent )
27 , mProviderKey( providerKey )
28{
29 setupUi( this );
30
31 QgsCoordinateReferenceSystem destinationCrs;
32 QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) );
33 mSpatialExtentBox->setOutputCrs( crs );
34}
35
36
38{
40
41 QgsCoordinateReferenceSystem destinationCrs;
42 QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) );
43
44 if ( mapCanvas() && mapCanvas()->mapSettings().destinationCrs().isValid() )
45 destinationCrs = mapCanvas()->mapSettings().destinationCrs();
46 else
47 destinationCrs = crs;
48
49 mSpatialExtentBox->setOutputCrs( destinationCrs );
50 mSpatialExtentBox->setMapCanvas( mapCanvas() );
51}
52
53
55{
56 QgsCoordinateReferenceSystem destinationCrs;
57 QgsCoordinateReferenceSystem crs = QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4326" ) );
58 mSpatialExtentBox->setOutputCrs( crs );
59
60 if ( mapCanvas() && mapCanvas()->mapSettings().destinationCrs().isValid() )
61 destinationCrs = mapCanvas()->mapSettings().destinationCrs();
62 else
63 destinationCrs = crs;
64 mSpatialExtentBox->setCurrentExtent( extent, destinationCrs );
65 mSpatialExtentBox->setOutputExtentFromCurrent();
66 mSpatialExtentBox->setMapCanvas( mapCanvas() );
67}
68
70{
71 return mSpatialExtentBox->outputExtent();
72}
73
74void QgsOWSSourceWidget::setSourceUri( const QString &uri )
75{
76 mSourceParts = QgsProviderRegistry::instance()->decodeUri( mProviderKey, uri );
77 bool inverted = mSourceParts.value( QStringLiteral( "InvertAxisOrientation" ) ).toBool();
78
79 QString bbox = mSourceParts.value( QStringLiteral( "bbox" ) ).toString();
81 if ( !bbox.isEmpty() )
82 {
83 QStringList coords = bbox.split( ',' );
84 extent = inverted ? QgsRectangle(
85 coords.takeAt( 1 ).toDouble(),
86 coords.takeAt( 0 ).toDouble(),
87 coords.takeAt( 2 ).toDouble(),
88 coords.takeAt( 3 ).toDouble() ) :
90 coords.takeAt( 0 ).toDouble(),
91 coords.takeAt( 1 ).toDouble(),
92 coords.takeAt( 2 ).toDouble(),
93 coords.takeAt( 3 ).toDouble() );
94 }
95 else
96 {
98 }
99
100 setExtent( extent );
101 mSpatialExtentBox->setChecked( !extent.isNull() );
102}
103
105{
106 QVariantMap parts = mSourceParts;
107
108 QgsRectangle spatialExtent = extent();
109
110 if ( mSpatialExtentBox->isChecked() && !spatialExtent.isNull() )
111 {
112 bool inverted = parts.value( QStringLiteral( "InvertAxisOrientation" ) ).toBool();
113
114 QString bbox = QString( inverted ? "%2,%1,%4,%3" : "%1,%2,%3,%4" )
115 .arg( qgsDoubleToString( spatialExtent.xMinimum() ),
116 qgsDoubleToString( spatialExtent.yMinimum() ),
117 qgsDoubleToString( spatialExtent.xMaximum() ),
118 qgsDoubleToString( spatialExtent.yMaximum() ) );
119
120 parts.insert( QStringLiteral( "bbox" ), bbox );
121 }
122
123
124 return QgsProviderRegistry::instance()->encodeUri( mProviderKey, parts );
125}
126
This class represents a coordinate reference system (CRS).
Map canvas is a class for displaying all GIS data types on a canvas.
Definition: qgsmapcanvas.h:90
const QgsMapSettings & mapSettings() const
Gets access to properties used for map rendering.
QgsCoordinateReferenceSystem destinationCrs() const
Returns the destination coordinate reference system for the map render.
QgsRectangle extent() const
Returns the spatial extent from the widget extent box.
QgsOWSSourceWidget(const QString &providerKey, QWidget *parent=nullptr)
Constructor for QgsOWSSourceWidget with the specified provider key and parent widget.
void setExtent(const QgsRectangle &extent)
Sets the spatial extent in the widget extent box.
void setMapCanvas(QgsMapCanvas *canvas) override
Sets a map canvas associated with the widget.
void setSourceUri(const QString &uri) override
Sets the source uri to show in the widget.
QString sourceUri() const override
Returns the source URI as currently defined by the widget.
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
QString encodeUri(const QString &providerKey, const QVariantMap &parts)
Reassembles a provider data source URI from its component paths (e.g.
Base class for widgets which allow customization of a provider's source URI.
virtual QgsMapCanvas * mapCanvas()
Returns the map canvas associated with the widget.
virtual void setMapCanvas(QgsMapCanvas *mapCanvas)
Sets a map canvas associated with the widget.
A rectangle specified with double values.
Definition: qgsrectangle.h:42
double yMaximum() const SIP_HOLDGIL
Returns the y maximum value (top side of rectangle).
Definition: qgsrectangle.h:193
double xMaximum() const SIP_HOLDGIL
Returns the x maximum value (right side of rectangle).
Definition: qgsrectangle.h:183
double xMinimum() const SIP_HOLDGIL
Returns the x minimum value (left side of rectangle).
Definition: qgsrectangle.h:188
double yMinimum() const SIP_HOLDGIL
Returns the y minimum value (bottom side of rectangle).
Definition: qgsrectangle.h:198
bool isNull() const
Test if the rectangle is null (all coordinates zero or after call to setMinimal()).
Definition: qgsrectangle.h:479
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition: qgis.h:2343
const QgsCoordinateReferenceSystem & crs