27 #include "../common/progress/TaskProgress.h" 
   28 #include "../common/Translator.h" 
   29 #include "../common/STLUtils.h" 
   30 #include "../common/StringUtils.h" 
   31 #include "../dataaccess/dataset/DataSetType.h" 
   32 #include "../dataaccess/query/And.h" 
   33 #include "../dataaccess/query/DataSetName.h" 
   34 #include "../dataaccess/query/Field.h" 
   35 #include "../dataaccess/query/LiteralEnvelope.h" 
   36 #include "../dataaccess/query/PropertyName.h" 
   37 #include "../dataaccess/query/Select.h" 
   38 #include "../dataaccess/query/ST_Intersects.h" 
   39 #include "../dataaccess/query/Where.h" 
   40 #include "../dataaccess/utils/Utils.h" 
   41 #include "../fe/Literal.h" 
   42 #include "../geometry/GeometryProperty.h" 
   43 #include "../geometry/Utils.h" 
   44 #include "../memory/DataSet.h" 
   45 #include "../raster/Grid.h" 
   46 #include "../raster/Raster.h" 
   47 #include "../raster/RasterFactory.h" 
   48 #include "../raster/RasterProperty.h" 
   49 #include "../raster/RasterSummary.h" 
   50 #include "../raster/RasterSummaryManager.h" 
   51 #include "../raster/Utils.h" 
   52 #include "../se/ChannelSelection.h" 
   53 #include "../se/CoverageStyle.h" 
   54 #include "../se/FeatureTypeStyle.h" 
   55 #include "../se/ImageOutline.h" 
   56 #include "../se/RasterSymbolizer.h" 
   57 #include "../se/Rule.h" 
   58 #include "../se/Utils.h" 
   59 #include "../srs/Config.h" 
   60 #include "../srs/Converter.h" 
   71 #include <boost/format.hpp> 
   72 #include <boost/lexical_cast.hpp> 
   81   std::list<te::map::AbstractLayerPtr>::const_iterator it = layers.begin();
 
   85   while(it != layers.end())
 
   87     if(it == layers.begin())
 
  107   if(!layer->hasChildren())
 
  109     std::auto_ptr<te::da::DataSetType> dt(layer->getSchema());
 
  116     std::auto_ptr<te::da::DataSet> ds(layer->getData(objSet));
 
  120     while(ds->moveNext())
 
  122       std::auto_ptr<te::gm::Geometry> geom = ds->getGeometry(geomProp->getName());
 
  126       if(layer->getSRID() != srid)
 
  127         auxEnv.
transform(layer->getSRID(), srid);
 
  136       finalEnv.
Union(auxEnv);
 
  141     for(std::size_t i = 0; i < layer->getChildrenCount(); ++i)
 
  157   std::vector<std::string> values;
 
  159   for(std::size_t i = 0; i < values.size(); ++i)
 
  160     style.push_back(atof(values[i].c_str()));
 
  166     throw Exception(
TE_TR(
"The layer is invalid!"));
 
  172     throw Exception(
TE_TR(
"The data set name referenced by the layer is empty!"));
 
  178   std::auto_ptr<te::da::DataSetType> dstype(ds->getDataSetType(dsname));
 
  180   if(dstype.get() == 0)
 
  181     throw Exception(
TE_TR(
"Could not get the data set type!"));
 
  184   std::auto_ptr<te::rst::RasterProperty> rasterProperty(dynamic_cast<te::rst::RasterProperty*>(dstype->getProperties()[0]->clone()));
 
  186   if(rasterProperty.get() == 0)
 
  187      throw Exception(
TE_TR(
"Could not get the raster property!"));
 
  189   return rasterProperty.release();
 
  195     throw Exception(
TE_TR(
"The layer is invalid!"));
 
  201     throw Exception(
TE_TR(
"The data set name referenced by the layer is empty!"));
 
  207   std::auto_ptr<te::da::DataSetType> dstype(ds->getDataSetType(dsname));
 
  209   if(dstype.get() == 0)
 
  210     throw Exception(
TE_TR(
"Could not get the data set type!"));
 
  212   if(!dstype->hasRaster())
 
  213     throw Exception(
TE_TR(
"The data set referenced by the layer not contains raster data!"));
 
  216   std::auto_ptr<te::da::DataSet> dataset(ds->getDataSet(dsname));
 
  217   if(dataset.get() == 0)
 
  218     throw Exception(
TE_TR(
"Could not get the data set reference by the layer!"));
 
  223   std::auto_ptr<te::rst::Raster> raster(dataset->getRaster(rpos));
 
  224   if(raster.get() == 0)
 
  225     throw Exception(
TE_TR(
"Could not get the raster referenced by the layer!"));
 
  227   return raster.release();
 
  238     visibleLayers.push_back(layer);
 
  240   for(std::size_t i = 0; i < layer->getChildrenCount(); ++i)
 
  250   for(std::list<te::map::AbstractLayerPtr>::const_iterator it = layers.begin(); it != layers.end(); ++it)
 
  258   for(std::list<te::map::AbstractLayerPtr>::const_iterator it = layers.begin(); it != layers.end(); ++it)
 
  274   for(std::size_t i = 0; i < layer->getChildrenCount(); ++i)
 
  288     throw Exception(
TE_TR(
"Could not copy the data set to memory!"));
 
  303   const std::string& datasetName = type->
getName();
 
  304   assert(!datasetName.empty());
 
  313   std::size_t nRules = style->
getRules().size();
 
  315   for(std::size_t i = 0; i < nRules; ++i) 
 
  327     std::auto_ptr<te::da::DataSet> dataset(0);
 
  331       dataset = ds->getDataSet(datasetName, geometryProperty->getName(), &bbox, 
te::gm::INTERSECTS);
 
  341         throw Exception(
TE_TR(
"Could not convert the OGC Filter expression to TerraLib expression!"));
 
  354       wh->
setExp(finalRestriction);
 
  369       dataset = ds->query(select);
 
  372     if(dataset.get() == 0)
 
  373       throw Exception((boost::format(
TE_TR(
"Could not retrieve the data set %1%.")) % datasetName).str());
 
  375     if(dataset->moveNext() == 
false)
 
  379     const std::vector<te::se::Symbolizer*>& symbolizers = rule->
getSymbolizers();
 
  380     std::size_t nSymbolizers = symbolizers.size();
 
  383     std::string message = 
TE_TR(
"Drawing the dataset");
 
  384     message += 
" " + datasetName + 
". ";
 
  385     message += 
TE_TR(
"Rule");
 
  386     message += 
" " + boost::lexical_cast<std::string>(i + 1) + 
" " + 
TE_TR(
"of") + 
" ";
 
  387     message += boost::lexical_cast<std::string>(nRules) + 
".";
 
  393     for(std::size_t j = 0; j < nSymbolizers; ++j) 
 
  405       DrawGeometries(dataset.get(), gpos, canvas, bboxSRID, srid, &task);
 
  408       dataset->moveFirst();
 
  421   bool needRemap = 
false;
 
  436     std::auto_ptr<te::gm::Geometry> geom(0);
 
  443     catch(std::exception& )
 
  451       geom->setSRID(fromSRID);
 
  452       geom->transform(toSRID);
 
  455     canvas->
draw(geom.get());
 
  470   const std::string& datasetName = type->
getName();
 
  471   assert(!datasetName.empty());
 
  477   std::auto_ptr<te::da::DataSet> dataset(ds->getDataSet(datasetName, rasterProperty->getName(), &bbox, 
te::gm::INTERSECTS));
 
  478   if(dataset.get() == 0)
 
  479     throw Exception((boost::format(
TE_TR(
"Could not retrieve the data set %1%.")) % datasetName).str());
 
  483   std::auto_ptr<te::rst::Raster> raster(dataset->getRaster(rpos));
 
  484   if(dataset.get() == 0)
 
  485     throw Exception((boost::format(
TE_TR(
"Could not retrieve the raster from the data set %1%.")) % datasetName).str());
 
  487   DrawRaster(raster.get(), canvas, bbox, bboxSRID, visibleArea, srid, style);
 
  501   std::auto_ptr<te::rst::Grid> gridCanvas(
new te::rst::Grid(static_cast<unsigned int>(canvas->
getWidth()), static_cast<unsigned int>(canvas->
getHeight()), gmbr, srid));
 
  504   double resx = visibleArea.
