All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
DataSet2Layer.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2011-2012 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/layer/utils/DataSet2Layer.cpp
22 
23  \brief ....
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 "../../../../geometry/GeometryProperty.h"
34 #include "../../../../maptools/AbstractLayer.h"
35 #include "../../../../maptools/DataSetLayer.h"
36 #include "../../../../raster/Grid.h"
37 #include "../../../../raster/RasterProperty.h"
38 #include "../../../../se/Utils.h"
39 #include "../../../../srs/Config.h"
40 #include "../../Exception.h"
41 #include "DataSet2Layer.h"
42 
43 // Boost
44 #include <boost/uuid/random_generator.hpp>
45 #include <boost/uuid/uuid_io.hpp>
46 
47 te::qt::widgets::DataSet2Layer::DataSet2Layer(const std::string& datasourceId)
48  : m_datasourceId(datasourceId)
49 {
50 }
51 
53 {
54  static boost::uuids::basic_random_generator<boost::mt19937> gen;
55 
56  if(dataset.get() == 0)
57  throw Exception(TR_QT_WIDGETS("Can not convert a NULL dataset to a layer!"));
58 
59  boost::uuids::uuid u = gen();
60  std::string id = boost::uuids::to_string(u);
61 
62  std::string title = dataset->getTitle().empty() ? dataset->getName() : dataset->getTitle();
63 
64  te::map::DataSetLayerPtr layer(new te::map::DataSetLayer(id, title));
65  layer->setDataSetName(dataset->getName());
66  layer->setDataSourceId(m_datasourceId);
67  layer->setVisibility(te::map::NOT_VISIBLE);
68  layer->setRendererType("ABSTRACT_LAYER_RENDERER");
69 
70  if(dataset->size() == 0)
71  {
73  te::da::LoadProperties(dataset.get(), m_datasourceId);
74  }
75 
76  if(dataset->hasGeom())
77  {
79  std::auto_ptr<te::gm::Envelope> mbr(te::da::GetExtent(dataset->getName(), gp->getName(), m_datasourceId));
80  layer->setSRID(gp->getSRID());
81  layer->setExtent(*mbr);
82  layer->setStyle(te::se::CreateFeatureTypeStyle(gp->getGeometryType()));
83  }
84  else if(dataset->hasRaster())
85  {
86  te::rst::Grid* grid = te::da::GetFirstRasterProperty(dataset.get())->getGrid();
87 
88  layer->setSRID(grid->getSRID());
89  layer->setExtent(*(grid->getExtent()));
90  layer->setStyle(te::se::CreateCoverageStyle(te::da::GetFirstRasterProperty(dataset.get())->getBandProperties()));
91  }
92  else
93  {
94  layer->setSRID(TE_UNKNOWN_SRS);
95  //layer->setExtent(te::gm::Envelope());
96  }
97 
98  return layer;
99 }
A layer with reference to a dataset.
Definition: DataSetLayer.h:47
TEDATAACCESSEXPORT te::rst::RasterProperty * GetFirstRasterProperty(const DataSetType *dt)
Definition: Utils.cpp:518
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
Definition: Utils.cpp:504
int getSRID() const
It returns the spatial reference system identifier associated to this property.
const std::string & getName() const
It returns the property name.
Definition: Property.h:126
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
Definition: Config.h:72
TEDATAACCESSEXPORT te::gm::Envelope * GetExtent(const std::string &datasetName, const std::string &propertyName, const std::string &datasourceId)
Definition: Utils.cpp:132
TESEEXPORT Style * CreateFeatureTypeStyle(const te::gm::GeomType &geomType)
Try creates an appropriate feature type style based on given geometry type.
Definition: Utils.cpp:282
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
A rectified grid is the spatial support for raster data.
Definition: Grid.h:55
te::gm::Envelope * getExtent()
Returns the geographic extension of the grid.
Definition: Grid.cpp:276
TESEEXPORT Style * CreateCoverageStyle(const std::vector< te::rst::BandProperty * > &properties)
Try creates an appropriate coverage style based on given band properties.
Definition: Utils.cpp:297
DataSet2Layer(const std::string &datasourceId)
boost::shared_ptr< DataSource > DataSourcePtr
Definition: DataSource.h:1395
boost::intrusive_ptr< DataSetLayer > DataSetLayerPtr
Definition: DataSetLayer.h:165
#define TR_QT_WIDGETS(message)
It marks a string in order to get translated. This is a special mark used in the TerraLib Qt Widgets ...
Definition: Config.h:60
boost::shared_ptr< DataSetType > DataSetTypePtr
Definition: DataSetType.h:653
TEDATAACCESSEXPORT void LoadProperties(te::da::DataSetType *dataset, const std::string &datasourceId)
Definition: Utils.cpp:116
int getSRID() const
Returns the grid spatial reference system identifier.
Definition: Grid.cpp:266
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
Geometric property.
te::map::DataSetLayerPtr operator()(const te::da::DataSetTypePtr &dataset) const