All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
WMS2Layer.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/WMS2Layer.cpp
22 
23  \brief A functor that converts a dataset from WMS server to a TerraLib WMSLayer.
24 */
25 
26 // TerraLib
27 #include "../common/Translator.h"
28 #include "../dataaccess/dataset/DataSetType.h"
29 #include "../dataaccess/datasource/DataSourceManager.h"
30 #include "../dataaccess/datasource/DataSourceTransactor.h"
31 #include "../dataaccess/utils/Utils.h"
32 #include "../geometry/Envelope.h"
33 #include "../maptools/AbstractLayer.h"
34 #include "../raster/Grid.h"
35 #include "../raster/RasterProperty.h"
36 #include "../se/Utils.h"
37 #include "../srs/Config.h"
38 #include "Exception.h"
39 #include "WMS2Layer.h"
40 
41 // Boost
42 #include <boost/uuid/random_generator.hpp>
43 #include <boost/uuid/uuid_io.hpp>
44 
45 te::wms::WMS2Layer::WMS2Layer(const std::string& datasourceId)
46  : m_datasourceId(datasourceId)
47 {
48 }
49 
51 {
52  static boost::uuids::basic_random_generator<boost::mt19937> gen;
53 
54  if(dataset.get() == 0)
55  throw Exception(TE_TR("Can not convert a NULL dataset to a WMS layer!"));
56 
57  boost::uuids::uuid u = gen();
58  std::string id = boost::uuids::to_string(u);
59 
60  std::string title = dataset->getTitle().empty() ? dataset->getName() : dataset->getTitle();
61 
62  WMSLayerPtr layer(new WMSLayer(id, title));
63  layer->setDataSetName(dataset->getName());
64  layer->setDataSourceId(m_datasourceId);
65  layer->setVisibility(te::map::NOT_VISIBLE);
66 
67  if(dataset->size() == 0)
68  {
70  te::da::LoadProperties(dataset.get(), m_datasourceId);
71  }
72 
73  assert(dataset->hasRaster());
74 
75  te::rst::Grid* grid = te::da::GetFirstRasterProperty(dataset.get())->getGrid();
76  layer->setSRID(grid->getSRID());
77  layer->setExtent(*(grid->getExtent()));
78  layer->setStyle(te::se::CreateCoverageStyle(te::da::GetFirstRasterProperty(dataset.get())->getBandProperties()));
79 
80  return layer;
81 }
TEDATAACCESSEXPORT te::rst::RasterProperty * GetFirstRasterProperty(const DataSetType *dt)
Definition: Utils.cpp:571
boost::intrusive_ptr< WMSLayer > WMSLayerPtr
Definition: WMSLayer.h:144
TEDATAACCESSEXPORT void LoadProperties(te::da::DataSetType *dataset, const std::string &datasourceId)
Definition: Utils.cpp:120
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
TESEEXPORT Style * CreateCoverageStyle(const std::vector< te::rst::BandProperty * > &properties)
Try creates an appropriate coverage style based on given band properties.
Definition: Utils.cpp:299
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:347
A functor that converts a dataset from WMS server to a TerraLib WMSLayer.
A layer with reference to a WMS Layer.
Definition: WMSLayer.h:45
An exception class for the TerraLib WMS module.
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
WMS2Layer(const std::string &datasourceId)
Definition: WMS2Layer.cpp:45
WMSLayerPtr operator()(const te::da::DataSetTypePtr &dataset) const
Definition: WMS2Layer.cpp:50
A rectified grid is the spatial support for raster data.
Definition: Grid.h:68