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 "../geometry/MultiPolygon.h"
49 #include "../geometry/Polygon.h"
50 #include "../raster/Raster.h"
51 #include "../raster/RasterProperty.h"
52 #include "../se/FeatureTypeStyle.h"
53 #include "../se/CoverageStyle.h"
54 #include "../se/Rule.h"
55 #include "../se/Utils.h"
56 #include "../srs/Config.h"
70 #include <boost/format.hpp>
71 #include <boost/lexical_cast.hpp>
96 throw Exception(
TE_TR(
"The requested box is invalid!"));
109 throw Exception(
TE_TR(
"The reprojected box is invalid!"));
111 else if(layer->
getSRID() != srid)
113 throw Exception(
TE_TR(
"The layer or map don't have a valid SRID!"));
130 std::auto_ptr<LayerSchema> schema(layer->
getSchema());
131 assert(schema.get());
136 if(schema->hasGeom())
140 if(spatialPropertyName.empty())
145 assert(geometryProperty);
151 drawLayerGroupingMem(layer, geometryProperty->
getName(), canvas, ibbox, srid);
163 throw Exception((boost::format(
TE_TR(
"Could not create a default feature type style to the layer %1%.")) % layer->
getTitle()).str());
171 throw Exception(
TE_TR(
"The layer style is not a Feature Type Style!"));
173 drawLayerGeometries(layer, geometryProperty->
getName(), fts, canvas, ibbox, srid);
175 else if(schema->hasRaster())
179 if(spatialPropertyName.empty())
184 assert(rasterProperty);
194 throw Exception((boost::format(
TE_TR(
"Could not create a default coverage style to the layer %1%.")) % layer->
getTitle()).str());
202 throw Exception(
TE_TR(
"The layer style is not a Coverage Style!"));
207 if(dataset.get() == 0)
208 throw Exception((boost::format(
TE_TR(
"Could not retrieve the data set from the layer %1%.")) % layer->
getTitle()).str());
211 std::auto_ptr<te::rst::Raster> raster(dataset->getRaster(rasterProperty->
getName()));
212 if(dataset.get() == 0)
213 throw Exception((boost::format(
TE_TR(
"Could not retrieve the raster from the layer %1%.")) % layer->
getTitle()).str());
220 throw Exception(
TE_TR(
"The layer don't have a geometry or raster property!"));
225 const std::string& geomPropertyName,
231 assert(!geomPropertyName.empty());
237 std::size_t nRules = style->
getRules().size();
239 for(std::size_t i = 0; i < nRules; ++i)
251 std::auto_ptr<te::da::DataSet> dataset(0);
275 throw Exception(
TE_TR(
"Could not convert the OGC Filter expression to TerraLib expression!"));
288 dataset = layer->
getData(restriction);
290 catch(std::exception& )
292 throw Exception((boost::format(
TE_TR(
"Could not retrieve the data set from the layer %1%.")) % layer->
getTitle()).str());
296 if(dataset.get() == 0)
297 throw Exception((boost::format(
TE_TR(
"Could not retrieve the data set from the layer %1%.")) % layer->
getTitle()).str());
299 if(dataset->moveNext() ==
false)
303 const std::vector<te::se::Symbolizer*>& symbolizers = rule->
getSymbolizers();
306 std::string message =
TE_TR(
"Drawing the layer");
307 message +=
" " + layer->
getTitle() +
". ";
308 message +=
TE_TR(
"Rule");
309 message +=
" " + boost::lexical_cast<std::string>(i + 1) +
" " +
TE_TR(
"of") +
" ";
310 message += boost::lexical_cast<std::string>(nRules) +
".";
319 if(symbolizers.empty())
322 std::auto_ptr<te::gm::Geometry> g(dataset->getGeometry(gpos));
330 dataset->moveFirst();
333 std::size_t nSymbolizers = symbolizers.size();
335 for(std::size_t j = 0; j < nSymbolizers; ++j)
344 if(j != nSymbolizers - 1)
345 drawDatSetGeometries(dataset.get(), gpos, canvas, layer->
getSRID(), srid, 0, &task);
347 drawDatSetGeometries(dataset.get(), gpos, canvas, layer->
getSRID(), srid, layer->
getChart(), &task);
350 dataset->moveFirst();
358 const std::string& geomPropertyName,
363 assert(!geomPropertyName.empty());
373 assert(!propertyName.empty());
384 std::size_t nGroupItems = items.size();
387 std::string message =
TE_TR(
"Drawing the grouping of layer");
388 message +=
" " + layer->
getTitle() +
".";
393 for(std::size_t i = 0; i < nGroupItems; ++i)
444 std::auto_ptr<te::da::DataSet> dataset(0);
447 dataset = layer->
getData(restriction);
449 catch(std::exception& )
454 if(dataset.get() == 0)
455 throw Exception((boost::format(
TE_TR(
"Could not retrieve the data set from the layer %1%.")) % layer->
getTitle()).str());
457 if(dataset->moveNext() ==
false)
461 const std::vector<te::se::Symbolizer*>& symbolizers = item->
getSymbolizers();
462 std::size_t nSymbolizers = symbolizers.size();
467 for(std::size_t j = 0; j < nSymbolizers; ++j)
476 if(j != nSymbolizers - 1)
477 drawDatSetGeometries(dataset.get(), gpos, canvas, layer->
getSRID(), srid, 0, &task);
479 drawDatSetGeometries(dataset.get(), gpos, canvas, layer->
getSRID(), srid, layer->
getChart(), &task);
482 dataset->moveFirst();
495 const std::string& geomPropertyName,
500 assert(!geomPropertyName.empty());
510 assert(!propertyName.empty());
516 const std::size_t& precision = grouping->
getPrecision();
521 std::size_t nGroupItems = items.size();
524 std::map<std::string, std::vector<te::se::Symbolizer*> > uniqueGroupsMap;
527 std::map<std::pair< double, double>, std::vector<te::se::Symbolizer*> > othersGroupsMap;
529 for(std::size_t i = 0; i < nGroupItems; ++i)
543 std::pair<double, double> range(lowerLimit, upperLimit);
550 std::string message =
TE_TR(
"Drawing the grouping of layer");
551 message +=
" " + layer->
getTitle() +
".";
556 std::auto_ptr<te::da::DataSet> dataset(0);
561 catch(std::exception& )
566 if(dataset.get() == 0)
567 throw Exception((boost::format(
TE_TR(
"Could not retrieve the data set from the layer %1%.")) % layer->
getTitle()).str());
569 if(dataset->moveNext() ==
false)
576 std::auto_ptr<te::map::LayerSchema> dt(layer->
getSchema());
580 bool needRemap =
false;
589 std::vector<te::se::Symbolizer*> symbolizers;
594 if(dataset->isNull(propertyPos))
597 value = dataset->getAsString(propertyPos, precision);
601 std::map<std::string, std::vector<te::se::Symbolizer*> >::const_iterator it = uniqueGroupsMap.find(value);
602 if(it == uniqueGroupsMap.end())
604 symbolizers = it->second;
608 double dvalue = atof(value.c_str());
609 std::map<std::pair< double, double>, std::vector<te::se::Symbolizer*> >::const_iterator it;
610 for(it = othersGroupsMap.begin(); it != othersGroupsMap.end(); ++it)
612 if(dvalue >= it->first.first && dvalue <= it->first.second)
616 if(it == othersGroupsMap.end())
631 symbolizers = it->second;
634 if(symbolizers.empty())
638 std::auto_ptr<te::gm::Geometry> geom;
641 geom = dataset->getGeometry(gpos);
645 catch(std::exception& )
651 std::size_t nSymbolizers = symbolizers.size();
653 for(std::size_t j = 0; j < nSymbolizers; ++j)
664 geom->setSRID(layer->
getSRID());
665 geom->transform(srid);
668 canvas->
draw(geom.get());
670 if(chart && j == nSymbolizers - 1)
671 buildChart(chart, dataset.get(), geom.get());
674 }
while(dataset->moveNext());
677 for(std::size_t i = 0; i < m_chartCoordinates.size(); ++i)
679 canvas->
drawImage(static_cast<int>(m_chartCoordinates[i].x),
680 static_cast<int>(m_chartCoordinates[i].y),
690 int fromSRID,
int toSRID,
697 bool needRemap =
false;
712 std::auto_ptr<te::gm::Geometry> geom(0);
719 catch(std::exception& )
727 geom->setSRID(fromSRID);
728 geom->transform(toSRID);
731 canvas->
draw(geom.get());
734 buildChart(chart, dataset, geom.get());
739 for(std::size_t i = 0; i < m_chartCoordinates.size(); ++i)
741 canvas->
drawImage(static_cast<int>(m_chartCoordinates[i].x),
742 static_cast<int>(m_chartCoordinates[i].y),
757 std::auto_ptr<te::gm::Coord2D> worldCoord;
781 if(worldCoord.get() == 0)
788 double dx = 0.0;
double dy = 0.0;
789 m_transformer.world2Device(worldCoord->x, worldCoord->y, dx, dy);
800 std::vector<std::size_t> report;
801 m_rtree.search(chartEnvelope, report);
807 m_rtree.insert(chartEnvelope, ++m_index);
814 std::size_t width = 0;
816 m_chartImages.push_back(rgba);
822 m_chartCoordinates.clear();
823 m_chartImages.clear();
TEDATAACCESSEXPORT te::rst::RasterProperty * GetFirstRasterProperty(const DataSetType *dt)
MultiPolygon is a MultiSurface whose elements are Polygons.
~AbstractLayerRenderer()
Destructor.
Utility functions for the data access module.
bool intersects(const Envelope &rhs) const
It returns true if the envelopes "spatially intersects".
It models the inequality operator less than or equal to (<=).
The Style defines the styling that is to be applied to a geographic dataset (vector geometries or cov...
Spatial intersects operator.
This is the base class for layers.
virtual const te::gm::Envelope & getExtent() const
It returns the Layer extent (or minimum bounding box).
int getPropertyType() const
It gets the property type whose values will be grouped.
TESEEXPORT Symbolizer * CreateSymbolizer(const te::gm::GeomType &geomType)
Try creates an appropriate symbolizer based on given geometry type.
const std::string & getValue() const
It gets the value of the legend item.
virtual const std::string & getTitle() const
It returns the layer title.
A class that models the name of any property of an object.
const size_t getPrecision() const
It gets the precision used for the property values.
A Symbolizer describes how a feature is to appear on a map.
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...
This is the base class for Layers.
std::string getPropertyName() const
It gets the property name whose values will be grouped.
TESEEXPORT Style * CreateCoverageStyle(const std::vector< te::rst::BandProperty * > &properties)
Try creates an appropriate coverage style based on given band properties.
This class can be used to inform the progress of a task.
TEDATAACCESSEXPORT std::size_t GetPropertyPos(const DataSet *dataset, const std::string &name)
This is a singleton for managing chart renderer instance available in the system. ...
double m_urx
Upper right corner x-coordinate.
te::da::Expression * getExpression(const te::fe::Filter *f)
It converts the OGC Filter Expression to a TerraLib Expression.
It models the inequality operator greater than or equal to (>=).
virtual int getWidth() const =0
It returns the canvas width.
An utility struct for representing 2D coordinates.
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.
const te::fe::Filter * getFilter() const
#define TE_TR(message)
It marks a string in order to get translated.
void push_back(Symbolizer *s)
It renders the objects associated to an abstract layer. i.e. a generic renderer.
bool isActive() const
Verify if the task is active.
Boolean logic operator: AND.
This is an abstract class that models a query expression.
virtual te::map::Chart * getChart() const
It returns the Chart associated to the Layer.
Expression * clone() const
It creates a new copy of this 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.
TESEEXPORT Style * CreateFeatureTypeStyle(const te::gm::GeomType &geomType)
Try creates an appropriate feature type style based on given geometry type.
Rule * getRule(std::size_t i) const
const std::vector< Rule * > & getRules() const
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
This class contains the parameters needed for grouping the values of a Property.
Coord2D getCenter() const
It returns the rectangle's center coordinate.
void Free(std::vector< T * > *v)
This function can be applied to a pointer to a vector of pointers.
double m_llx
Lower left corner x-coordinate.
This class represents the informations needed to build map charts.
static T & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
A GroupingItem contains information about a grouping item associated to a layer.
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.
void buildChart(Chart *chart, te::da::DataSet *dataset, te::gm::Geometry *geom)
virtual te::se::Style * getStyle() const
It returns the Style associated to the layer.
std::size_t getHeight() const
bool isVisible() const
It gets the chart visibility.
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
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.
A visitor that converts a OGC Filter Expression to TerraLib Expression.
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
virtual void drawImage(char *src, std::size_t size, ImageType t)=0
It draws the src image over the canvas.
A filter is any valid predicate expression.
A class that models a literal for double values.
This class represents the informations needed to build map charts.
GeomType getGeomTypeId() const
It returns the geometry subclass type identifier.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
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
double m_lly
Lower left corner y-coordinate.
A dataset is the unit of information manipulated by the data access module of TerraLib.
A canvas is an abstraction of a drawing area.
bool isVisible() const
It gets the grouping visibility.
const std::vector< te::map::GroupingItem * > & getGroupingItems() const
It gets the vector of grouping items.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
GroupingType
The grouping type associated to the layer.
A Rule is used to attach property/scale conditions to and group the individual symbols used for rende...
const std::string & getUpperLimit() const
It gets the upper limit value of the legend item.
virtual te::map::Grouping * getGrouping() const
It returns the Grouping associated to the Layer.
double m_ury
Upper right corner y-coordinate.
It models the comparison operator.
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. ...
Coord2D * getCentroidCoord() const
It returns the mathematical centroid for this surface as a coordinate.
virtual void setStyle(te::se::Style *style)
It sets the Style associated to the layer.
A helper class for 32-bit RGBA (Red-Green-Blue-Alpha channel) color.
const GroupingType getType() const
It gets the grouping type.
bool getAvoidConflicts() const
A class that models a literal for Envelope values.
virtual const std::string & getGeomPropertyName() const
virtual int getSRID() const
It returns the Spatial Reference System ID associated to the Layer.
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.
This class contains the parameters needed for grouping the values of a Property.
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.
std::vector< te::rst::BandProperty * > & getBandProperties()
Returns a reference to the list of bands definitions.
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.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
const std::vector< te::se::Symbolizer * > & getSymbolizers() const
It gets the symbolizer of the legend item.
void transform(int oldsrid, int newsrid)
It will transform the coordinates of the Envelope from the old SRS to the new one.
virtual void draw(const te::gm::Geometry *geom)=0
It draws the geometry on canvas.
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
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)
Coord2D * getCentroidCoord() const
std::size_t getWidth() const
virtual std::auto_ptr< LayerSchema > getSchema() const =0
It returns the layer schema.
This class models a string Literal value.
static const std::string sm_nanStr
Not a number string value.
const std::string & getName() const
It returns the property name.