src/terralib/ws/ogc/wms/dataaccess/WMS2Layer.cpp
Go to the documentation of this file.
1 #include "WMS2Layer.h"
2 
3 //TerraLib
4 #include "../../../core/Exception.h"
5 #include "../../../../core/translator/Translator.h"
6 #include "../../../../dataaccess/dataset/DataSetType.h"
7 #include "../../../../dataaccess/datasource/DataSourceManager.h"
8 #include "../../../../dataaccess/datasource/DataSourceTransactor.h"
9 #include "../../../../geometry/Envelope.h"
10 #include "Transactor.h"
11 #include "../client/DataTypes.h"
12 #include "../../../../common/StringUtils.h"
13 
14 // Boost
15 #include <boost/uuid/random_generator.hpp>
16 #include <boost/uuid/uuid_io.hpp>
17 #include <boost/lexical_cast.hpp>
18 
19 te::ws::ogc::wms::WMS2Layer::WMS2Layer(const std::string dataSourceId)
20 {
21  m_dataSourceId = dataSourceId;
22 }
23 
25 {
26  static boost::uuids::basic_random_generator<boost::mt19937> gen;
27 
28  boost::uuids::uuid u = gen();
29  std::string id = boost::uuids::to_string(u);
30 
32 
33  if(ds.get() == nullptr)
34  {
35  throw te::ws::core::Exception() << te::ErrorDescription(TE_TR("DataSource is NULL for this DataSetType."));
36  }
37 
38  te::ws::ogc::wms::da::Transactor* transactor = dynamic_cast<te::ws::ogc::wms::da::Transactor*>(ds->getTransactor().release());
39 
40  te::ws::ogc::wms::Layer wmsLayer = transactor->getLayerByName(request.m_layers[0]);
41 
42  std::string title = wmsLayer.m_title.empty() ? wmsLayer.m_name : wmsLayer.m_title;
43 
45 
46  //Using the default box and CRS but it should be choosen by the user.
48  std::string crs = request.m_srs;
49 
50  te::gm::Envelope extent (bbox.m_minX, bbox.m_minY, bbox.m_maxX, bbox.m_maxY);
51 
52  std::vector<std::string> crsValues = te::common::SplitString(crs, ':');
53 
54  // Integer Value.
55  crs = crsValues[1];
56 
57  int srid = boost::lexical_cast<int>(crs.c_str());
58  layer->setSRID(srid);
59  layer->setDataSourceId(m_dataSourceId);
60  layer->setExtent(extent);
61  layer->setDataSetName(request.m_layers[0]);
62  layer->setVisibility(te::map::NOT_VISIBLE);
63 
64  layer->setGetMapRequest(request);
65 
66  return layer;
67 }
TECOMMONEXPORT std::vector< std::string > SplitString(const std::string &str, const char &delimiter)
Definition: StringUtils.cpp:32
boost::shared_ptr< DataSource > DataSourcePtr
static te::dt::Date ds(2010, 01, 01)
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
boost::error_info< struct tag_error_description, std::string > ErrorDescription
The base type for error report messages.
WMSLayerPtr operator()(const te::ws::ogc::wms::WMSGetMapRequest &request) const
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
The Layer WMS 1.3.0 struct.
A layer with reference to a WMS Layer.
Base exception class for WS Core Runtime Library.
Implementation of the transactor for the WS OGC WMS.
A functor that converts a dataset from WMS server to a TerraLib OGC WMSLayer.
te::ws::ogc::wms::Layer getLayerByName(const std::string &layerName)
boost::intrusive_ptr< WMSLayer > WMSLayerPtr
Implementation of the transactor for the WMS driver.
The WMSGetMapRequest WMS 1.3.0 struct.
The BoundingBox WMS 1.3.0 struct.