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/Fill.h"
56 #include "../se/ImageOutline.h"
57 #include "../se/ParameterValue.h"
58 #include "../se/SelectedChannel.h"
59 #include "../se/Stroke.h"
60 #include "../se/SvgParameter.h"
61 #include "../se/RasterSymbolizer.h"
62 #include "../se/Rule.h"
63 #include "../srs/Config.h"
64 #include "../srs/Converter.h"
75 #include <boost/format.hpp>
76 #include <boost/lexical_cast.hpp>
100 if(color == 0 && opacity == 0)
141 return *p->m_mixedData;
153 std::list<te::map::AbstractLayerPtr>::const_iterator it = layers.begin();
157 while(it != layers.end())
159 if(it == layers.begin())
179 if(!layer->hasChildren())
181 std::auto_ptr<te::da::DataSetType> dt(layer->getSchema());
188 std::auto_ptr<te::da::DataSet> ds(layer->getData(objSet));
192 while(ds->moveNext())
194 std::auto_ptr<te::gm::Geometry> geom = ds->getGeometry(geomProp->getName());
198 if(layer->getSRID() != srid)
199 auxEnv.
transform(layer->getSRID(), srid);
208 finalEnv.
Union(auxEnv);
213 for(std::size_t i = 0; i < layer->getChildrenCount(); ++i)
229 std::vector<std::string> values;
231 for(std::size_t i = 0; i < values.size(); ++i)
232 style.push_back(atof(values[i].c_str()));
238 throw Exception(
TR_MAP(
"The layer is invalid!"));
244 throw Exception(
TR_MAP(
"The data set name referenced by the layer is empty!"));
250 std::auto_ptr<te::da::DataSetType> dstype(ds->getDataSetType(dsname));
252 if(dstype.get() == 0)
253 throw Exception(
TR_MAP(
"Could not get the data set type!"));
256 std::auto_ptr<te::rst::RasterProperty> rasterProperty(dynamic_cast<te::rst::RasterProperty*>(dstype->getProperties()[0]->clone()));
258 if(rasterProperty.get() == 0)
259 throw Exception(
TR_MAP(
"Could not get the raster property!"));
261 return rasterProperty.release();
267 throw Exception(
TR_MAP(
"The layer is invalid!"));
273 throw Exception(
TR_MAP(
"The data set name referenced by the layer is empty!"));
279 std::auto_ptr<te::da::DataSetType> dstype(ds->getDataSetType(dsname));
281 if(dstype.get() == 0)
282 throw Exception(
TR_MAP(
"Could not get the data set type!"));
284 if(!dstype->hasRaster())
285 throw Exception(
TR_MAP(
"The data set referenced by the layer not contains raster data!"));
288 std::auto_ptr<te::da::DataSet> dataset(ds->getDataSet(dsname));
289 if(dataset.get() == 0)
290 throw Exception(
TR_MAP(
"Could not get the data set reference by the layer!"));
295 std::auto_ptr<te::rst::Raster> raster(dataset->getRaster(rpos));
296 if(raster.get() == 0)
297 throw Exception(
TR_MAP(
"Could not get the raster referenced by the layer!"));
299 return raster.release();
310 visibleLayers.push_back(layer);
312 for(std::size_t i = 0; i < layer->getChildrenCount(); ++i)
322 for(std::list<te::map::AbstractLayerPtr>::const_iterator it = layers.begin(); it != layers.end(); ++it)
330 for(std::list<te::map::AbstractLayerPtr>::const_iterator it = layers.begin(); it != layers.end(); ++it)
346 for(std::size_t i = 0; i < layer->getChildrenCount(); ++i)
360 throw Exception(
TR_MAP(
"Could not copy the data set to memory!"));
375 const std::string& datasetName = type->
getName();
376 assert(!datasetName.empty());
385 std::size_t nRules = style->
getRules().size();
387 for(std::size_t i = 0; i < nRules; ++i)
399 std::auto_ptr<te::da::DataSet> dataset(0);
403 dataset = ds->getDataSet(datasetName, geometryProperty->getName(), &bbox,
te::gm::INTERSECTS);
413 throw Exception(
TR_MAP(
"Could not convert the OGC Filter expression to TerraLib expression!"));
426 wh->
setExp(finalRestriction);
441 dataset = ds->query(select);
444 if(dataset.get() == 0)
445 throw Exception((boost::format(
TR_MAP(
"Could not retrieve the data set %1%.")) % datasetName).str());
447 if(dataset->moveNext() ==
false)
451 const std::vector<te::se::Symbolizer*>& symbolizers = rule->
getSymbolizers();
452 std::size_t nSymbolizers = symbolizers.size();
455 std::string message =
TR_MAP(
"Drawing the dataset");
456 message +=
" " + datasetName +
". ";
457 message +=
TR_MAP(
"Rule");
458 message +=
" " + boost::lexical_cast<std::string>(i + 1) +
" " +
TR_MAP(
"of") +
" ";
459 message += boost::lexical_cast<std::string>(nRules) +
".";
465 for(std::size_t j = 0; j < nSymbolizers; ++j)
477 DrawGeometries(dataset.get(), gpos, canvas, bboxSRID, srid, &task);
480 dataset->moveFirst();
493 bool needRemap =
false;
508 std::auto_ptr<te::gm::Geometry> geom(0);
515 catch(std::exception& )
523 geom->setSRID(fromSRID);
524 geom->transform(toSRID);
527 canvas->
draw(geom.get());
542 const std::string& datasetName = type->
getName();
543 assert(!datasetName.empty());
549 std::auto_ptr<te::da::DataSet> dataset(ds->getDataSet(datasetName, rasterProperty->getName(), &bbox,
te::gm::INTERSECTS));
550 if(dataset.get() == 0)
551 throw Exception((boost::format(
TR_MAP(
"Could not retrieve the data set %1%.")) % datasetName).str());
555 std::auto_ptr<te::rst::Raster> raster(dataset->getRaster(rpos));
556 if(dataset.get() == 0)
557 throw Exception((boost::format(
TR_MAP(
"Could not retrieve the raster from the data set %1%.")) % datasetName).str());
559 DrawRaster(raster.get(), canvas, bbox, bboxSRID, visibleArea, srid, style);
573 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));
584 const std::complex<double>* cmin = rsMin->at(0).m_minVal;
585 const std::complex<double>* cmax = rsMax->at(0).m_maxVal;
586 double min = cmin->real();
587 double max = cmax->real();
590 rasterTransform.setLinearTransfParameters(min, max, 0, 255);
594 rasterTransform.setLinearTransfParameters(0, 255, 0, 255);
598 std::size_t nRules = style->
getRules().size();
604 const std::vector<te::se::Symbolizer*>& symbolizers = rule->
getSymbolizers();
605 assert(!symbolizers.empty());
609 assert(rasterSymbolizer);
616 bool needRemap =
false;
621 std::string message =
TR_MAP(
"Drawing raster");
622 const std::string& rasterName = raster->
getName();
623 !rasterName.empty() ? message +=
" " + raster->
getName() +
". " : message +=
".";
641 converter->setSourceSRID(srid);
642 converter->setTargetSRID(bboxSRID);
646 for(
unsigned int r = 0; r < gridCanvas->getNumberOfRows(); ++r)
648 for(
unsigned int c = 0; c < gridCanvas->getNumberOfColumns(); ++c)
653 converter->convert(inputGeo.
x, inputGeo.
y, inputGeo.
x, inputGeo.
y);
665 color = rasterTransform.apply(x, y);
698 if(rasterSymbolizer->getImageOutline() == 0)
702 te::se::Symbolizer* outlineSymbolizer = rasterSymbolizer->getImageOutline()->getSymbolizer();
703 if(outlineSymbolizer == 0)
708 cc.
config(outlineSymbolizer);
714 geom->setSRID(bboxSRID);
715 geom->transform(srid);
718 canvas->
draw(geom.get());
728 std::vector<te::rst::BandProperty*> bprops;
736 bprops.push_back(bp);
747 bool needRemap =
false;
756 converter->setSourceSRID(srid);
757 converter->setTargetSRID(bboxSRID);
768 converter->convert(inputGeo.
x, inputGeo.
y, inputGeo.
x, inputGeo.
y);
779 std::vector<double> values;
793 std::auto_ptr<te::map::LayerSchema> schema(layer->getSchema());
796 assert(geometryProperty);
815 std::auto_ptr<te::da::DataSet> dataset(layer->getData());
816 assert(dataset.get());
822 std::auto_ptr<te::gm::Geometry> g(dataset->getGeometry(gpos));
825 return g->getGeomTypeId();
const std::string & getName() const
Returns the raster name.
bool hasRaster() const
It returns true if the DataSetType has at least one raster property; otherwise, it returns false...
boost::ptr_vector< BandSummary > RasterSummary
RasterSummary is just a typedef of a boost::ptr_vector.
The RasterSymbolizer describes how to render raster/matrix-coverage data (e.g., satellite photos...
bool isActive() const
Verify if the task is active.
const std::vector< Rule * > & getRules() const
TEMAPEXPORT void GetColor(const te::se::Stroke *stroke, te::color::RGBAColor &color)
Gets the RGBA color from Stroke element.
A layer with reference to a dataset.
const std::string & getDataSetName() const
bool isValid() const
It tells if the rectangle is valid or not.
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.
A Fill specifies the pattern for filling an area geometry.
TEMAPEXPORT int GetInt(const te::se::ParameterValue *param)
Gets the parameter value as integer.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
The FeatureTypeStyle defines the styling that is to be applied to a dataset that can be viewed as a f...
A class that models the name of a dataset used in a From clause.
Rule * getRule(std::size_t i) const
TERASTEREXPORT int Round(double val)
Round a double value to a integer value.
TEDATAACCESSEXPORT te::rst::RasterProperty * GetFirstRasterProperty(const DataSetType *dt)
unsigned int getNumberOfRows() const
Returns the raster number of rows.
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.
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
A layer with reference to a dataset.
A Select models a query to be used when retrieving data from a DataSource.
A canvas is an abstraction of a drawing area.
A Symbolizer describes how a feature is to appear on a map.
Grid * getGrid()
It returns the raster grid.
Spatial intersects operator.
void config(const te::se::Symbolizer *symbolizer)
It configs the canvas based on given symbolizer.
The Field class can be used to model an expression that takes part of the output items of a SELECT...
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
A Stroke specifies the appearance of a linear geometry.
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
static Raster * make()
It creates and returns an empty raster with default raster driver.
TEMAPEXPORT te::rst::RasterProperty * GetRasterProperty(DataSetLayer *layer)
It gets the raster property referenced by the given data set layer.
const SvgParameter * getOpacity() const
const std::string & getName() const
It returns the property name.
const std::string & getValue() const
It returns the literal value.
TEMAPEXPORT double GetDouble(const te::se::ParameterValue *param)
Gets the parameter value as double.
The CoverageStyle defines the styling that is to be applied to a subset of Coverage data...
Visibility
Each layer can have three states of visibility.
A Raster Transform configurer generates a Raster Transform given a RasterSymbolzier.
const std::vector< Symbolizer * > & getSymbolizers() const
A class that models the name of any property of an object.
const std::string & getDataSourceId() const
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
TEDATAACCESSEXPORT te::gm::Envelope * GetExtent(const std::string &datasetName, const std::string &propertyName, const std::string &datasourceId)
int getGreen() const
It returns the green component color value (a value from 0 to 255).
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
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 filter is any valid predicate expression.
An utility struct for representing 2D coordinates.
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
unsigned int getNumberOfRows() const
Returns the grid number of rows.
virtual void drawImage(char *src, std::size_t size, ImageType t)=0
It draws the src image over the canvas.
TEMAPEXPORT te::da::DataSet * DataSet2Memory(te::da::DataSet *dataset)
It creates a new In-Memory dataset with the items from the given dataset.
TEMAPEXPORT void GetDashStyle(const std::string &dasharray, std::vector< double > &style)
Converts a dasharray pattern coded by a string to a vector of double.
A Rule is used to attach property/scale conditions to and group the individual symbols used for rende...
Boolean logic operator: AND.
te::gm::Envelope * getExtent()
Returns the geographic extension of the raster data.
A Raster Transform configurer generates a Raster Transform given a RasterSymbolzier.
A raster band description.
A rectified grid is the spatial support for raster data.
An abstract class that models a source of data in a query.
A Symbology Enconding visitor that configures a given canvas based on symbolizers elements...
Utility functions for the data access module.
An exception class for the MapTools module.
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)
virtual int getHeight() const =0
It returns the canvas height.
bool hasGeom() const
It returns true if the DataSetType has at least one geometry property; otherwise, it returns false...
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
TEMAPEXPORT te::rst::Raster * GetRaster(DataSetLayer *layer)
It gets the raster referenced by the given data set layer.
This class can be used to represent literal values.
void setColor(const std::string &hexColor)
It sets the color using a two hexadecimal RGB-encoded color.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
A visitor that converts a OGC Filter Expression to TerraLib Expression.
virtual int getBandDataType(std::size_t i) const =0
Returns the data type in a particular band (or dimension).
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
A class that models a literal for Envelope values.
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
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.
void configure()
Configure Transformation.
boost::shared_ptr< DataSource > DataSourcePtr
TEMAPEXPORT std::string GetString(const te::se::ParameterValue *param)
Gets the parameter value as string.
A Symbology Enconding visitor that configures a given canvas based on symbolizers elements...
const Parameter * getParameter(size_t i) const
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.
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.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
const SvgParameter * getColor() const
void transform(int oldsrid, int newsrid)
It will transform the coordinates of the Envelope from the old SRS to the new one.
#define TR_MAP(message)
It marks a string in order to get translated. This is a special mark used in the Map Rendering module...
const te::fe::Filter * getFilter() const
#define TE_OPAQUE
For an RGBA color this is the value of the alpha-channel for totally opaque.
A raster band description.
void Free(std::vector< T * > *v)
This function can be applied to a pointer to a vector of pointers.
A class that models the description of a dataset.
const SvgParameter * getOpacity() const
void gridToGeo(const double &col, const double &row, double &x, double &y) const
Get the spatial location of a grid point.
A Converter is responsible for the conversion of coordinates between different Coordinate Systems (CS...
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.
virtual void draw(const te::gm::Geometry *geom)=0
It draws the geometry on canvas.
te::da::Expression * getExpression(const te::fe::Filter *f)
It converts the OGC Filter Expression to a TerraLib Expression.
size_t getNParameters() const
This is an abstract class that models a query expression.
A Raster Transform is a class that defines functions to transform a styled raster.
An abstract class for raster data strucutures.
BandProperty * getProperty()
Returns the band property.
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
This class can be used to inform the progress of a task.
unsigned int getNumberOfColumns() const
Returns the grid number of columns.
const SvgParameter * getColor() const
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
A visitor that converts a OGC Filter Expression to TerraLib Expression.
TEMAPEXPORT te::gm::GeomType GetGeomType(const te::map::AbstractLayerPtr &layer)
It gets the geometry type of the given layer.
A Raster Transform is a class that defines functions to transform a styled raster.
static RasterSummaryManager & getInstance()
It returns a reference to the singleton instance.
virtual std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
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)
An Envelope defines a 2D rectangular region.
A class that can be used to model a filter expression that can be applied to a query.
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.
int getBlue() const
It returns the blue component color value (a value from 0 to 255).
virtual int getWidth() const =0
It returns the canvas width.
void geoToGrid(const double &x, const double &y, double &col, double &row) const
Get the grid point associated to a spatial location.
int getAlpha() const
It returns the alpha component color value (a value from 0 to 255).
The "ParameterValueType" uses WFS-Filter expressions to give values for SE graphic parameters...
A dataset is the unit of information manipulated by the data access module of TerraLib.
void Union(const Envelope &rhs)
It updates the envelop with coordinates of another envelope.
int getRed() const
It returns the red component color value (a value from 0 to 255).
void setExp(Expression *exp)
Sets the expression.