attic/src/wms/WMSLayer.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/wms/WMSLayer.cpp
22 
23  \brief A layer with reference to a WMS Layer.
24 */
25 
26 // TerraLib
27 #include "../core/translator/Translator.h"
28 #include "../dataaccess/utils/Utils.h"
29 #include "../maptools/AbstractRenderer.h"
30 #include "../maptools/RendererFactory.h"
31 #include "Exception.h"
32 #include "WMSLayer.h"
33 
34 // Boost
35 #include <boost/format.hpp>
36 #include <boost/lexical_cast.hpp>
37 
38 const std::string te::wms::WMSLayer::sm_type("WMSLAYER");
39 
41  : te::map::AbstractLayer(parent),
42  m_rendererType("WMS_LAYER_RENDERER"),
43  m_width(boost::lexical_cast<std::size_t>(TE_WMS_DEFAULT_WIDTH)),
44  m_height(boost::lexical_cast<std::size_t>(TE_WMS_DEFAULT_HEIGHT)),
46  m_schema(0)
47 {
48 }
49 
50 te::wms::WMSLayer::WMSLayer(const std::string& id, te::map::AbstractLayer* parent)
51  : te::map::AbstractLayer(id, parent),
52  m_rendererType("WMS_LAYER_RENDERER"),
53  m_width(boost::lexical_cast<std::size_t>(TE_WMS_DEFAULT_WIDTH)),
54  m_height(boost::lexical_cast<std::size_t>(TE_WMS_DEFAULT_HEIGHT)),
56  m_schema(0)
57 {
58 }
59 
60 te::wms::WMSLayer::WMSLayer(const std::string& id,
61  const std::string& title,
62  te::map::AbstractLayer* parent)
63  : te::map::AbstractLayer(id, title, parent),
64  m_rendererType("WMS_LAYER_RENDERER"),
65  m_width(boost::lexical_cast<std::size_t>(TE_WMS_DEFAULT_WIDTH)),
66  m_height(boost::lexical_cast<std::size_t>(TE_WMS_DEFAULT_HEIGHT)),
68  m_schema(0)
69 {
70 }
71 
73 {
74 }
75 
76 std::auto_ptr<te::map::LayerSchema> te::wms::WMSLayer::getSchema() const
77 {
78  if(m_schema.get())
79  return std::auto_ptr<te::map::LayerSchema>(static_cast<te::map::LayerSchema*>(m_schema->clone()));
80 
81  assert(!m_datasetName.empty());
82 
84 
85  m_schema = ds->getDataSetType(m_datasetName);
86 
87  return std::auto_ptr<te::map::LayerSchema>(static_cast<te::map::LayerSchema*>(m_schema->clone()));
88 }
89 
90 std::auto_ptr<te::da::DataSet> te::wms::WMSLayer::getData(te::common::TraverseType travType,
91  const te::common::AccessPolicy accessPolicy) const
92 {
93  std::string request = buildRequest();
94 
96 
97  return ds->getDataSet(request, travType, accessPolicy);
98 }
99 
100 std::auto_ptr<te::da::DataSet> te::wms::WMSLayer::getData(const std::string& propertyName,
101  const te::gm::Envelope* e,
103  te::common::TraverseType travType,
104  const te::common::AccessPolicy accessPolicy) const
105 {
106  std::string request = buildRequest();
107 
109 
110  return ds->getDataSet(request, propertyName, e, r, travType, accessPolicy);
111 }
112 
113 std::auto_ptr<te::da::DataSet> te::wms::WMSLayer::getData(const std::string& propertyName,
114  const te::gm::Geometry* g,
116  te::common::TraverseType travType,
117  const te::common::AccessPolicy accessPolicy) const
118 {
119  std::string request = buildRequest();
120 
122 
123  return ds->getDataSet(request, propertyName, g, r, travType, accessPolicy);
124 }
125 
126 std::auto_ptr<te::da::DataSet> te::wms::WMSLayer::getData(te::da::Expression* restriction,
127  te::common::TraverseType travType,
128  const te::common::AccessPolicy accessPolicy) const
129 {
130  throw Exception(TE_TR("Query operations are not supported by the WMS Layer!"));
131 }
132 
133 std::auto_ptr<te::da::DataSet> te::wms::WMSLayer::getData(const te::da::ObjectIdSet* oids,
134  te::common::TraverseType travType,
135  const te::common::AccessPolicy accessPolicy) const
136 {
137  throw Exception(TE_TR("The ObjectIdSet concept is not supported by the WMS Layer!"));
138 }
139 
141 {
142  if(m_datasourceId.empty() || m_datasetName.empty())
143  return false;
144 
145  if(m_width == 0 || m_height == 0 || m_format.empty())
146  return false;
147 
149  try
150  {
152  }
153  catch(...)
154  {
155  return false;
156  }
157 
158  if(ds.get() == 0 || !ds->isValid() || !ds->isOpened())
159  return false;
160 
161  return true;
162 }
163 
164 void te::wms::WMSLayer::draw(te::map::Canvas* canvas, const te::gm::Envelope& bbox, int srid, const double& scale, bool* cancel)
165 {
166  if(m_rendererType.empty())
167  throw Exception((boost::format(TE_TR("Could not draw the WMS layer %1%. The renderer type is empty!")) % getTitle()).str());
168 
169  // Try get the defined renderer
170  std::auto_ptr<te::map::AbstractRenderer> renderer(te::map::RendererFactory::make(m_rendererType));
171  if(renderer.get() == 0)
172  throw Exception((boost::format(TE_TR("Could not draw the WMS layer %1%. The renderer %2% could not be created!")) % getTitle() % m_rendererType).str());
173 
174  renderer->draw(this, canvas, bbox, srid, scale, cancel);
175 }
176 
177 const std::string& te::wms::WMSLayer::getType() const
178 {
179  return sm_type;
180 }
181 
182 const std::string& te::wms::WMSLayer::getDataSetName() const
183 {
184  return m_datasetName;
185 }
186 
187 void te::wms::WMSLayer::setDataSetName(const std::string& name)
188 {
189  m_datasetName = name;
190 }
191 
192 const std::string& te::wms::WMSLayer::getDataSourceId() const
193 {
194  return m_datasourceId;
195 }
196 
197 void te::wms::WMSLayer::setDataSourceId(const std::string& id)
198 {
199  m_datasourceId = id;
200 }
201 
202 const std::string& te::wms::WMSLayer::getRendererType() const
203 {
204  return m_rendererType;
205 }
206 
207 void te::wms::WMSLayer::setRendererType(const std::string& t)
208 {
209  m_rendererType = t;
210 }
211 
212 void te::wms::WMSLayer::setWidth(const std::size_t& width)
213 {
214  m_width = width;
215 }
216 
217 void te::wms::WMSLayer::setHeight(const std::size_t& height)
218 {
219  m_height = height;
220 }
221 
222 void te::wms::WMSLayer::setFormat(const std::string& format)
223 {
224  m_format = format;
225 }
226 
228 {
229  assert(!m_datasetName.empty());
230  assert(m_width > 0);
231  assert(m_height > 0);
232  assert(!m_format.empty());
233 
234  std::string request = "LAYER=" + m_datasetName;
235  request += "&WIDTH=" + boost::lexical_cast<std::string>(m_width);
236  request += "&HEIGHT=" + boost::lexical_cast<std::string>(m_height);
237  request += "&FORMAT=" + m_format;
238 
239  return request;
240 }
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
void setDataSourceId(const std::string &id)
std::auto_ptr< te::map::LayerSchema > getSchema() const
It returns the layer schema.
This is the base class for layers.
Definition: AbstractLayer.h:77
boost::shared_ptr< DataSource > DataSourcePtr
virtual const std::string & getTitle() const
It returns the layer title.
Base exception class for plugin module.
A class that models the description of a dataset.
Definition: DataSetType.h:72
std::string m_datasetName
The dataset name where we will retrieve the layer data.
std::auto_ptr< te::da::DataSet > getData(te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess) const
It gets the dataset identified by the layer name.
void setFormat(const std::string &format)
const std::string & getType() const
It returns the layer type.
SpatialRelation
Spatial relations between geometric objects.
const std::string & getDataSetName() const
std::size_t m_width
Width that will be requested.
std::string m_format
Format that will be requested.
std::size_t m_height
Height that will be requested.
static te::dt::Date ds(2010, 01, 01)
void setDataSetName(const std::string &name)
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
#define TE_WMS_DEFAULT_IMAGE_FORMAT
It specifies the default image format used on GetMap request.
static const std::string sm_type
A static data member used in the implementation of getType method.
This is an abstract class that models a query expression.
AccessPolicy
Supported data access policies (can be used as bitfield).
TraverseType
A dataset can be traversed in two ways:
const std::string & getDataSourceId() const
WMSLayer(te::map::AbstractLayer *parent=0)
It initializes a new layer.
#define TE_WMS_DEFAULT_HEIGHT
It specifies the default height used on GetMap request.
An Envelope defines a 2D rectangular region.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
URI C++ Library.
Definition: Attributes.h:37
void setWidth(const std::size_t &width)
void draw(te::map::Canvas *canvas, const te::gm::Envelope &bbox, int srid, const double &scale, bool *cancel)
It draws the layer geographic objects in the given canvas using the informed SRS. ...
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
static AbstractRenderer * make(const std::string &factoryKey)
It creates an object with the appropriated factory.
std::string buildRequest() const
A canvas is an abstraction of a drawing area.
bool isValid() const
It returns true if the layer can be used for instance to draw, otherwise, it returns false...
const std::string & getRendererType() const
#define TE_WMS_DEFAULT_WIDTH
It specifies the default width used on GetMap request.
AbstractLayer(AbstractLayer *parent=0)
It initializes a new layer.
std::auto_ptr< te::map::LayerSchema > m_schema
The WMS layer schema.
std::string m_rendererType
A pointer to the internal renderer used to paint this layer.
std::string m_datasourceId
The DataSource associated to this layer.
void setRendererType(const std::string &t)
void setHeight(const std::size_t &height)