All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ColorMap.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011-2011 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/serialization/se/ColorMap.cpp
22 
23  \brief Support for ColorMap serialization.
24 */
25 
26 // TerraLib
27 #include "../../se/ColorMap.h"
28 #include "../../xml/Reader.h"
29 #include "../../xml/Writer.h"
30 #include "Categorize.h"
31 #include "ColorMap.h"
32 #include "Interpolate.h"
33 #include "Utils.h"
34 
35 // STL
36 #include <cassert>
37 #include <memory>
38 
40 {
41  assert(reader.getNodeType() == te::xml::START_ELEMENT);
42  assert(reader.getElementLocalName() == "ColorMap");
43 
44  reader.next();
45 
46  std::auto_ptr<te::se::ColorMap> cm(new te::se::ColorMap);
47 
48  if(reader.getElementLocalName() == "Categorize")
49  cm->setCategorize(ReadCategorize(reader));
50  else // Interpolate
51  cm->setInterpolate(ReadInterpolate(reader));
52 
53  assert(reader.getNodeType() == te::xml::END_ELEMENT);
54  reader.next();
55 
56  return cm.release();
57 }
58 
60 {
61  if(cm == 0)
62  return;
63 
64  writer.writeStartElement("se:ColorMap");
65 
66  te::se::Categorize* categorize = cm->getCategorize();
67  if(categorize)
68  Save(categorize, writer);
69  else
70  {
71  te::se::Interpolate* interpolate = cm->getInterpolate();
72  assert(interpolate);
73  Save(interpolate, writer);
74  }
75 
76  writer.writeEndElement("se:ColorMap");
77 }
Utility methods for Symbology serialization.
TEDATAACCESSEXPORT void Save(const std::string &fileName)
Definition: Serializer.cpp:191
This class models a XML reader object.
Definition: Reader.h:55
The transformation of continuous values to distinct values (Categorize function). ...
Definition: Categorize.h:90
virtual bool next()=0
It gets the next event to be read.
Interpolate * getInterpolate() const
Definition: ColorMap.cpp:75
The transformation of continuous values to a number of values (Interpolate function).
Definition: Interpolate.h:88
virtual void writeStartElement(const std::string &qName)
Definition: Writer.cpp:44
A ColorMap defines either the colors of a pallette-type raster source or the mapping of numeric pixel...
virtual void writeEndElement(const std::string &qName)
Definition: Writer.cpp:156
TESERIALIZATIONEXPORT void Save(const te::fe::Filter *filter, te::xml::Writer &writer)
Definition: Filter.cpp:54
A ColorMap defines either the colors of a pallette-type raster source or the mapping of numeric pixel...
Definition: ColorMap.h:60
TESERIALIZATIONEXPORT te::se::ColorMap * ReadColorMap(te::xml::Reader &reader)
Definition: ColorMap.cpp:39
Support for Categorize serialization.
TESERIALIZATIONEXPORT te::se::Categorize * ReadCategorize(te::xml::Reader &reader)
Definition: Categorize.cpp:39
Categorize * getCategorize() const
Definition: ColorMap.cpp:64
Support for Interpolate serialization.
TESERIALIZATIONEXPORT te::se::Interpolate * ReadInterpolate(te::xml::Reader &reader)
Definition: Interpolate.cpp:40
virtual NodeType getNodeType() const =0
It return the type of node read.
virtual std::string getElementLocalName() const =0
It returns the local part of the element name in the case of an element node.
This class models a XML writer object.
Definition: Writer.h:52