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"
53 const std::string& name,
62 int srid = layerBase->getSRID();
66 maxcols = (int)ceil((env.
m_urx-env.
m_llx)/resX);
67 maxrows = (int)ceil((env.
m_ury-env.
m_lly)/resY);
69 std::auto_ptr<te::da::DataSet> refDs;
73 refDs = layerBase->getData();
76 std::auto_ptr<te::da::DataSetType> outputDataSetType(createCellularDataSetType(name, srid, type));
78 std::auto_ptr<te::sam::rtree::Index<size_t, 8> > rtree;
82 rtree.reset(getRtree(layerBase));
89 std::auto_ptr<te::da::DataSet> outputDataSet(
new te::mem::DataSet(outputDataSetType.get()));
91 std::auto_ptr<te::mem::DataSet> ds(dynamic_cast<te::mem::DataSet*>(outputDataSet.release()));
94 for(
int lin = 0; lin < maxrows; ++lin)
97 y = env.
m_lly+(lin*resY);
98 for(
int col = 0; col < maxcols; ++col)
100 x = env.
m_llx+(col*resX);
104 std::auto_ptr<te::gm::Geometry> geom;
106 if(type == CELLSPACE_POLYGONS)
110 else if(type == CELLSPACE_POINTS)
119 std::vector<size_t> report;
120 rtree->search(*geom->getMBR(), report);
126 for(std::size_t i = 0; i < report.size(); ++i)
128 refDs->move(report[i]);
130 std::auto_ptr<te::gm::Geometry> g = refDs->getGeometry(geomPos);
133 if(geom->intersects(g.get()))
135 addCell(ds.get(), col, lin, geom.release());
143 addCell(ds.get(), col, lin, geom.release());
152 source->setConnectionInfo(outputSource->getConnInfo());
155 std::map<std::string, std::string> options;
157 source->createDataSet(outputDataSetType.get(), options);
160 ds->moveBeforeFirst();
161 source->add(outputDataSetType->getName(),ds.get(), options);
165 const std::string& name,
174 auxLayer->setSRID(srid);
175 auxLayer->setExtent(env);
177 createCellSpace(outputSource, name, auxLayer, resX, resY,
false, type);
183 sprintf(celId,
"C%02dL%02d",col,row);
197 std::auto_ptr<te::da::DataSet> ds = layerBase->getData();
201 ds->moveBeforeFirst();
205 while(ds->moveNext())
207 std::auto_ptr<te::gm::Geometry> geom = ds->getGeometry(geomPos);
209 rtree->
insert(*geom->getMBR(), count);
226 if(type == CELLSPACE_POLYGONS)
228 else if(type == CELLSPACE_POINTS)
236 std::string pkName = name +
"_pk_id";
238 std::vector<te::dt::Property*> pkProp;
239 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.
This class can be used to inform the progress of a task.
double m_urx
Upper right corner x-coordinate.
It models a property definition.
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.
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.
A layer with reference to a dataset.
void setString(std::size_t i, const std::string &value)
It sets the value of the i-th property.
boost::intrusive_ptr< AbstractLayer > AbstractLayerPtr
TEGEOMEXPORT Geometry * GetGeomFromEnvelope(const Envelope *const e, int srid)
It creates a Geometry (a polygon) from the given envelope.
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
void createCellSpace(te::da::DataSourceInfoPtr outputSource, const std::string &name, te::map::AbstractLayerPtr layerBase, double resX, double resY, bool useMask, CellSpaceType type=CELLSPACE_POLYGONS)
It create a Cellular Space.