All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Intersection.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008-2013 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/vp/core/IntersectionDialog.cpp
22 
23  \brief Group of functions to intersection operation
24 */
25 
26 // Terralib
27 #include "../common/Exception.h"
28 #include "../common/progress/TaskProgress.h"
29 #include "../common/Translator.h"
30 #include "../dataaccess/dataset/DataSet.h"
31 #include "../dataaccess/dataset/DataSetAdapter.h"
32 #include "../dataaccess/dataset/DataSetType.h"
33 #include "../dataaccess/datasource/DataSourceCapabilities.h"
34 #include "../dataaccess/datasource/DataSourceInfo.h"
35 #include "../dataaccess/datasource/DataSourceManager.h"
36 #include "../dataaccess/dataset/DataSetTypeConverter.h"
37 #include "../dataaccess/query_h.h"
38 #include "../dataaccess/utils/Utils.h"
39 #include "../datatype/Property.h"
40 #include "../geometry/Geometry.h"
41 #include "../geometry/GeometryCollection.h"
42 #include "../geometry/GeometryProperty.h"
43 #include "../geometry/MultiLineString.h"
44 #include "../geometry/MultiPoint.h"
45 #include "../geometry/MultiPolygon.h"
46 #include "../maptools/AbstractLayer.h"
47 #include "../memory/DataSet.h"
48 #include "../memory/DataSetItem.h"
49 #include "../qt/widgets/layer/utils/DataSet2Layer.h"
50 #include "Config.h"
51 #include "Exception.h"
52 #include "Intersection.h"
53 #include "Utils.h"
54 
55 // Boost
56 #include <boost/lexical_cast.hpp>
57 #include <boost/uuid/random_generator.hpp>
58 #include <boost/uuid/uuid_io.hpp>
59 
60 #include <iostream>
61 #include <memory>
62 
63 
64 // -- auxiliary function
66 {
69  std::vector<te::dt::Property*> props;
70 };
71 
73 
74 bool IntersectionQuery(const std::string& inFirstDataSetName,
75  const std::string& inSecondDataSetName,
76  te::da::DataSource* inFirstDataSource,
77  const std::string& outDataSetName,
78  te::da::DataSetType*& outDataSetType,
79  te::da::DataSet*& outDataSet,
80  const bool& copyInputColumns,
81  size_t outputSRID);
82 
83 bool IntersectionMemory(const std::string& inFirstDataSetName,
84  te::da::DataSource* inFirstDataSource,
85  const std::string& inSecondDataSetName,
86  te::da::DataSource* inSecondDataSource,
87  const std::string& outDataSetName,
88  te::da::DataSetType*& outDataSetType,
89  te::da::DataSet*& outDataSet,
90  const bool& copyInputColumns,
91  size_t outputSRID);
92 
93 te::da::DataSetType* CreateDataSetType(std::string newName,
94  te::da::DataSetType* firstDt,
95  std::vector<te::dt::Property*> firstProps,
96  te::da::DataSetType* secondDt,
97  std::vector<te::dt::Property*> secondProps);
98 
100 
101 std::pair<te::da::DataSetType*, te::da::DataSet*> PairwiseIntersection(std::string newName,
102  IntersectionMember firstMember,
103  IntersectionMember secondMember,
104  std::size_t outputSRID = 0);
105 
106 std::vector<te::dt::Property*> GetTabularProperties(te::da::DataSetType* dsType);
107 
109 // ---
110 
111 bool te::vp::Intersection(const std::string& inFirstDataSetName,
112  te::da::DataSource* inFirstDataSource,
113  const std::string& inSecondDataSetName,
114  te::da::DataSource* inSecondDataSource,
115  const bool& copyInputColumns,
116  const std::string& outDataSetName,
117  te::da::DataSource* outDataSource)
118 {
119  assert(inFirstDataSource);
120  assert(inSecondDataSource);
121  assert(outDataSource);
122 
123  std::pair<te::da::DataSetType*, te::da::DataSet*> resultPair;
124  std::size_t outputSRID = 0;
125 
126  te::da::DataSetType* outDataSetType = 0;
127  te::da::DataSet* outDataSet = 0;
128 
129  const te::da::DataSourceCapabilities firstDSCapabilities = inFirstDataSource->getCapabilities();
130  const te::da::DataSourceCapabilities secondDSCapabilities = inSecondDataSource->getCapabilities();
131 
132  bool res;
133  if( firstDSCapabilities.getQueryCapabilities().supportsSpatialSQLDialect() &&
134  secondDSCapabilities.getQueryCapabilities().supportsSpatialSQLDialect() &&
135  (inFirstDataSource->getId() == inSecondDataSource->getId()))
136  {
137  res = IntersectionQuery(inFirstDataSetName,
138  inSecondDataSetName,
139  inFirstDataSource,
140  outDataSetName,
141  outDataSetType,
142  outDataSet,
143  copyInputColumns,
144  outputSRID);
145  }
146  else
147  {
148  res = IntersectionMemory(inFirstDataSetName,
149  inFirstDataSource,
150  inSecondDataSetName,
151  inSecondDataSource,
152  outDataSetName,
153  outDataSetType,
154  outDataSet,
155  copyInputColumns,
156  outputSRID);
157  }
158 
159  if(!res)
160  return false;
161 
162  // do any adaptation necessary to persist the output dataset
163  te::da::DataSetTypeConverter* converter = new te::da::DataSetTypeConverter(outDataSetType, outDataSource->getCapabilities());
164  te::da::DataSetType* dsTypeResult = converter->getResult();
165  std::auto_ptr<te::da::DataSetAdapter> dsAdapter(te::da::CreateAdapter(outDataSet, converter));
166 
167  std::map<std::string, std::string> options;
168  // create the dataset
169  outDataSource->createDataSet(dsTypeResult, options);
170 
171  // copy from memory to output datasource
172  outDataSet->moveBeforeFirst();
173  outDataSource->add(dsTypeResult->getName(),outDataSet, options);
174 
175  return true;
176 }
177 
178 bool IntersectionQuery(const std::string& inFirstDataSetName,
179  const std::string& inSecondDataSetName,
180  te::da::DataSource* inFirstDataSource,
181  const std::string& outDataSetName,
182  te::da::DataSetType*& outDataSetType,
183  te::da::DataSet*& outDataSet,
184  const bool& copyInputColumns,
185  size_t outputSRID)
186 {
187  if(outputSRID == 0)
188  {
189  std::auto_ptr<te::da::DataSetType> inDataSetType = inFirstDataSource->getDataSetType(inFirstDataSetName);
190  te::gm::GeometryProperty* geom = te::da::GetFirstGeomProperty(inDataSetType.get());
191 
192  outputSRID = geom->getSRID();
193  }
194 
195  te::da::Fields* fields = new te::da::Fields;
196  te::da::Select* select = new te::da::Select;
197 
198  std::auto_ptr<te::da::DataSetType> firstDSType(inFirstDataSource->getDataSetType(inFirstDataSetName));
199  std::auto_ptr<te::da::DataSetType> secondDSType(inFirstDataSource->getDataSetType(inSecondDataSetName));
200 
201  std::vector<te::dt::Property*> firstProps = GetTabularProperties(firstDSType.get());
202  std::vector<te::dt::Property*> secondProps;
203  if(copyInputColumns)
204  secondProps = GetTabularProperties(secondDSType.get());
205 
206  te::gm::GeometryProperty* firstGeom;
207  te::gm::GeometryProperty* secondGeom;
208 
209  firstGeom = te::da::GetFirstGeomProperty(firstDSType.get());
210  secondGeom = te::da::GetFirstGeomProperty(secondDSType.get());
211 
212  std::string firstTableName = te::vp::GetSimpleTableName(firstDSType->getTitle());
213  std::string secondTableName = te::vp::GetSimpleTableName(secondDSType->getTitle());
214 
215  for(std::size_t i = 0; i < firstProps.size(); ++i)
216  {
217  te::da::Field* f_field = new te::da::Field(firstTableName + "." + firstProps[i]->getName() + " ", firstTableName + "_" + firstProps[i]->getName());
218  fields->push_back(f_field);
219  }
220 
221  for(std::size_t i = 0; i < secondProps.size(); ++i)
222  {
223  te::da::Field* f_field = new te::da::Field(secondTableName + "." + secondProps[i]->getName() + " ", secondTableName + "_" + secondProps[i]->getName());
224  fields->push_back(f_field);
225  }
226 
227  te::da::Expression* e_intersection = new te::da::ST_Intersection( new te::da::PropertyName(firstDSType->getName() + "." + firstGeom->getName()),
228  new te::da::PropertyName(secondDSType->getName() + "." + secondGeom->getName()));
229  te::da::Field* f_intersection = new te::da::Field(*e_intersection, "geom");
230  fields->push_back(f_intersection);
231 
232  te::da::FromItem* firstFromItem = new te::da::DataSetName(firstDSType->getName());
233  te::da::FromItem* secondFromItem = new te::da::DataSetName(secondDSType->getName());
234  te::da::Expression* e_intersects = new te::da::ST_Intersects( new te::da::PropertyName(firstDSType->getName() + "." + firstGeom->getName()),
235  new te::da::PropertyName(secondDSType->getName() + "." + secondGeom->getName()));
236  te::da::JoinConditionOn* on = new te::da::JoinConditionOn(e_intersects);
237  te::da::Join* join = new te::da::Join(*firstFromItem, *secondFromItem, te::da::INNER_JOIN, *on);
238 
239  te::da::From* from = new te::da::From;
240  from->push_back(join);
241 
242  select->setFields(fields);
243  select->setFrom(from);
244 
245  std::auto_ptr<te::da::DataSet> dsQuery = inFirstDataSource->query(select);
246  dsQuery->moveBeforeFirst();
247 
248  outDataSetType = CreateDataSetType(outDataSetName, firstDSType.get(), firstProps, secondDSType.get(), secondProps);
249  outDataSet = UpdateGeometryType(outDataSetType, dsQuery.release());
250 
251  outDataSet->moveBeforeFirst();
252 
253  return true;
254 }
255 
256 bool IntersectionMemory(const std::string& inFirstDataSetName,
257  te::da::DataSource* inFirstDataSource,
258  const std::string& inSecondDataSetName,
259  te::da::DataSource* inSecondDataSource,
260  const std::string& outDataSetName,
261  te::da::DataSetType*& outDataSetType,
262  te::da::DataSet*& outDataSet,
263  const bool& copyInputColumns,
264  size_t outputSRID)
265 {
266  if(outputSRID == 0)
267  {
268  std::auto_ptr<te::da::DataSetType> inDataSetType = inFirstDataSource->getDataSetType(inFirstDataSetName);
269  te::gm::GeometryProperty* geom = te::da::GetFirstGeomProperty(inDataSetType.get());
270 
271  outputSRID = geom->getSRID();
272  }
273 
274  std::auto_ptr<te::da::DataSetType> firstDSType(inFirstDataSource->getDataSetType(inFirstDataSetName));
275  std::auto_ptr<te::da::DataSetType> secondDSType(inSecondDataSource->getDataSetType(inSecondDataSetName));
276 
277  std::vector<te::dt::Property*> firstProps = GetTabularProperties(firstDSType.get());
278 
279  IntersectionMember firstMember;
280  firstMember.dt = firstDSType.release();
281  firstMember.ds = inFirstDataSource->getDataSet(inFirstDataSetName).release();
282  firstMember.props = firstProps;
283 
284  std::vector<te::dt::Property*> secondProps = GetTabularProperties(secondDSType.get());
285 
286  IntersectionMember secondMember;
287  secondMember.dt = secondDSType.release();
288  secondMember.ds = inSecondDataSource->getDataSet(inSecondDataSetName).release();
289  if(copyInputColumns)
290  secondMember.props = secondProps;
291 
292  std::pair<te::da::DataSetType*, te::da::DataSet*> resultPair;
293  resultPair = PairwiseIntersection(outDataSetName, firstMember, secondMember, outputSRID);
294 
295  if(resultPair.second->size() < 1)
296  throw te::common::Exception(TR_VP("The Layers do not intersect!"));
297 
298  outDataSetType = resultPair.first;
299  outDataSet = resultPair.second;
300 
301  return true;
302 }
303 
305  te::da::DataSetType* firstDt,
306  std::vector<te::dt::Property*> firstProps,
307  te::da::DataSetType* secondDt,
308  std::vector<te::dt::Property*> secondProps)
309 {
310  te::da::DataSetType* outputDt = new te::da::DataSetType(newName);
311 
312 
313 
314  te::dt::SimpleProperty* pkProperty = new te::dt::SimpleProperty(newName + "_id", te::dt::INT32_TYPE);
315  pkProperty->setAutoNumber(true);
316  outputDt->add(pkProperty);
317 
318  te::da::PrimaryKey* pk = new te::da::PrimaryKey(newName + "_pk", outputDt);
319  pk->add(pkProperty);
320  outputDt->setPrimaryKey(pk);
321 
322  for(size_t i = 0; i < firstProps.size(); ++i)
323  {
324  te::dt::Property* prop = firstProps[i]->clone();
325  if(!firstDt->getTitle().empty())
326  prop->setName(te::vp::GetSimpleTableName(firstDt->getTitle()) + "_" + prop->getName());
327  outputDt->add(prop);
328  }
329 
330  for(size_t i = 0; i < secondProps.size(); ++i)
331  {
332  te::dt::Property* prop = secondProps[i]->clone();
333  prop->setName(te::vp::GetSimpleTableName(secondDt->getTitle()) + "_" + prop->getName());
334  outputDt->add(prop);
335  }
336 
337  te::gm::GeomType newType = te::vp::GeomOpResultType(te::da::GetFirstGeomProperty(firstDt)->getGeometryType(), te::da::GetFirstGeomProperty(secondDt)->getGeometryType());
338 
339  te::gm::GeometryProperty* newGeomProp = new te::gm::GeometryProperty("geom");
340  newGeomProp->setGeometryType(newType);
341  newGeomProp->setSRID(te::da::GetFirstGeomProperty(firstDt)->getSRID());
342 
343  outputDt->add(newGeomProp);
344 
345  return outputDt;
346 }
347 
349 {
351 
352  size_t secGeomPropPos = dt->getPropertyPosition(dt->findFirstPropertyOfType(te::dt::GEOMETRY_TYPE));
353 
354  size_t secondDsCount = 0;
355  while(ds->moveNext())
356  {
357  std::auto_ptr<te::gm::Geometry> g = ds->getGeometry(secGeomPropPos);
358 
359  rtree->insert(*g->getMBR(), secondDsCount);
360 
361  ++secondDsCount;
362  }
363 
364  return rtree;
365 }
366 
367 std::pair<te::da::DataSetType*, te::da::DataSet*> PairwiseIntersection(std::string newName,
368  IntersectionMember firstMember,
369  IntersectionMember secondMember,
370  std::size_t outputSRID)
371 {
372 
373  //Creating the RTree with the secound layer geometries
374  te::sam::rtree::Index<size_t, 8>* rtree = CreateRTree(secondMember.dt, secondMember.ds);
375 
376  firstMember.ds->moveBeforeFirst();
377 
378  std::auto_ptr<te::gm::GeometryProperty> fiGeomProp (te::da::GetFirstGeomProperty(firstMember.dt));
379  size_t fiGeomPropPos = firstMember.dt->getPropertyPosition(fiGeomProp.get());
380 
381  size_t secGeomPropPos = secondMember.dt->getPropertyPosition(te::da::GetFirstGeomProperty(secondMember.dt));
382 
383  // Create the DataSetType and DataSet
384  te::da::DataSetType* outputDt = CreateDataSetType(newName, firstMember.dt, firstMember.props, secondMember.dt, secondMember.props);
385  te::mem::DataSet* outputDs = new te::mem::DataSet(outputDt);
386 
387  std::pair<te::da::DataSetType*, te::da::DataSet*> resultPair;
388 
389  te::common::TaskProgress task("Processing intersection...");
390  task.setTotalSteps(firstMember.ds->size());
391  task.useTimer(true);
392 
393  std::size_t pk = 0;
394 
395  while(firstMember.ds->moveNext())
396  {
397  std::auto_ptr<te::gm::Geometry> currGeom = firstMember.ds->getGeometry(fiGeomPropPos);
398 
399  if(currGeom->getSRID() != outputSRID && outputSRID != 0)
400  currGeom->transform(outputSRID);
401 
402  std::vector<size_t> report;
403  rtree->search(*currGeom->getMBR(), report);
404 
405  for(size_t i = 0; i < report.size(); ++i)
406  {
407  secondMember.ds->move(report[i]);
408  std::auto_ptr<te::gm::Geometry> secGeom = secondMember.ds->getGeometry(secGeomPropPos);
409 
410  if(secGeom->getSRID() != outputSRID && outputSRID != 0)
411  secGeom->transform(outputSRID);
412 
413  if(!currGeom->intersects(secGeom.get()))
414  continue;
415 
416  te::mem::DataSetItem* item = new te::mem::DataSetItem(outputDs);
417  std::auto_ptr<te::gm::Geometry> resultGeom;
418 
419  if(currGeom->isValid() && secGeom->isValid())
420  resultGeom.reset(currGeom->intersection(secGeom.get()));
421 
422  if(resultGeom.get()!=0 && resultGeom->isValid())
423  {
425 
426  if(fiGeomProp->getGeometryType() == te::gm::MultiPolygonType)
427  {
428  if(resultGeom->getGeomTypeId() == te::gm::MultiPolygonType)
429  {
430  item->setGeometry("geom", resultGeom.release());
431  }
432  else if(resultGeom->getGeomTypeId() == te::gm::PolygonType)
433  {
434  te::gm::MultiPolygon* newGeom = new te::gm::MultiPolygon(0, te::gm::MultiPolygonType, resultGeom->getSRID());
435  newGeom->add(resultGeom.release());
436  item->setGeometry("geom", newGeom);
437  }
438  }
439  else if(fiGeomProp->getGeometryType() == te::gm::MultiLineStringType)
440  {
441  if(resultGeom->getGeomTypeId() == te::gm::MultiLineStringType)
442  {
443  item->setGeometry("geom", resultGeom.release());
444  }
445  else if(resultGeom->getGeomTypeId() == te::gm::LineStringType)
446  {
447  te::gm::MultiLineString* newGeom = new te::gm::MultiLineString(0, te::gm::MultiLineStringType, resultGeom->getSRID());
448  newGeom->add(resultGeom.release());
449  item->setGeometry("geom", newGeom);
450  }
451  }
452  else if(fiGeomProp->getGeometryType() == te::gm::MultiPointType)
453  {
454  if(resultGeom->getGeomTypeId() == te::gm::MultiPointType)
455  {
456  item->setGeometry("geom", resultGeom.release());
457  }
458  else if(resultGeom->getGeomTypeId() == te::gm::PointType)
459  {
460  te::gm::MultiPoint* newGeom = new te::gm::MultiPoint(0, te::gm::MultiPointType, resultGeom->getSRID());
461  newGeom->add(resultGeom.release());
462  item->setGeometry("geom", newGeom);
463  }
464  }
465  }
466  else
467  {
468  continue;
469  }
470 
471  for(size_t j = 0; j < firstMember.props.size(); ++j)
472  {
473  std::string name = firstMember.props[j]->getName();
474 
475  if(!firstMember.dt->getTitle().empty())
476  name = te::vp::GetSimpleTableName(firstMember.dt->getTitle()) + "_" + name;
477 
478  te::dt::AbstractData* ad = firstMember.ds->getValue(firstMember.props[j]->getName()).release();
479 
480  item->setValue(name, ad);
481  }
482 
483  for(size_t j = 0; j < secondMember.props.size(); ++j)
484  {
485  std::string name = secondMember.props[j]->getName();
486 
487  if (!secondMember.dt->getTitle().empty())
488  name = te::vp::GetSimpleTableName(secondMember.dt->getTitle()) + "_" + name;
489 
490  te::dt::AbstractData* ad = secondMember.ds->getValue(secondMember.props[j]->getName()).release();
491 
492  item->setValue(name, ad);
493  }
494 
495  item->setInt32(newName + "_id", pk);
496  ++pk;
497 
498  outputDs->moveNext();
499 
500  int aux = te::da::GetFirstSpatialPropertyPos(outputDs);
501 
502  if(!item->isNull(aux))
503  outputDs->add(item);
504  }
505 
506  if(task.isActive() == false)
507  {
508  delete outputDt;
509  delete outputDs;
510 
511  throw te::common::Exception(TR_VP("Operation canceled!"));
512  }
513 
514  task.pulse();
515  }
516 
517  outputDs->moveBeforeFirst();
518 
519  resultPair.first = outputDt;
520  resultPair.second = outputDs;
521  return resultPair;
522 }
523 
524 std::vector<te::dt::Property*> GetTabularProperties(te::da::DataSetType* dsType)
525 {
526  std::vector<te::dt::Property*> props;
527  te::dt::Property* prop;
528 
529  for(std::size_t i = 0; i < dsType->getProperties().size(); ++i)
530  {
531  prop = dsType->getProperty(i);
532 
533  if(prop->getType() != te::dt::GEOMETRY_TYPE && prop->getType() != te::dt::NUMERIC_TYPE)
534  {
535  props.push_back(prop);
536  }
537  }
538 
539  return props;
540 }
541 
543 {
544  te::mem::DataSet* dsMem = new te::mem::DataSet(dsType);
545 
546  std::size_t type = 0;
547  std::vector<te::dt::Property*> props = dsType->getProperties();
548 
549  std::size_t pk = 0;
550  while(ds->moveNext())
551  {
552  std::string propName;
553  te::mem::DataSetItem* dsItem = new te::mem::DataSetItem(dsMem);
554 
555  dsItem->setInt32(0, pk);
556 
557  for(std::size_t i = 1; i < props.size(); ++i)
558  {
559  type = props[i]->getType();
560  propName = props[i]->getName();
561 
562  if(type != te::dt::GEOMETRY_TYPE)
563  {
564  if (!ds->isNull(propName))
565  {
566  std::auto_ptr<te::dt::AbstractData> value = ds->getValue(propName);
567  dsItem->setValue(i, value.release());
568  }
569  }
570  else
571  {
572  std::auto_ptr<te::gm::Geometry> geom = ds->getGeometry(propName);
573  std::auto_ptr<te::gm::GeometryProperty> geomProp((te::gm::GeometryProperty*)props[i]->clone());
574 
575  if(geomProp->getGeometryType() == te::gm::MultiPolygonType)
576  {
577  if(geom->getGeomTypeId() == te::gm::MultiPolygonType)
578  {
579  dsItem->setGeometry(i, geom.release());
580  }
581  else if(geom->getGeomTypeId() == te::gm::PolygonType)
582  {
583  std::auto_ptr<te::gm::GeometryCollection> newGeom(new te::gm::GeometryCollection(0, te::gm::MultiPolygonType, geom->getSRID()));
584  newGeom->add(geom.release());
585  dsItem->setGeometry(i, newGeom.release());
586  }
587  }
588  else if(geomProp->getGeometryType() == te::gm::MultiLineStringType)
589  {
590  if(geom->getGeomTypeId() == te::gm::MultiLineStringType)
591  {
592  dsItem->setGeometry(i, geom.release());
593  }
594  else if(geom->getGeomTypeId() == te::gm::LineStringType)
595  {
596  std::auto_ptr<te::gm::GeometryCollection> newGeom(new te::gm::GeometryCollection(0, te::gm::MultiLineStringType, geom->getSRID()));
597  newGeom->add(geom.release());
598  dsItem->setGeometry(i, newGeom.release());
599  }
600  }
601  else if(geomProp->getGeometryType() == te::gm::MultiPointType)
602  {
603  if(geom->getGeomTypeId() == te::gm::MultiPointType)
604  {
605  dsItem->setGeometry(i, geom.release());
606  }
607  else if(geom->getGeomTypeId() == te::gm::PointType)
608  {
609  std::auto_ptr<te::gm::GeometryCollection> newGeom(new te::gm::GeometryCollection(0, te::gm::MultiPointType, geom->getSRID()));
610  newGeom->add(geom.release());
611  dsItem->setGeometry(i, newGeom.release());
612  }
613  }
614  }
615  }
616  ++pk;
617  dsMem->add(dsItem);
618  }
619  return dsMem;
620 }
MultiLineString is a MultiCurve whose elements are LineStrings.
void setGeometryType(GeomType t)
It sets the geometry subtype.
bool isActive() const
Verify if the task is active.
const std::string & getTitle() const
A human descriptive title for the DataSetType.
Definition: DataSetType.h:130
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
Definition: Exception.h:58
virtual void createDataSet(DataSetType *dt, const std::map< std::string, std::string > &options)
It creates the dataset schema definition in the target data source.
Definition: DataSource.cpp:424
void setGeometry(std::size_t i, te::gm::Geometry *value)
It sets the value of the i-th property.
A class that models the name of a dataset used in a From clause.
Definition: DataSetName.h:43
te::gm::GeomType GeomOpResultType(te::gm::GeomType firstGeom, te::gm::GeomType secondGeom)
Definition: Utils.cpp:134
TEDATAACCESSEXPORT std::size_t GetFirstSpatialPropertyPos(const te::da::DataSet *dataset)
It returns the first dataset spatial property or NULL if none is found.
Definition: Utils.cpp:409
An atomic property like an integer or double.
Property * getProperty(std::size_t i) const
It returns the i-th property.
An converter for DataSetType.
Implementation of a random-access dataset class for the TerraLib In-Memory Data Access driver...
Definition: DataSet.h:64
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
Definition: Utils.cpp:504
virtual const DataSourceCapabilities & getCapabilities() const =0
It returns the known capabilities of the data source.
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:65
int getSRID() const
It returns the spatial reference system identifier associated to this property.
te::da::DataSetType * dt
void setTotalSteps(int value)
Set the task total stepes.
bool supportsSpatialSQLDialect() const
Spatial intersects operator.
Definition: ST_Intersects.h:46
void add(DataSetItem *item)
It adds a new item to the dataset and takes its ownership.
Definition: DataSet.cpp:149
The Field class can be used to model an expression that takes part of the output items of a SELECT...
Definition: Field.h:50
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
Definition: From.h:37
const QueryCapabilities & getQueryCapabilities() const
An implementation of the DatasetItem class for the TerraLib In-Memory Data Access driver...
Definition: DataSetItem.h:56
const std::string & getName() const
It returns the property name.
Definition: Property.h:126
A class that represents an R-tree.
Definition: Index.h:56
void add(Constraint *c)
It adds a new constraint.
void setInt32(std::size_t i, boost::int32_t value)
It sets the value of the i-th property.
A class that models the name of any property of an object.
Definition: PropertyName.h:50
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
JoinConditionOn is a boolean expression and it specifies which items in a join are considered to matc...
te::da::DataSet * ds
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
Definition: Fields.h:37
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
void setValue(std::size_t i, te::dt::AbstractData *value)
It sets the value of the i-th property.
void setName(const std::string &name)
It sets the property name.
Definition: Property.h:136
TEVPEXPORT bool Intersection(const std::string &inFirstDataSetName, te::da::DataSource *inFirstDataSource, const std::string &inSecondDataSetName, te::da::DataSource *inSecondDataSource, const bool &copyInputColumns, const std::string &outDataSetName, te::da::DataSource *outDataSource)
void add(Geometry *g)
It adds the geometry into the collection.
bool IntersectionMemory(const std::string &inFirstDataSetName, te::da::DataSource *inFirstDataSource, const std::string &inSecondDataSetName, te::da::DataSource *inSecondDataSource, const std::string &outDataSetName, te::da::DataSetType *&outDataSetType, te::da::DataSet *&outDataSet, const bool &copyInputColumns, size_t outputSRID)
void setPrimaryKey(PrimaryKey *pk)
It sets the primary key constraint.
GeomType getGeometryType() const
It returns the geometry subtype allowed for the property.
Configuration flags for the Terrralib Vector Processing module.
MultiPolygon is a MultiSurface whose elements are Polygons.
Definition: MultiPolygon.h:50
An abstract class that models a source of data in a query.
Definition: FromItem.h:50
Utility functions for the data access module.
void setFields(Fields *f)
It sets the list of output expressions used to form the result set.
Definition: Select.cpp:927
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
void setAutoNumber(bool a)
It tells if the property is an autonumber or not.
std::vector< te::dt::Property * > GetTabularProperties(te::da::DataSetType *dsType)
const std::vector< Property * > & getProperties() const
It returns the list of properties describing the CompositeProperty.
std::size_t getPropertyPosition(const std::string &name) const
It returns the property position based on its name.
virtual std::auto_ptr< te::dt::AbstractData > getValue(std::size_t i) const
Method for retrieving any other type of data value stored in the data source.
Definition: DataSet.cpp:151
GeomType
Each enumerated type is compatible with a Well-known Binary (WKB) type code.
Definition: Enums.h:41
Spatial intersection operator.
Property * findFirstPropertyOfType(const int t) const
returns the first property of the given data type. Caller doesn&#39;t take ownership of the returned poin...
virtual std::auto_ptr< DataSet > query(const Select &q, te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It executes a query that may return some data using a generic query. This method always returns a dis...
Definition: DataSource.cpp:99
virtual bool moveBeforeFirst()=0
It moves the internal pointer to a position before the first item in the collection.
virtual void add(const std::string &datasetName, DataSet *d, const std::map< std::string, std::string > &options, std::size_t limit=0)
It adds data items to the dataset in the data source.
Definition: DataSource.cpp:450
std::string GetSimpleTableName(std::string fullName)
Definition: Utils.cpp:124
A base class for values that can be retrieved from the data access module.
Definition: AbstractData.h:57
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Definition: DataSource.h:116
bool isNull(std::size_t i) const
It is a collection of other geometric objects.
A class that models the description of a dataset.
Definition: DataSetType.h:72
DataSetRTree CreateRTree(te::da::DataSetType *dt, te::da::DataSet *ds)
bool moveNext()
It moves the internal pointer to the next item of the collection.
Definition: DataSet.cpp:284
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
Definition: PrimaryKey.h:123
It models a property definition.
Definition: Property.h:59
This is an abstract class that models a query expression.
Definition: Expression.h:47
bool moveBeforeFirst()
It moves the internal pointer to a position before the first item in the collection.
Definition: DataSet.cpp:296
std::pair< te::da::DataSetType *, te::da::DataSet * > PairwiseIntersection(std::string newName, IntersectionMember firstMember, IntersectionMember secondMember, std::size_t outputSRID=0)
void useTimer(bool flag)
Used to define if task use progress timer information.
te::da::DataSetType * CreateDataSetType(std::string newName, te::da::DataSetType *firstDt, std::vector< te::dt::Property * > firstProps, te::da::DataSetType *secondDt, std::vector< te::dt::Property * > secondProps)
std::vector< te::dt::Property * > props
MultiPoint is a GeometryCollection whose elements are restricted to points.
Definition: MultiPoint.h:50
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
virtual std::auto_ptr< DataSet > getDataSet(const std::string &name, te::common::TraverseType travType=te::common::FORWARDONLY, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It gets the dataset identified by the given name. This method always returns a disconnected dataset...
Definition: DataSource.cpp:60
virtual std::size_t size() const =0
It returns the collection size, if it is known.
const std::string & getId() const
An identification value for the data source.
Definition: DataSource.cpp:50
te::sam::rtree::Index< size_t, 8 > * DataSetRTree
int search(const te::gm::Envelope &mbr, std::vector< DATATYPE > &report) const
Range search query.
Definition: Index.h:326
int getType() const
It returns the property data type.
Definition: Property.h:143
void insert(const te::gm::Envelope &mbr, const DATATYPE &data)
It inserts an item into the tree.
Definition: Index.h:313
virtual std::auto_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
A Join clause combines two FromItems.
Definition: Join.h:50
bool IntersectionQuery(const std::string &inFirstDataSetName, const std::string &inSecondDataSetName, te::da::DataSource *inFirstDataSource, const std::string &outDataSetName, te::da::DataSetType *&outDataSetType, te::da::DataSet *&outDataSet, const bool &copyInputColumns, size_t outputSRID)
Geometric property.
virtual Property * clone() const =0
It returns a clone of the object.
virtual bool move(std::size_t i)=0
It moves the dataset internal pointer to a given position.
#define TR_VP(message)
It marks a string in order to get translated. This is a special mark used in the Terrralib Vector Pro...
Definition: Config.h:58
void setFrom(From *f)
It sets the list of source information.
Definition: Select.cpp:937
te::da::DataSet * UpdateGeometryType(te::da::DataSetType *dsType, te::da::DataSet *ds)
A dataset is the unit of information manipulated by the data access module of TerraLib.
Definition: DataSet.h:111
TEDATAACCESSEXPORT DataSetAdapter * CreateAdapter(DataSet *ds, DataSetTypeConverter *converter, bool isOwner=false)
Definition: Utils.cpp:591
virtual std::auto_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
Definition: DataSource.cpp:155