27 #include "../common/progress/TaskProgress.h"
28 #include "../dataaccess.h"
29 #include "../datatype/SimpleProperty.h"
30 #include "../datatype/StringProperty.h"
31 #include "../geometry/Envelope.h"
32 #include "../geometry/GeometryProperty.h"
33 #include "../geometry/Point.h"
34 #include "../geometry/Polygon.h"
35 #include "../maptools/DataSetLayer.h"
36 #include "../memory/DataSet.h"
37 #include "../memory/DataSetItem.h"
38 #include "../raster.h"
54 const std::string& name,
62 int maxcols = (int)ceil((env.
m_urx-env.
m_llx)/resX),
63 maxrows = (
int)ceil((env.
m_ury-env.
m_lly)/resY);
66 std::auto_ptr<te::da::DataSet> refDs;
69 refDs = layerBase->getData();
73 std::auto_ptr<te::da::DataSetType> outputDataSetType(createCellularDataSetType(name, srid, type));
75 std::auto_ptr<te::sam::rtree::Index<size_t, 8> > rtree;
77 rtree.reset(getRtree(layerBase));
83 std::auto_ptr<te::da::DataSet> outputDataSet(
new te::mem::DataSet(outputDataSetType.get()));
85 std::auto_ptr<te::mem::DataSet> ds(dynamic_cast<te::mem::DataSet*>(outputDataSet.release()));
88 for(
int lin = 0; lin < maxrows; ++lin)
90 y = env.
m_lly+(lin*resY);
91 for(
int col = 0; col < maxcols; ++col)
93 x = env.
m_llx+(col*resX);
97 std::auto_ptr<te::gm::Geometry> geom;
98 if(type == CELLSPACE_POLYGONS)
102 else if(type == CELLSPACE_POINTS)
111 std::vector<size_t> report;
112 rtree->search(*geom->getMBR(), report);
118 for(std::size_t i = 0; i < report.size(); ++i)
120 refDs->move(report[i]);
122 std::auto_ptr<te::gm::Geometry> g = refDs->getGeometry(geomPos);
125 if(geom->intersects(g.get()))
127 addCell(ds.get(), col, lin, geom.release());
135 addCell(ds.get(), col, lin, geom.release());
148 source->setConnectionInfo(outputSource->getConnInfo());
151 std::map<std::string, std::string> options;
153 source->createDataSet(outputDataSetType.get(), options);
156 ds->moveBeforeFirst();
157 source->add(outputDataSetType->getName(),ds.get(), options);
163 sprintf(celId,
"C%02dL%02d",col,row);
177 std::auto_ptr<te::da::DataSet> ds = layerBase->getData();
181 ds->moveBeforeFirst();
185 while(ds->moveNext())
187 std::auto_ptr<te::gm::Geometry> geom = ds->getGeometry(geomPos);
189 rtree->
insert(*geom->getMBR(), count);
207 if(type == CELLSPACE_POLYGONS)
209 else if(type == CELLSPACE_POINTS)
217 std::string pkName = name +
"_pk_id";
219 std::vector<te::dt::Property*> pkProp;
220 pkProp.push_back(idProp);
void addCell(te::mem::DataSet *ds, int col, int row, te::gm::Geometry *geom)
Add a cell in the memory dataset.
CellularSpacesOperations()
void setGeometry(std::size_t i, te::gm::Geometry *value)
It sets the value of the i-th property.
An atomic property like an integer or double.
~CellularSpacesOperations()
A class that represents an R-tree.
A class that models the description of a dataset.
void useTimer(bool flag)
Used to define if task use progress timer information.
void setSize(std::size_t s)
It sets the maximum number of characters for a varying string, or the number of characters for a fixe...
This class can be used to inform the progress of a task.
double m_urx
Upper right corner x-coordinate.
#define TE_TR(message)
It marks a string in order to get translated.
It models a property definition.
bool isActive() const
Verify if the task is active.
void add(DataSetItem *item)
It adds a new item to the dataset and takes its ownership.
void setTotalSteps(int value)
Set the task total stepes.
te::da::DataSetType * createCellularDataSetType(const std::string &name, int srid, CellSpaceType type)
Create the DataSetType of the cellular space.
void setInt32(std::size_t i, boost::int32_t value)
It sets the value of the i-th property.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
double m_llx
Lower left corner x-coordinate.
TEDATAACCESSEXPORT std::size_t GetFirstSpatialPropertyPos(const te::da::DataSet *dataset)
It returns the first dataset spatial property or NULL if none is found.
A point with x and y coordinate values.
An Envelope defines a 2D rectangular region.
static std::auto_ptr< DataSource > make(const std::string &dsType)
void setProperties(const std::vector< te::dt::Property * > &properties)
It sets the properties that form the primary key.
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
te::sam::rtree::Index< size_t, 8 > * getRtree(te::map::AbstractLayerPtr layerBase)
Get a RTree with the geometries envelopes of layer.
The type for string types: FIXED_STRING, VAR_STRING or STRING.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
double m_lly
Lower left corner y-coordinate.
void add(Constraint *c)
It adds a new constraint.
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
void insert(const te::gm::Envelope &mbr, const DATATYPE &data)
It inserts an item into the tree.
double m_ury
Upper right corner y-coordinate.
It describes a primary key (pk) constraint.
void setString(std::size_t i, const std::string &value)
It sets the value of the i-th property.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
void createCellSpace(te::da::DataSourceInfoPtr outputSource, const std::string &name, const double &resX, const double &resY, const te::gm::Envelope &env, const int srid, CellSpaceType type, te::map::AbstractLayerPtr layerBase)
It creates a Cellular Space.
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr