All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Utils.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/qt/widgets/rp/Utils.h
22 
23  \brief Utility functions for the qt widgets rp Module.
24 */
25 
26 // TerraLib
27 #include "../../../dataaccess/dataset/DataSetType.h"
28 #include "../../../dataaccess/datasource/DataSource.h"
29 #include "../../../dataaccess/datasource/DataSourceFactory.h"
30 #include "../../../dataaccess/datasource/DataSourceInfoManager.h"
31 #include "../../../dataaccess/datasource/DataSourceManager.h"
32 #include "../layer/utils/DataSet2Layer.h"
33 #include "Utils.h"
34 
35 // Boost
36 #include <boost/uuid/random_generator.hpp>
37 #include <boost/uuid/uuid_io.hpp>
38 
39 
41  const std::map<std::string, std::string>& connInfo)
42 {
44 
45  static boost::uuids::basic_random_generator<boost::mt19937> gen;
46 
47  boost::uuids::uuid valU = gen();
48  std::string id = boost::uuids::to_string(valU);
49 
50  std::auto_ptr<te::da::DataSource> ds(te::da::DataSourceFactory::make(driverName));
51  ds->setConnectionInfo(connInfo);
52  ds->open();
53 
54  std::vector<std::string> dsNames = ds->getDataSetNames();
55  assert(!dsNames.empty());
56 
57  //add ds info
59  dsInfoPtr->setConnInfo(connInfo);
60  dsInfoPtr->setId(id);
61  dsInfoPtr->setTitle(dsNames[0]);
62  dsInfoPtr->setAccessDriver(driverName);
63  dsInfoPtr->setType(driverName);
64 
66 
67  //add ds
68  te::da::DataSourcePtr dsPtr(ds.release());
69  dsPtr->setId(id);
70 
72 
73  //create layer
74  te::da::DataSetTypePtr dsType(dsPtr->getDataSetType(dsNames[0]).release());
75 
76  te::qt::widgets::DataSet2Layer ds2l(dsPtr->getId());
77 
78  layer = ds2l(dsType);
79 
80  return layer;
81 }
82 
83 /*
84  te::map::RasterLayer* rLayer = new te::map::RasterLayer(layerId, layerName);
85 
86  rLayer->setRasterInfo(connInfo);
87  rLayer->setVisibility(te::map::VISIBLE);
88  rLayer->setRendererType("RASTER_LAYER_RENDERER");
89 
90  layer.reset(rLayer);
91 
92  std::auto_ptr<te::rst::Raster> rst(rLayer->getRaster());
93 
94  te::se::Style* style = layer->getStyle();
95  if(style == 0)
96  {
97  // Try create an appropriate style. i.e. a CoverageStyle
98  style = te::se::CreateCoverageStyle(rst->getNumberOfBands());
99 
100  if(style != 0)
101  layer->setStyle(style);
102  }
103 */
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1435
static DataSourceInfoManager & getInstance()
It returns a reference to the singleton instance.
static std::auto_ptr< DataSource > make(const std::string &dsType)
Utility functions for the qt widgets rp Module.
A class that represents a data source component.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
TEQTWIDGETSEXPORT te::map::AbstractLayerPtr createLayer(const std::string &driverName, const std::map< std::string, std::string > &connInfo)
Definition: Utils.cpp:40
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr