27 #include "../color/RGBAColor.h"
28 #include "../common/progress/TaskProgress.h"
29 #include "../common/Globals.h"
30 #include "../common/STLUtils.h"
31 #include "../common/Translator.h"
32 #include "../dataaccess/dataset/DataSet.h"
33 #include "../dataaccess/dataset/DataSetType.h"
34 #include "../dataaccess/query/And.h"
35 #include "../dataaccess/query/EqualTo.h"
36 #include "../dataaccess/query/GreaterThanOrEqualTo.h"
37 #include "../dataaccess/query/LessThanOrEqualTo.h"
38 #include "../dataaccess/query/LiteralDouble.h"
39 #include "../dataaccess/query/LiteralEnvelope.h"
40 #include "../dataaccess/query/LiteralString.h"
41 #include "../dataaccess/query/PropertyName.h"
42 #include "../dataaccess/query/ST_Intersects.h"
43 #include "../dataaccess/utils/Utils.h"
44 #include "../fe/Filter.h"
45 #include "../geometry/Coord2D.h"
46 #include "../geometry/Envelope.h"
47 #include "../geometry/GeometryProperty.h"
48 #include "../raster/Raster.h"
49 #include "../raster/RasterProperty.h"
50 #include "../se/FeatureTypeStyle.h"
51 #include "../se/CoverageStyle.h"
52 #include "../se/Rule.h"
53 #include "../se/Utils.h"
54 #include "../srs/Config.h"
68 #include <boost/format.hpp>
69 #include <boost/lexical_cast.hpp>
94 throw Exception(
TR_MAP(
"The requested box is invalid!"));
107 throw Exception(
TR_MAP(
"The reprojected box is invalid!"));
109 else if(layer->
getSRID() != srid)
111 throw Exception(
TR_MAP(
"The layer or map don't have a valid SRID!"));
128 std::auto_ptr<LayerSchema> schema(layer->
getSchema());
129 assert(schema.get());
131 if(schema->hasGeom())
138 if(grouping && grouping->isVisible())
140 drawLayerGroupingMem(layer, geometryProperty->
getName(), canvas, ibbox, srid);
152 throw Exception((boost::format(
TR_MAP(
"Could not create a default feature type style to the layer %1%.")) % layer->
getTitle()).str());
160 throw Exception(
TR_MAP(
"The layer style is not a Feature Type Style!"));
162 drawLayerGeometries(layer, geometryProperty->
getName(), fts, canvas, ibbox, srid);
164 else if(schema->hasRaster())
177 throw Exception((boost::format(
TR_MAP(
"Could not create a default coverage style to the layer %1%.")) % layer->
getTitle()).str());
185 throw Exception(
TR_MAP(
"The layer style is not a Coverage Style!"));
190 if(dataset.get() == 0)
191 throw Exception((boost::format(
TR_MAP(
"Could not retrieve the data set from the layer %1%.")) % layer->
getTitle()).str());
196 std::auto_ptr<te::rst::Raster> raster(dataset->getRaster(rpos));
197 if(dataset.get() == 0)
198 throw Exception((boost::format(
TR_MAP(
"Could not retrieve the raster from the layer %1%.")) % layer->
getTitle()).str());
205 throw Exception(
TR_MAP(
"The layer don't have a geometry or raster property!"));
210 const std::string& geomPropertyName,
216 assert(!geomPropertyName.empty());
222 std::size_t nRules = style->
getRules().size();
224 for(std::size_t i = 0; i < nRules; ++i)
236 std::auto_ptr<te::da::DataSet> dataset(0);
245 catch(std::exception& )
260 throw Exception(
TR_MAP(
"Could not convert the OGC Filter expression to TerraLib expression!"));
273 dataset = layer->
getData(restriction);
275 catch(std::exception& )
281 if(dataset.get() == 0)
282 throw Exception((boost::format(
TR_MAP(
"Could not retrieve the data set from the layer %1%.")) % layer->
getTitle()).str());
284 if(dataset->moveNext() ==
false)
288 const std::vector<te::se::Symbolizer*>& symbolizers = rule->
getSymbolizers();
291 std::string message =
TR_MAP(
"Drawing the layer");
292 message +=
" " + layer->
getTitle() +
". ";
293 message +=
TR_MAP(
"Rule");
294 message +=
" " + boost::lexical_cast<std::string>(i + 1) +
" " +
TR_MAP(
"of") +
" ";
295 message += boost::lexical_cast<std::string>(nRules) +
".";
304 if(symbolizers.empty())
307 std::auto_ptr<te::gm::Geometry> g(dataset->getGeometry(gpos));
315 dataset->moveFirst();
318 std::size_t nSymbolizers = symbolizers.size();
320 for(std::size_t j = 0; j < nSymbolizers; ++j)
329 if(j != nSymbolizers - 1)
330 drawDatSetGeometries(dataset.get(), gpos, canvas, layer->
getSRID(), srid, 0, &task);
332 drawDatSetGeometries(dataset.get(), gpos, canvas, layer->
getSRID(), srid, layer->
getChart(), &task);
335 dataset->moveFirst();
343 const std::string& geomPropertyName,
348 assert(!geomPropertyName.empty());
358 assert(!propertyName.empty());
369 std::size_t nGroupItems = items.size();
372 std::string message =
TR_MAP(
"Drawing the grouping of layer");
373 message +=
" " + layer->
getTitle() +
".";
378 for(std::size_t i = 0; i < nGroupItems; ++i)
429 std::auto_ptr<te::da::DataSet> dataset(0);
432 dataset = layer->
getData(restriction);
434 catch(std::exception& )
439 if(dataset.get() == 0)
440 throw Exception((boost::format(
TR_MAP(
"Could not retrieve the data set from the layer %1%.")) % layer->
getTitle()).str());
442 if(dataset->moveNext() ==
false)
446 const std::vector<te::se::Symbolizer*>& symbolizers = item->
getSymbolizers();
447 std::size_t nSymbolizers = symbolizers.size();
452 for(std::size_t j = 0; j < nSymbolizers; ++j)
461 if(j != nSymbolizers - 1)
462 drawDatSetGeometries(dataset.get(), gpos, canvas, layer->
getSRID(), srid, 0, &task);
464 drawDatSetGeometries(dataset.get(), gpos, canvas, layer->
getSRID(), srid, layer->
getChart(), &task);
467 dataset->moveFirst();
480 const std::string& geomPropertyName,
485 assert(!geomPropertyName.empty());
495 assert(!propertyName.empty());
501 const std::size_t& precision = grouping->
getPrecision();
506 std::size_t nGroupItems = items.size();
509 std::map<std::string, std::vector<te::se::Symbolizer*> > uniqueGroupsMap;
512 std::map<std::pair< double, double>, std::vector<te::se::Symbolizer*> > othersGroupsMap;
514 for(std::size_t i = 0; i < nGroupItems; ++i)
528 std::pair<double, double> range(lowerLimit, upperLimit);
535 std::string message =
TR_MAP(
"Drawing the grouping of layer");
536 message +=
" " + layer->
getTitle() +
".";
541 std::auto_ptr<te::da::DataSet> dataset(0);
546 catch(std::exception& )
551 if(dataset.get() == 0)
552 throw Exception((boost::format(
TR_MAP(
"Could not retrieve the data set from the layer %1%.")) % layer->
getTitle()).str());
554 if(dataset->moveNext() ==
false)
561 std::auto_ptr<te::map::LayerSchema> dt(layer->
getSchema());
565 bool needRemap =
false;
574 std::vector<te::se::Symbolizer*> symbolizers;
579 if(dataset->isNull(propertyPos))
582 value = dataset->getAsString(propertyPos, precision);
586 std::map<std::string, std::vector<te::se::Symbolizer*> >::const_iterator it = uniqueGroupsMap.find(value);
587 if(it == uniqueGroupsMap.end())
589 symbolizers = it->second;
593 double dvalue = atof(value.c_str());
594 std::map<std::pair< double, double>, std::vector<te::se::Symbolizer*> >::const_iterator it;
595 for(it = othersGroupsMap.begin(); it != othersGroupsMap.end(); ++it)
597 if(dvalue >= it->first.first && dvalue <= it->first.second)
601 if(it == othersGroupsMap.end())
616 symbolizers = it->second;
619 if(symbolizers.empty())
623 std::auto_ptr<te::gm::Geometry> geom;
626 geom = dataset->getGeometry(gpos);
630 catch(std::exception& )
636 std::size_t nSymbolizers = symbolizers.size();
638 for(std::size_t j = 0; j < nSymbolizers; ++j)
649 geom->setSRID(layer->
getSRID());
650 geom->transform(srid);
653 canvas->
draw(geom.get());
655 if(chart && j == nSymbolizers - 1)
656 buildChart(chart, dataset.get(), geom.get());
659 }
while(dataset->moveNext());
662 for(std::size_t i = 0; i < m_chartCoordinates.size(); ++i)
664 canvas->
drawImage(static_cast<int>(m_chartCoordinates[i].x),
665 static_cast<int>(m_chartCoordinates[i].y),
675 int fromSRID,
int toSRID,
682 bool needRemap =
false;
697 std::auto_ptr<te::gm::Geometry> geom(0);
704 catch(std::exception& )
712 geom->setSRID(fromSRID);
713 geom->transform(toSRID);
716 canvas->
draw(geom.get());
719 buildChart(chart, dataset, geom.get());
724 for(std::size_t i = 0; i < m_chartCoordinates.size(); ++i)
726 canvas->
drawImage(static_cast<int>(m_chartCoordinates[i].x),
727 static_cast<int>(m_chartCoordinates[i].y),
745 double dx = 0.0;
double dy = 0.0;
755 std::vector<std::size_t> report;
756 m_rtree.search(chartEnvelope, report);
762 m_rtree.insert(chartEnvelope, ++m_index);
768 std::size_t width = 0;
770 m_chartImages.push_back(rgba);
776 m_chartCoordinates.clear();
777 m_chartImages.clear();
GroupingType
The grouping type associated to the layer.
std::vector< te::rst::BandProperty * > & getBandProperties()
Returns a reference to the list of bands definitions.
bool isActive() const
Verify if the task is active.
This class represents the informations needed to build map charts.
const std::vector< Rule * > & getRules() const
virtual te::map::Chart * getChart() const
It returns the Chart associated to the Layer.
bool isValid() const
It tells if the rectangle is valid or not.
void push_back(Symbolizer *s)
This class contains the parameters needed for grouping the values of a Property.
The FeatureTypeStyle defines the styling that is to be applied to a dataset that can be viewed as a f...
Rule * getRule(std::size_t i) const
TEDATAACCESSEXPORT te::rst::RasterProperty * GetFirstRasterProperty(const DataSetType *dt)
std::size_t getWidth() const
Expression * clone() const
It creates a new copy of this expression.
virtual const std::string & getTitle() const
It returns the layer title.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
This is the base class for layers.
A canvas is an abstraction of a drawing area.
void drawDatSetGeometries(te::da::DataSet *dataset, const std::size_t &gpos, Canvas *canvas, int fromSRID, int toSRID, Chart *chart, te::common::TaskProgress *task=0)
It draws the data set geometries in the given canvas using the informed SRS.
A Symbolizer describes how a feature is to appear on a map.
Spatial intersects operator.
bool isVisible() const
It gets the chart visibility.
It models the inequality operator greater than or equal to (>=).
This class models a string Literal value.
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
virtual std::auto_ptr< LayerSchema > getSchema() const =0
It returns the layer schema.
It renders the objects associated to an abstract layer. i.e. a generic renderer.
const std::string & getName() const
It returns the property name.
The CoverageStyle defines the styling that is to be applied to a subset of Coverage data...
const std::vector< Symbolizer * > & getSymbolizers() const
A class that models the name of any property of an object.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
const std::string & getValue() const
It gets the value of the legend item.
virtual te::map::Grouping * getGrouping() const
It returns the Grouping associated to the Layer.
int getPropertyType() const
It gets the property type whose values will be grouped.
void drawLayerGeometries(AbstractLayer *layer, const std::string &geomPropertyName, te::se::FeatureTypeStyle *style, Canvas *canvas, const te::gm::Envelope &bbox, int srid)
It draws the abstract layer in the given canvas using the SRS informed.
A filter is any valid predicate expression.
An utility struct for representing 2D coordinates.
~AbstractLayerRenderer()
Destructor.
virtual void drawImage(char *src, std::size_t size, ImageType t)=0
It draws the src image over the canvas.
A Rule is used to attach property/scale conditions to and group the individual symbols used for rende...
Boolean logic operator: AND.
TESEEXPORT Style * CreateFeatureTypeStyle(const te::gm::GeomType &geomType)
Try creates an appropriate feature type style based on given geometry type.
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
double m_lly
Lower left corner y-coordinate.
A Symbology Enconding visitor that configures a given canvas based on symbolizers elements...
This is a singleton for managing chart renderer instance available in the system. ...
Utility functions for the data access module.
An exception class for the MapTools module.
virtual int getHeight() const =0
It returns the canvas height.
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
double m_ury
Upper right corner y-coordinate.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
It models the inequality operator less than or equal to (<=).
TESEEXPORT Style * CreateCoverageStyle(const std::vector< te::rst::BandProperty * > &properties)
Try creates an appropriate coverage style based on given band properties.
std::string getPropertyName() const
It gets the property name whose values will be grouped.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
A visitor that converts a OGC Filter Expression to TerraLib Expression.
TESEEXPORT Symbolizer * CreateSymbolizer(const te::gm::GeomType &geomType)
Try creates an appropriate symbolizer based on given geometry type.
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
void drawLayerGroupingMem(AbstractLayer *layer, const std::string &geomPropertyName, Canvas *canvas, const te::gm::Envelope &bbox, int srid)
It draws the grouping of the abstract layer in the given canvas using the SRS informed.
A class that models a literal for Envelope values.
double m_urx
Upper right corner x-coordinate.
A Symbology Enconding visitor that configures a given canvas based on symbolizers elements...
virtual te::se::Style * getStyle() const
It returns the Style associated to the layer.
virtual const te::gm::Envelope & getExtent() const
It returns the Layer extent (or minimum bounding box).
void draw(AbstractLayer *layer, Canvas *canvas, const te::gm::Envelope &bbox, int srid)
It draws the layer geographic objects in the given canvas using the SRS informed. ...
const size_t getPrecision() const
It gets the precision used for the property values.
Envelope intersection(const Envelope &rhs) const
It returns an envelope that represents the point set intersection with another envelope.
const std::string & getLowerLimit() const
It gets the lower limit value of the legend item.
Coord2D getCenter() const
It returns the rectangle's center coordinate.
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...
TEDATAACCESSEXPORT std::size_t GetPropertyPos(const DataSet *dataset, const std::string &name)
const te::fe::Filter * getFilter() const
The Style defines the styling that is to be applied to a geographic dataset (vector geometries or cov...
void Free(std::vector< T * > *v)
This function can be applied to a pointer to a vector of pointers.
This class contains the parameters needed for grouping the values of a Property.
bool intersects(const Envelope &rhs) const
It returns true if the envelopes "spatially intersects".
virtual void draw(const te::gm::Geometry *geom)=0
It draws the geometry on canvas.
const std::vector< te::se::Symbolizer * > & getSymbolizers() const
It gets the symbolizer of the legend item.
te::da::Expression * getExpression(const te::fe::Filter *f)
It converts the OGC Filter Expression to a TerraLib Expression.
This is an abstract class that models a query expression.
double m_llx
Lower left corner x-coordinate.
This class represents the informations needed to build map charts.
This class can be used to inform the progress of a task.
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
It models the comparison operator.
This is the base class for Layers.
A visitor that converts a OGC Filter Expression to TerraLib Expression.
void drawLayerGrouping(AbstractLayer *layer, const std::string &geomPropertyName, Canvas *canvas, const te::gm::Envelope &bbox, int srid)
It draws the grouping of the abstract layer in the given canvas using the SRS informed.
static const std::string sm_nanStr
Not a number string value.
static T & getInstance()
It returns a reference to the singleton instance.
void buildChart(Chart *chart, te::da::DataSet *dataset, te::gm::Geometry *geom)
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.
std::size_t getHeight() const
virtual int getSRID() const
It returns the Spatial Reference System ID associated to the Layer.
virtual int getWidth() const =0
It returns the canvas width.
A class that models a literal for double values.
const std::string & getUpperLimit() const
It gets the upper limit value of the legend item.
const std::vector< te::map::GroupingItem * > & getGroupingItems() const
It gets the vector of grouping items.
A dataset is the unit of information manipulated by the data access module of TerraLib.
virtual void setStyle(te::se::Style *style)
It sets the Style associated to the layer.
virtual std::auto_ptr< te::da::DataSet > getData(te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess) const =0
It gets the dataset identified by the layer name.
const GroupingType getType() const
It gets the grouping type.
A GroupingItem contains information about a grouping item associated to a layer.