QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
qgsxmlutils.cpp
Go to the documentation of this file.
1 #include "qgsxmlutils.h"
2 
3 #include <QDomElement>
4 
5 #include "qgslogger.h"
6 #include "qgsrectangle.h"
7 
8 
9 QGis::UnitType QgsXmlUtils::readMapUnits( const QDomElement& element )
10 {
11  if ( "meters" == element.text() )
12  {
13  return QGis::Meters;
14  }
15  else if ( "feet" == element.text() )
16  {
17  return QGis::Feet;
18  }
19  else if ( "nautical miles" == element.text() )
20  {
21  return QGis::NauticalMiles;
22  }
23  else if ( "degrees" == element.text() )
24  {
25  return QGis::Degrees;
26  }
27  else if ( "unknown" == element.text() )
28  {
29  return QGis::UnknownUnit;
30  }
31  else
32  {
33  QgsDebugMsg( "Unknown map unit type " + element.text() );
34  return QGis::Degrees;
35  }
36 }
37 
38 QgsRectangle QgsXmlUtils::readRectangle( const QDomElement& element )
39 {
40  QgsRectangle aoi;
41 
42  QDomNode xminNode = element.namedItem( "xmin" );
43  QDomNode yminNode = element.namedItem( "ymin" );
44  QDomNode xmaxNode = element.namedItem( "xmax" );
45  QDomNode ymaxNode = element.namedItem( "ymax" );
46 
47  QDomElement exElement = xminNode.toElement();
48  double xmin = exElement.text().toDouble();
49  aoi.setXMinimum( xmin );
50 
51  exElement = yminNode.toElement();
52  double ymin = exElement.text().toDouble();
53  aoi.setYMinimum( ymin );
54 
55  exElement = xmaxNode.toElement();
56  double xmax = exElement.text().toDouble();
57  aoi.setXMaximum( xmax );
58 
59  exElement = ymaxNode.toElement();
60  double ymax = exElement.text().toDouble();
61  aoi.setYMaximum( ymax );
62 
63  return aoi;
64 }
65 
66 
67 
68 QDomElement QgsXmlUtils::writeMapUnits( QGis::UnitType units, QDomDocument& doc )
69 {
70  QString unitsString;
71  switch ( units )
72  {
73  case QGis::Meters:
74  unitsString = "meters";
75  break;
76  case QGis::Feet:
77  unitsString = "feet";
78  break;
80  unitsString = "nautical miles";
81  break;
82  case QGis::Degrees:
83  unitsString = "degrees";
84  break;
85  case QGis::UnknownUnit:
86  default:
87  unitsString = "unknown";
88  break;
89  }
90 
91  QDomElement unitsNode = doc.createElement( "units" );
92  unitsNode.appendChild( doc.createTextNode( unitsString ) );
93  return unitsNode;
94 }
95 
96 QDomElement QgsXmlUtils::writeRectangle( const QgsRectangle& rect, QDomDocument& doc )
97 {
98  QDomElement xMin = doc.createElement( "xmin" );
99  QDomElement yMin = doc.createElement( "ymin" );
100  QDomElement xMax = doc.createElement( "xmax" );
101  QDomElement yMax = doc.createElement( "ymax" );
102 
103  QDomText xMinText = doc.createTextNode( qgsDoubleToString( rect.xMinimum() ) );
104  QDomText yMinText = doc.createTextNode( qgsDoubleToString( rect.yMinimum() ) );
105  QDomText xMaxText = doc.createTextNode( qgsDoubleToString( rect.xMaximum() ) );
106  QDomText yMaxText = doc.createTextNode( qgsDoubleToString( rect.yMaximum() ) );
107 
108  xMin.appendChild( xMinText );
109  yMin.appendChild( yMinText );
110  xMax.appendChild( xMaxText );
111  yMax.appendChild( yMaxText );
112 
113  QDomElement extentNode = doc.createElement( "extent" );
114  extentNode.appendChild( xMin );
115  extentNode.appendChild( yMin );
116  extentNode.appendChild( xMax );
117  extentNode.appendChild( yMax );
118  return extentNode;
119 }
A rectangle specified with double values.
Definition: qgsrectangle.h:35
void setXMaximum(double x)
Set the maximum x value.
Definition: qgsrectangle.h:169
double yMaximum() const
Get the y maximum value (top side of rectangle)
Definition: qgsrectangle.h:194
#define QgsDebugMsg(str)
Definition: qgslogger.h:36
static QDomElement writeRectangle(const QgsRectangle &rect, QDomDocument &doc)
Definition: qgsxmlutils.cpp:96
double yMinimum() const
Get the y minimum value (bottom side of rectangle)
Definition: qgsrectangle.h:199
double xMaximum() const
Get the x maximum value (right side of rectangle)
Definition: qgsrectangle.h:184
void setYMinimum(double y)
Set the minimum y value.
Definition: qgsrectangle.h:174
static QGis::UnitType readMapUnits(const QDomElement &element)
Definition: qgsxmlutils.cpp:9
QString qgsDoubleToString(const double &a, const int &precision=17)
Definition: qgis.h:316
void setYMaximum(double y)
Set the maximum y value.
Definition: qgsrectangle.h:179
UnitType
Map units that qgis supports.
Definition: qgis.h:229
double xMinimum() const
Get the x minimum value (left side of rectangle)
Definition: qgsrectangle.h:189
static QgsRectangle readRectangle(const QDomElement &element)
Definition: qgsxmlutils.cpp:38
void setXMinimum(double x)
Set the minimum x value.
Definition: qgsrectangle.h:164
static QDomElement writeMapUnits(QGis::UnitType units, QDomDocument &doc)
Definition: qgsxmlutils.cpp:68