QGIS API Documentation  2.99.0-Master (6a61179)
qgsxmlutils.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsxmlutils.cpp
3  ---------------------
4  begin : December 2013
5  copyright : (C) 2013 by Martin Dobias
6  email : wonder dot sk at gmail dot 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 #include "qgsxmlutils.h"
16 
17 #include <QDomElement>
18 
19 #include "qgslogger.h"
20 #include "qgsrectangle.h"
21 
22 
24 {
25  if ( "unknown" == element.text() )
26  {
28  }
29  else
30  {
33  }
34 }
35 
36 QgsRectangle QgsXmlUtils::readRectangle( const QDomElement& element )
37 {
38  QgsRectangle aoi;
39 
40  QDomNode xminNode = element.namedItem( QStringLiteral( "xmin" ) );
41  QDomNode yminNode = element.namedItem( QStringLiteral( "ymin" ) );
42  QDomNode xmaxNode = element.namedItem( QStringLiteral( "xmax" ) );
43  QDomNode ymaxNode = element.namedItem( QStringLiteral( "ymax" ) );
44 
45  QDomElement exElement = xminNode.toElement();
46  double xmin = exElement.text().toDouble();
47  aoi.setXMinimum( xmin );
48 
49  exElement = yminNode.toElement();
50  double ymin = exElement.text().toDouble();
51  aoi.setYMinimum( ymin );
52 
53  exElement = xmaxNode.toElement();
54  double xmax = exElement.text().toDouble();
55  aoi.setXMaximum( xmax );
56 
57  exElement = ymaxNode.toElement();
58  double ymax = exElement.text().toDouble();
59  aoi.setYMaximum( ymax );
60 
61  return aoi;
62 }
63 
64 
65 
66 QDomElement QgsXmlUtils::writeMapUnits( QgsUnitTypes::DistanceUnit units, QDomDocument& doc )
67 {
68  QString unitsString = QgsUnitTypes::encodeUnit( units );
69  // maintain compatibility with old projects
70  if ( units == QgsUnitTypes::DistanceUnknownUnit )
71  unitsString = QStringLiteral( "unknown" );
72 
73  QDomElement unitsNode = doc.createElement( QStringLiteral( "units" ) );
74  unitsNode.appendChild( doc.createTextNode( unitsString ) );
75  return unitsNode;
76 }
77 
78 QDomElement QgsXmlUtils::writeRectangle( const QgsRectangle& rect, QDomDocument& doc )
79 {
80  QDomElement xMin = doc.createElement( QStringLiteral( "xmin" ) );
81  QDomElement yMin = doc.createElement( QStringLiteral( "ymin" ) );
82  QDomElement xMax = doc.createElement( QStringLiteral( "xmax" ) );
83  QDomElement yMax = doc.createElement( QStringLiteral( "ymax" ) );
84 
85  QDomText xMinText = doc.createTextNode( qgsDoubleToString( rect.xMinimum() ) );
86  QDomText yMinText = doc.createTextNode( qgsDoubleToString( rect.yMinimum() ) );
87  QDomText xMaxText = doc.createTextNode( qgsDoubleToString( rect.xMaximum() ) );
88  QDomText yMaxText = doc.createTextNode( qgsDoubleToString( rect.yMaximum() ) );
89 
90  xMin.appendChild( xMinText );
91  yMin.appendChild( yMinText );
92  xMax.appendChild( xMaxText );
93  yMax.appendChild( yMaxText );
94 
95  QDomElement extentNode = doc.createElement( QStringLiteral( "extent" ) );
96  extentNode.appendChild( xMin );
97  extentNode.appendChild( yMin );
98  extentNode.appendChild( xMax );
99  extentNode.appendChild( yMax );
100  return extentNode;
101 }
A rectangle specified with double values.
Definition: qgsrectangle.h:35
void setXMaximum(double x)
Set the maximum x value.
Definition: qgsrectangle.h:176
static QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc)
Definition: qgsxmlutils.cpp:78
static QgsUnitTypes::DistanceUnit readMapUnits(const QDomElement &element)
Decodes a distance unit from a DOM element.
Definition: qgsxmlutils.cpp:23
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
Definition: qgis.h:184
void setYMinimum(double y)
Set the minimum y value.
Definition: qgsrectangle.h:181
static QDomElement writeMapUnits(QgsUnitTypes::DistanceUnit units, QDomDocument &doc)
Encodes a distance unit to a DOM element.
Definition: qgsxmlutils.cpp:66
Degrees, for planar geographic CRS distance measurements.
Definition: qgsunittypes.h:50
static Q_INVOKABLE QString encodeUnit(QgsUnitTypes::DistanceUnit unit)
Encodes a distance unit to a string.
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
Definition: qgsrectangle.h:206
DistanceUnit
Units of distance.
Definition: qgsunittypes.h:42
double xMaximum() const
Get the x maximum value (right side of rectangle)
Definition: qgsrectangle.h:191
Unknown distance unit.
Definition: qgsunittypes.h:51
void setYMaximum(double y)
Set the maximum y value.
Definition: qgsrectangle.h:186
double xMinimum() const
Get the x minimum value (left side of rectangle)
Definition: qgsrectangle.h:196
double yMaximum() const
Get the y maximum value (top side of rectangle)
Definition: qgsrectangle.h:201
static QgsRectangle readRectangle(const QDomElement &element)
Definition: qgsxmlutils.cpp:36
void setXMinimum(double x)
Set the minimum x value.
Definition: qgsrectangle.h:171
static Q_INVOKABLE QgsUnitTypes::DistanceUnit decodeDistanceUnit(const QString &string, bool *ok=0)
Decodes a distance unit from a string.