getWidth() / 
static_cast<double>(canvas->
getWidth());
 
  510   double factor = std::min(rx, ry);
 
  511   factor = std::max(factor, 1.0);
 
  513   std::size_t level = 
static_cast<std::size_t
>(std::log(factor) / std::log(2.0));
 
  517   bool needDelete = 
false;
 
  519   if(level != 0 && numberOfLevels != 0) 
 
  521     if(numberOfLevels >= level)
 
  540     const std::complex<double>* cmin = rsMin->at(0).m_minVal;
 
  541     const std::complex<double>* cmax = rsMax->at(0).m_maxVal;
 
  542     double min = cmin->real();
 
  543     double max = cmax->real();
 
  554   std::size_t nRules = style->
getRules().size();
 
  560   const std::vector<te::se::Symbolizer*>& symbolizers = rule->
getSymbolizers();
 
  561   assert(!symbolizers.empty());
 
  565   assert(rasterSymbolizer);
 
  572   bool needRemap = 
false;
 
  577   std::string message = 
TE_TR(
"Drawing raster");
 
  578   const std::string& rasterName = raster->
getName();
 
  579   !rasterName.empty() ? message += 
" " + raster->
getName() + 
". " : message += 
".";
 
  597     converter->setSourceSRID(srid);
 
  598     converter->setTargetSRID(bboxSRID);
 
  602   for(
unsigned int r = 0; r < gridCanvas->getNumberOfRows(); ++r)
 
  604     for(
unsigned int c = 0; c < gridCanvas->getNumberOfColumns(); ++c)
 
  609         converter->convert(inputGeo.
x, inputGeo.
y, inputGeo.
x, inputGeo.
y);
 
  621            color = rasterTransform.
apply(x, y);
 
  657   if(rasterSymbolizer->getImageOutline() == 0)
 
  661   te::se::Symbolizer* outlineSymbolizer = rasterSymbolizer->getImageOutline()->getSymbolizer();
 
  662   if(outlineSymbolizer == 0)
 
  667   cc.
config(outlineSymbolizer);
 
  673     geom->setSRID(bboxSRID);
 
  674     geom->transform(srid);
 
  677   canvas->
draw(geom.get());
 
  687   std::vector<te::rst::BandProperty*> bprops;
 
  695     bprops.push_back(bp);
 
  706   bool needRemap = 
false;
 
  715     converter->setSourceSRID(srid);
 
  716     converter->setTargetSRID(bboxSRID);
 
  727         converter->convert(inputGeo.
x, inputGeo.
y, inputGeo.
x, inputGeo.
y);
 
  738         std::vector<double> values;
 
  752   std::auto_ptr<te::map::LayerSchema> schema(layer->getSchema());
 
  755   assert(geometryProperty);
 
  774   std::auto_ptr<te::da::DataSet> dataset(layer->getData());
 
  775   assert(dataset.get());
 
  781   std::auto_ptr<te::gm::Geometry> g(dataset->getGeometry(gpos));
 
  784   return g->getGeomTypeId();
 
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager. 
 
unsigned int getNumberOfRows() const 
Returns the grid number of rows. 
 
virtual void setValues(unsigned int c, unsigned int r, const std::vector< double > &values)
Sets the imaginary attribute values in all complex bands of a cell. 
 
te::gm::Envelope * getExtent()
Returns the geographic extension of the raster data. 
 
TEDATAACCESSEXPORT te::rst::RasterProperty * GetFirstRasterProperty(const DataSetType *dt)
 
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code. 
 
Utility functions for the data access module. 
 
const std::string & getDataSetName() const 
 
An abstract class that models a source of data in a query. 
 
The Field class can be used to model an expression that takes part of the output items of a SELECT...
 
Spatial intersects operator. 
 
A class that models the name of a dataset used in a From clause. 
 
