All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Serializer.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/geometry/serialization/xml/Serializer.cpp
22 
23  \brief Auxiliary classes and functions to read envelope information from a XML document.
24 */
25 
26 // TerraLib
27 #include "../../../xml/AbstractWriter.h"
28 #include "../../../xml/Reader.h"
29 #include "../../../xml/ReaderFactory.h"
30 #include "../../Envelope.h"
31 #include "../../Exception.h"
32 #include "Serializer.h"
33 
34 std::auto_ptr<te::gm::Envelope> te::serialize::xml::ReadExtent(te::xml::Reader& reader)
35 {
36  assert(reader.getNodeType() == te::xml::START_ELEMENT);
37  assert(reader.getElementLocalName() == "Extent");
38 
39  double llx = reader.getAttrAsDouble(0);
40  double lly = reader.getAttrAsDouble(1);
41  double urx = reader.getAttrAsDouble(2);
42  double ury = reader.getAttrAsDouble(3);
43 
44  reader.next();
45 
46  assert(reader.getNodeType() == te::xml::END_ELEMENT);
47  reader.next();
48 
49  return std::auto_ptr<te::gm::Envelope>(new te::gm::Envelope(llx, lly, urx, ury));
50 }
51 
53 {
54  writer.writeStartElement("te_map:Extent");
55  writer.writeAttribute("llx", e.m_llx);
56  writer.writeAttribute("lly", e.m_lly);
57  writer.writeAttribute("urx", e.m_urx);
58  writer.writeAttribute("ury", e.m_ury);
59  writer.writeEndElement("te_map:Extent");
60 }
61 
This class models a XML reader object.
Definition: Reader.h:55
virtual void writeStartElement(const std::string &qName)=0
double m_urx
Upper right corner x-coordinate.
Definition: Envelope.h:346
This class models a XML writer object.
virtual std::string getElementLocalName() const =0
It returns the local part of the element name in the case of an element node.
double m_llx
Lower left corner x-coordinate.
Definition: Envelope.h:344
An Envelope defines a 2D rectangular region.
Definition: Envelope.h:51
Auxiliary classes and functions to read geometry information from a XML document. ...
TEGEOMEXPORT std::auto_ptr< te::gm::Envelope > ReadExtent(te::xml::Reader &reader)
Definition: Serializer.cpp:34
TEGEOMEXPORT void SaveExtent(const te::gm::Envelope &e, te::xml::AbstractWriter &writer)
Definition: Serializer.cpp:52
double m_lly
Lower left corner y-coordinate.
Definition: Envelope.h:345
virtual void writeAttribute(const std::string &attName, const std::string &value)=0
double m_ury
Upper right corner y-coordinate.
Definition: Envelope.h:347
virtual NodeType getNodeType() const =0
It return the type of node read.
virtual double getAttrAsDouble(const std::string &name) const
It returns the attribute value in the case of an element node with valid attributes.
Definition: Reader.cpp:69
virtual void writeEndElement(const std::string &qName)=0
virtual bool next()=0
It gets the next event to be read.