boost::shared_ptr< DataSource > DataSourcePtr
 
bool hasGeom() const 
It returns true if the DataSetType has at least one geometry property; otherwise, it returns false...
 
A raster band description. 
 
TEMAPEXPORT te::gm::Envelope GetExtent(const std::list< te::map::AbstractLayerPtr > &layers, int srid, bool onlyVisibles)
It calculates the extent of the given layers in the given SRID. 
 
A class that models the name of any property of an object. 
 
A class that models the description of a dataset. 
 
unsigned int getNumberOfColumns() const 
Returns the raster number of columns. 
 
A Symbolizer describes how a feature is to appear on a map. 
 
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band. 
 
TEMAPEXPORT te::rst::RasterProperty * GetRasterProperty(DataSetLayer *layer)
It gets the raster property referenced by the given data set layer. 
 
A visitor that converts a OGC Filter Expression to TerraLib Expression. 
 
virtual int getHeight() const =0
It returns the canvas height. 
 
The CoverageStyle defines the styling that is to be applied to a subset of Coverage data...
 
virtual void getValues(unsigned int c, unsigned int r, std::vector< double > &values) const 
Returns the imaginary attribute values in all complex bands of a cell. 
 
This class can be used to inform the progress of a task. 
 
TEMAPEXPORT te::gm::GeomType GetGeomType(const te::map::AbstractLayerPtr &layer)
It gets the geometry type of the given layer. 
 
double getWidth() const 
It returns the envelope width. 
 
te::da::Expression * getExpression(const te::fe::Filter *f)
It converts the OGC Filter Expression to a TerraLib Expression. 
 
virtual int getWidth() const =0
It returns the canvas width. 
 
An utility struct for representing 2D coordinates. 
 
A layer with reference to a dataset. 
 
const te::fe::Filter * getFilter() const 
 
#define TE_TR(message)
It marks a string in order to get translated. 
 
TEMAPEXPORT void DrawGeometries(te::da::DataSetType *type, te::da::DataSourcePtr ds, Canvas *canvas, const te::gm::Envelope &bbox, int bboxSRID, int srid, te::se::FeatureTypeStyle *style)
It draws the data set geometries in the given canvas using the informed SRID and style. 
 
bool isActive() const 
Verify if the task is active. 
 
Boolean logic operator: AND. 
 
void Union(const Envelope &rhs)
It updates the envelop with coordinates of another envelope. 
 
void geoToGrid(const double &x, const double &y, double &col, double &row) const 
Get the grid point associated to a spatial location. 
 
This is an abstract class that models a query expression. 
 
Rule * getRule(std::size_t i) const 
 
const std::vector< Rule * > & getRules() const 
 
TEMAPEXPORT te::gm::Envelope GetSelectedExtent(const std::list< te::map::AbstractLayerPtr > layers, int srid, bool onlyVisibles)
It calculates the extent of selected objects of the given layers in the given SRID. 
 
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection. 
 
TEMAPEXPORT te::da::DataSet * DataSet2Memory(te::da::DataSet *dataset)
It creates a new In-Memory dataset with the items from the given dataset. 
 
void Tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
It tokenizes a given string with a delimiter of your own choice. 
 
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
 
void Free(std::vector< T * > *v)
This function can be applied to a pointer to a vector of pointers. 
 
TEMAPEXPORT void GetDashStyle(const std::string &dasharray, std::vector< double > &style)
Converts a dasharray pattern coded by a string to a vector of double. 
 
static RasterSummaryManager & getInstance()
It returns a reference to the singleton instance. 
 
TERASTEREXPORT int Round(double val)
Round a double value to a integer value. 
 
An Envelope defines a 2D rectangular region. 
 
const std::string & getDataSourceId() const 
 
The FeatureTypeStyle defines the styling that is to be applied to a dataset that can be viewed as a f...
 
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib. 
 
This class represents a set of unique ids created in the same context. i.e. from the same data set...
 
An abstract class for raster data strucutures. 
 
unsigned int getNumberOfRows() const 
Returns the raster number of rows. 
 
bool hasRaster() const 
It returns true if the DataSetType has at least one raster property; otherwise, it returns false...
 
BandProperty * getProperty()
Returns the band property. 
 
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster. 
 
unsigned int getNumberOfColumns() const 
Returns the grid number of columns. 
 
double getResolutionX() const 
Returns the raster horizontal (x-axis) resolution. 
 
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers. 
 
A visitor that converts a OGC Filter Expression to TerraLib Expression. 
 
boost::ptr_vector< BandSummary > RasterSummary
RasterSummary is just a typedef of a boost::ptr_vector. 
 
A class that can be used to model a filter expression that can be applied to a query. 
 
void setExp(Expression *exp)
Sets the expression. 
 
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1. 
 
The RasterSymbolizer describes how to render raster/matrix-coverage data (e.g., satellite photos...
 
virtual void drawImage(char *src, std::size_t size, ImageType t)=0
It draws the src image over the canvas. 
 
A raster band description. 
 
A filter is any valid predicate expression. 
 
Grid * getGrid()
It returns the raster grid. 
 
TEMAPEXPORT te::rst::Raster * GetRaster(DataSetLayer *layer)
It gets the raster referenced by the given data set layer. 
 
A Select models a query to be used when retrieving data from a DataSource. 
 
virtual std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value. 
 
const std::vector< Symbolizer * > & getSymbolizers() const 
 
boost::ptr_vector< FromItem > From
It models the FROM clause for a query. 
 
A Converter is responsible for the conversion of coordinates between different Coordinate Systems (CS...
 
A dataset is the unit of information manipulated by the data access module of TerraLib. 
 
A canvas is an abstraction of a drawing area. 
 
virtual Raster * getMultiResLevel(const unsigned int level) const =0
Returns the required level of a multi-resolution pyramid or NULL if that level does not exists...
 
const std::string & getName() const 
Returns the raster name. 
 
A Rule is used to attach property/scale conditions to and group the individual symbols used for rende...
 
std::auto_ptr< te::gm::Envelope > GetExtent(te::da::DataSet *dset, te::qt::widgets::Promoter *p, const int &rowPosition)
 
static Raster * make()
It creates and returns an empty raster with default raster driver. 
 
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color. 
 
TEMAPEXPORT te::rst::Raster * GetExtentRaster(te::rst::Raster *raster, int w, int h, const te::gm::Envelope &bbox, int bboxSRID, const te::gm::Envelope &visibleArea, int srid)
 
A class that models a literal for Envelope values. 
 
void gridToGeo(const double &col, const double &row, double &x, double &y) const 
Get the spatial location of a grid point. 
 
double getResolutionY() const 
Returns the raster vertical (y-axis) resolution. 
 
int getType() const 
It returns the data type of the elements in the band. 
 
A layer with reference to a dataset. 
 
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
 
Visibility
Each layer can have three states of visibility. 
 
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
 
A rectified grid is the spatial support for raster data. 
 
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
 
void transform(int oldsrid, int newsrid)
It will transform the coordinates of the Envelope from the old SRS to the new one. 
 
virtual int getBandDataType(std::size_t i) const =0
Returns the data type in a particular band (or dimension). 
 
virtual void draw(const te::gm::Geometry *geom)=0
It draws the geometry on canvas. 
 
double getHeight() const 
It returns the envelope height. 
 
virtual unsigned int getMultiResLevelsCount() const =0
Returns the current number of multi-resolution pyramid levels. 
 
bool isValid() const 
It tells if the rectangle is valid or not. 
 
TEMAPEXPORT void DrawRaster(te::da::DataSetType *type, te::da::DataSourcePtr ds, Canvas *canvas, const te::gm::Envelope &bbox, int bboxSRID, const te::gm::Envelope &visibleArea, int srid, te::se::CoverageStyle *style)
 
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope. 
 
TEMAPEXPORT void GetVisibleLayers(const std::list< te::map::AbstractLayerPtr > &layers, std::list< te::map::AbstractLayerPtr > &visibleLayers)
It gets the visible layers of the given layer list. 
 
const std::string & getName() const 
It returns the property name.