src/terralib/dataaccess/utils/Utils.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 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/dataaccess/utils/Utils.cpp
22 
23  \brief Utility functions for the data access module.
24 */
25 
26 // TerraLib
27 #include "../../common/StringUtils.h"
28 #include "../../core/translator/Translator.h"
29 #include "../../core/uri/URI.h"
30 #include "../../geometry/Envelope.h"
31 #include "../../geometry/GeometryProperty.h"
32 #include "../../raster/RasterProperty.h"
33 #include "../dataset/DataSet.h"
34 #include "../dataset/DataSetAdapter.h"
35 #include "../dataset/DataSetType.h"
36 #include "../dataset/DataSetTypeConverter.h"
37 #include "../dataset/ObjectId.h"
38 #include "../dataset/ObjectIdSet.h"
39 #include "../dataset/PrimaryKey.h"
40 #include "../dataset/UniqueKey.h"
41 #include "../datasource/DataSourceCapabilities.h"
42 #include "../datasource/DataSourceInfoManager.h"
43 #include "../datasource/DataSourceManager.h"
44 #include "../query/DataSetName.h"
45 #include "../query/Field.h"
46 #include "../query/Fields.h"
47 #include "../query/LiteralEnvelope.h"
48 #include "../query/LiteralGeom.h"
49 #include "../query/PropertyName.h"
50 #include "../query/ST_Contains.h"
51 #include "../query/ST_Crosses.h"
52 #include "../query/ST_Disjoint.h"
53 #include "../query/ST_Equals.h"
54 #include "../query/ST_Intersects.h"
55 #include "../query/ST_Overlaps.h"
56 #include "../query/ST_Touches.h"
57 #include "../query/ST_Within.h"
58 #include "../query/Where.h"
59 #include "../Enums.h"
60 #include "../Exception.h"
61 #include "Utils.h"
62 
63 // STL
64 #include <cassert>
65 #include <algorithm>
66 
67 //BOOST
68 #include <boost/algorithm/string.hpp>
69 #include <boost/math/special_functions/round.hpp>
70 #include <boost/lexical_cast.hpp>
71 
72 void te::da::LoadFull(te::da::DataSetType* dataset, const std::string& datasourceId)
73 {
74  assert(dataset);
75  assert(!datasourceId.empty());
76 
77  //DataSourcePtr datasource(te::da::DataSourceManager::getInstance().get(datasourceId));
78  DataSourcePtr datasource(te::da::DataSourceManager::getInstance().find(datasourceId));
79 
80  if(datasource.get() == nullptr)
81  return;
82 
83  if(dataset->size() == 0)
84  {
85  boost::ptr_vector<te::dt::Property> properties = datasource->getProperties(dataset->getName());
86 
87  dataset->add(properties);
88  }
89 
90  //datasource->getCheckConstraints(dataset);
91 
92  //cloader->getIndexes(dataset);
93 
94  //cloader->getUniqueKeys(dataset);
95 
96  //cloader->getPrimaryKey(dataset);
97 }
98 
99 //void te::da::LoadFull(te::da::DataSetType* dataset, const std::string& datasourceId)
100 //{
101 // assert(dataset);
102 // assert(!datasourceId.empty());
103 //
104 // DataSourcePtr datasource(te::da::DataSourceManager::getInstance().find(datasourceId));
105 //
106 // if(datasource.get() == 0)
107 // return;
108 //
109 // LoadFull(dataset, datasource.get());
110 //}
111 
112 //void te::da::LoadFull(DataSetType* dataset, DataSource* datasource)
113 //{
114 // assert(dataset);
115 // assert(datasource);
116 //
117 // std::unique_ptr<DataSourceTransactor> transactor(datasource->getTransactor());
118 //
119 // LoadFull(dataset, transactor.get());
120 //}
121 
122 void te::da::LoadProperties(te::da::DataSetType* dataset, const std::string& datasourceId)
123 {
124  assert(dataset);
125  assert(!datasourceId.empty());
126 
127  //DataSourcePtr datasource(te::da::DataSourceManager::getInstance().get(datasourceId));
128  DataSourcePtr datasource(te::da::DataSourceManager::getInstance().find(datasourceId));
129 
130  if(datasource.get() == nullptr)
131  return;
132 
133  boost::ptr_vector<te::dt::Property> properties = datasource->getProperties(dataset->getName());
134 
135  dataset->add(properties);
136 }
137 
138 te::gm::Envelope* te::da::GetExtent(const std::string& datasetName,
139  const std::string& propertyName,
140  const std::string& datasourceId)
141 {
142  assert(!datasourceId.empty());
143 
144  //DataSourcePtr datasource(te::da::DataSourceManager::getInstance().get(datasourceId));
145  DataSourcePtr datasource(te::da::DataSourceManager::getInstance().find(datasourceId));
146 
147  if(datasource.get() == nullptr)
148  throw Exception(TE_TR("Could not retrieve data source in order to search for a property extent!"));
149 
150  std::unique_ptr<te::gm::Envelope> mbr(datasource->getExtent(datasetName, propertyName));
151 
152  return mbr.release();
153 }
154 
155 void te::da::GetDataSetNames(std::vector<std::string>& datasetNames, const std::string& datasourceId)
156 {
157  assert(!datasourceId.empty());
158 
160  if(ds.get() == nullptr)
161  return;
162 
163  datasetNames = ds->getDataSetNames();
164 }
165 
166 std::string te::da::GetDataSetCategoryName(int category)
167 {
168  switch(category)
169  {
171  return "Unknown";
172 
173  case te::da::TABLE_TYPE:
174  return "Table";
175 
177  return "System";
178 
179  case te::da::VIEW_TYPE:
180  return "View";
181 
182  case te::da::QUERY_TYPE:
183  return "Query";
184 
185  case te::da::INDEX_TYPE:
186  return "Index";
187 
189  return "Sequence";
190 
192  return "Trigger";
193 
195  return "Regular File";
196 
197  default:
198  return "";
199  }
200 }
201 
202 bool te::da::HasDataSet(const std::string& datasourceId)
203 {
204  assert(!datasourceId.empty());
205 
206  //DataSourcePtr datasource(te::da::DataSourceManager::getInstance().get(datasourceId));
207  DataSourcePtr datasource(te::da::DataSourceManager::getInstance().find(datasourceId));
208 
209  if(datasource.get() == nullptr)
210  return false;
211 
212  return datasource->hasDataSets();
213 }
214 
215 te::da::DataSet* te::da::GetDataSet(const std::string& name, const std::string& datasourceId)
216 {
217  assert(!datasourceId.empty());
218 
219  //DataSourcePtr datasource(te::da::DataSourceManager::getInstance().get(datasourceId));
220 
221  DataSourcePtr datasource(te::da::DataSourceManager::getInstance().find(datasourceId));
222 
223  if(datasource.get() == nullptr)
224  return nullptr;
225 
226  std::unique_ptr<DataSet> dataset(datasource->getDataSet(name));
227 
228  return dataset.release();
229 }
230 
231 te::da::DataSetType* te::da::GetDataSetType(const std::string& name, const std::string& datasourceId)
232 {
233  assert(!datasourceId.empty());
234 
235  DataSourcePtr datasource(te::da::DataSourceManager::getInstance().find(datasourceId));
236 
237  if(datasource.get() == nullptr)
238  return nullptr;
239 
240  std::unique_ptr<DataSetType> datasettype(datasource->getDataSetType(name));
241 
242  return datasettype.release();
243 }
244 
245 //te::da::DataSourcePtr te::da::GetDataSource(const std::string& datasourceId)
246 //{
247 // assert(!datasourceId.empty());
248 //
249 // DataSourcePtr datasource(te::da::DataSourceManager::getInstance().get(datasourceId));
250 //
251 // if(datasource.get() == 0)
252 // {
253 // DataSourceInfoPtr dsinfo = te::da::DataSourceInfoManager::getInstance().get(datasourceId);
254 //
255 // if(dsinfo.get() == 0)
256 // throw Exception(TE_TR("Could not find data source!"));
257 //
258 // te::da::DataSourceManager::getInstance().open(datasourceId, dsinfo->getAccessDriver(), dsinfo->getConnInfo());
259 //
260 // datasource = te::da::DataSourceManager::getInstance().get(datasourceId);
261 // }
262 //
263 // return datasource;
264 //}
265 
266 te::da::DataSourcePtr te::da::GetDataSource(const std::string& datasourceId, const bool opened)
267 {
268  assert(!datasourceId.empty());
269 
270  DataSourcePtr datasource(te::da::DataSourceManager::getInstance().find(datasourceId));
271 
272  if(datasource.get() == nullptr)
273  {
275 
276  if(dsinfo.get() == nullptr)
277  throw Exception(TE_TR("Could not find data source!"));
278 
279  datasource = te::da::DataSourceManager::getInstance().make(datasourceId, dsinfo->getAccessDriver(), dsinfo->getConnInfo());
280  }
281 
282  if(opened && !datasource->isOpened())
283  datasource->open();
284 
285  return datasource;
286 }
287 
289 {
290  assert (type);
291 
292  std::vector<size_t> ppos;
293  std::vector<int> ptypes;
294  std::vector<std::string> pnames;
295  std::vector<size_t>::iterator it;
296  set = new ObjectIdSet();
297 
298  GetOIDPropertyPos(type, ppos);
299 
300  for(it=ppos.begin(); it!=ppos.end(); ++it)
301  {
302  te::dt::Property* prop = type->getProperty(*it);
303  ptypes.push_back(prop->getType());
304  pnames.push_back(prop->getName());
305  }
306 
307  for(size_t i=0; i<ppos.size(); i++)
308  set->addProperty(pnames[i], ppos[i], ptypes[i]);
309 }
310 
311 void te::da::GetOIDPropertyNames(const te::da::DataSetType* type, std::vector<std::string>& pnames)
312 {
313  assert(type);
314 
315  // Looking for the primary key properties
316  PrimaryKey* pk = type->getPrimaryKey();
317  if(pk != nullptr)
318  {
319  const std::vector<te::dt::Property*>& pkProperties = pk->getProperties();
320 
321  for(std::size_t i = 0; i < pkProperties.size(); ++i)
322  pnames.push_back(pkProperties[i]->getName());
323 
324  return;
325  }
326 
327  // Looking for the unique key properties
328  if(type->getNumberOfUniqueKeys() > 0)
329  {
330  for(std::size_t i = 0; i < type->getNumberOfUniqueKeys(); ++i)
331  {
332  UniqueKey* uk = type->getUniqueKey(i);
333 
334  const std::vector<te::dt::Property*>& ukProperties = uk->getProperties();
335 
336  for(std::size_t j = 0; j < ukProperties.size(); ++j)
337  pnames.push_back(ukProperties[j]->getName());
338  }
339 
340  return;
341  }
342 
343  // Here, the data set type do not have primary key properties or unique key properties.
344  // So, use all the non geometric properties.
345  const std::vector<te::dt::Property*>& props = type->getProperties();
346  for(std::size_t i = 0; i < props.size(); ++i)
347  {
348  if(props[i]->getType() == te::dt::GEOMETRY_TYPE || props[i]->getType() == te::dt::RASTER_TYPE ||
349  props[i]->getType() == te::dt::FLOAT_TYPE || props[i]->getType() == te::dt::DOUBLE_TYPE ||
350  props[i]->getType() == te::dt::BYTE_ARRAY_TYPE || props[i]->getType() == te::dt::NUMERIC_TYPE)
351  continue;
352 
353  pnames.push_back(props[i]->getName());
354  }
355 }
356 
357 void te::da::GetOIDDatasetProps(const DataSetType* type, std::pair<std::string, int>& dsProps)
358 {
359  assert(type);
360  std::map<std::string, std::pair<int, int> > dsNames;
361  std::map<std::string, std::pair<int, int> >::const_iterator dsNamesIt;
362  std::vector<te::dt::Property*> props;
363 
364  // Looking for the primary key or unique key properties
365  PrimaryKey* pk = type->getPrimaryKey();
366  if(pk != nullptr)
367  props = pk->getProperties();
368 
369  //Getting the name and the number of properties of each dataset involved
370  for(size_t i = 0; i < props.size(); ++i)
371  {
372  te::dt::Property* pRef =props[i];
373  assert(pRef);
374  int propPos = (int)dsNames.size();
375  dsNames[pRef->getDatasetName()].first = propPos;
376  dsNames[pRef->getDatasetName()].second++;
377  }
378 
379  //Getting the name and the number of properties of the base dataset
380  for(dsNamesIt = dsNames.begin(); dsNamesIt != dsNames.end(); ++dsNamesIt)
381  {
382  if((*dsNamesIt).second.first == 0)
383  {
384  dsProps.first = (*dsNamesIt).first;
385  dsProps.second = (*dsNamesIt).second.second;
386  break;
387  }
388  }
389 }
390 
391 std::string te::da::getBasePkey(te::da::ObjectId* oid, std::pair<std::string, int>& dsProps)
392 {
393  assert(oid);
394  std::string res;
395  boost::ptr_vector<te::dt::AbstractData> curValues;
396  curValues = oid->getValue();
397  for(int i = 0; i < dsProps.second; ++i)
398  {
399  res = res + curValues[i].toString();
400  }
401  return res;
402 }
403 
404 void te::da::GetOIDPropertyPos(const te::da::DataSetType* type, std::vector<std::size_t>& ppos)
405 {
406  assert(type);
407 
408  std::vector<std::string> oidprops;
409  GetOIDPropertyNames(type, oidprops);
410 
411  for(std::size_t i = 0; i < oidprops.size(); ++i)
412  ppos.push_back(type->getPropertyPosition(oidprops[i]));
413 }
414 
416 {
417  assert(dataset);
418  assert(type);
419 
420  std::vector<std::string> oidprops;
421  GetOIDPropertyNames(type, oidprops);
422 
423  return te::da::GenerateOIDSet(dataset, oidprops);
424 }
425 
426 te::da::ObjectIdSet* te::da::GenerateOIDSet(te::da::DataSet* dataset, const std::vector<std::string>& names)
427 {
428  assert(dataset);
429  assert(!names.empty());
430 
431  ObjectIdSet* oids = new ObjectIdSet;
432 
433  for(std::size_t i = 0; i < names.size(); ++i)
434  {
435  std::size_t pos = GetPropertyPos(dataset, names[i]);
436 
437  if(pos == std::string::npos)
438  throw Exception(TE_TR("Primary Key ") + names[i] + TE_TR(" not found!"));
439 
440  oids->addProperty(names[i], pos, dataset->getPropertyDataType(pos));
441  }
442 
443  while(dataset->moveNext())
444  oids->add(GenerateOID(dataset, names));
445 
446  return oids;
447 }
448 
449 te::da::ObjectId* te::da::GenerateOID(te::da::DataSet* dataset, const std::vector<std::string>& names)
450 {
451  assert(dataset);
452  assert(!names.empty());
453 
454  ObjectId* oid = new ObjectId;
455 
456  for(std::size_t i = 0; i < names.size(); ++i)
457  {
458  if(!dataset->isNull(names[i]))
459  oid->addValue(dataset->getValue(names[i]).release());
460  }
461 
462  return oid;
463 }
464 
466 {
467  assert(dataset);
468 
469  const std::size_t np = dataset->getNumProperties();
470 
471  for(std::size_t i = 0; i != np; ++i)
472  {
473  int pdt = dataset->getPropertyDataType(i);
474 
475  if(pdt == te::dt::GEOMETRY_TYPE || pdt == te::dt::RASTER_TYPE)
476  {
477  return i;
478  }
479  }
480 
481  return std::string::npos;
482 }
483 
484 std::size_t te::da::GetFirstPropertyPos(const te::da::DataSet* dataset, int datatype)
485 {
486  assert(dataset);
487 
488  const std::size_t np = dataset->getNumProperties();
489 
490  for(std::size_t i = 0; i != np; ++i)
491  {
492  int pdt = dataset->getPropertyDataType(i);
493 
494  if(pdt == datatype)
495  {
496  return i;
497  }
498  }
499 
500  return std::string::npos;
501 }
502 
503 std::size_t te::da::GetPropertyPos(const DataSet* dataset, const std::string& name)
504 {
505  assert(dataset);
506 
507  const std::size_t np = dataset->getNumProperties();
508 
509  for(std::size_t i = 0; i != np; ++i)
510  {
511  std::string pname = dataset->getPropertyName(i);
512 
513  if(boost::iequals(pname, name))
514  return i;
515  }
516 
517  return std::string::npos;
518 }
519 
520 std::size_t te::da::GetPropertyPos(const DataSetType* dt, const std::string& name)
521 {
522  assert(dt);
523 
524  const std::size_t np = dt->getProperties().size();
525 
526  for(std::size_t i = 0; i != np; ++i)
527  {
528  std::string pname = dt->getProperty(i)->getName();
529 
530  if(boost::iequals(pname, name))
531  return i;
532  }
533 
534  return std::string::npos;
535 }
536 
538 {
539  assert(dt);
540 
541  const std::size_t np = dt->size();
542 
543  for(std::size_t i = 0; i != np; ++i)
544  {
545  te::dt::Property* p = dt->getProperty(i);
546 
547  assert(p);
548 
549  int pdt = p->getType();
550 
551  if(pdt == te::dt::GEOMETRY_TYPE || pdt == te::dt::RASTER_TYPE)
552  {
553  return p;
554  }
555  }
556 
557  return nullptr;
558 }
559 
561 {
563 
564  if(p)
565  {
566  return static_cast<te::gm::GeometryProperty*>(p);
567  }
568  else
569  {
570  return nullptr;
571  }
572 }
573 
575 {
577 
578  assert(p);
579 
580  return static_cast<te::rst::RasterProperty*>(p);
581 }
582 
583 //te::da::DataSetType* te::da::CreateDataSetType(const te::da::DataSet* dataset)
584 //{
585 // assert(dataset);
586 //
587 // te::da::DataSetType* dt = new DataSetType("");
588 //
589 // const std::size_t np = dataset->getNumProperties();
590 //
591 // for(std::size_t i = 0; i != np; ++i)
592 // {
593 // const te::dt::Property* p = dataset->getProperty(i);
594 //
595 // dt->add(p->clone());
596 // }
597 //
598 // return dt;
599 //}
600 
602  std::vector<std::string>& pnames,
603  std::vector<int>& ptypes)
604 {
605  assert(dt);
606 
607  for(std::size_t i = 0; i != dt->size(); ++i)
608  {
609  const te::dt::Property* p = dt->getProperty(i);
610 
611  pnames.push_back(p->getName());
612  ptypes.push_back(p->getType());
613  }
614 }
615 
616 void te::da::GetPropertyInfo(const DataSet* const dataset,
617  std::vector<std::string>& pnames,
618  std::vector<int>& ptypes)
619 {
620  assert(dataset);
621 
622  for(std::size_t i = 0; i != dataset->getNumProperties(); ++i)
623  {
624  pnames.push_back(dataset->getPropertyName(i));
625  ptypes.push_back(dataset->getPropertyDataType(i));
626  }
627 }
628 
629 void te::da::Create(DataSource* ds, DataSetType* dt, DataSet* d, std::size_t limit)
630 {
631  std::map<std::string, std::string> options;
632 
633  Create(ds, dt, d, options, limit);
634 }
635 
637  DataSetType* dt,
638  DataSet* d,
639  const std::map<std::string, std::string>& options,
640  std::size_t limit)
641 {
642  ds->createDataSet(dt, options);
643 
644  ds->add(dt->getName(), d, options, limit);
645 }
646 
648 {
649  assert(ds);
650  assert(converter);
651 
652  DataSetType* type = converter->getResult();
653  assert(type);
654 
655  const std::vector<std::vector<std::size_t> >& indexes = converter->getConvertedPropertyIndexes();
656  const std::vector<AttributeConverter>& funcs = converter->getConverters();
657 
658  assert((type->size() == indexes.size()) && (type->size() == funcs.size()));
659 
660  DataSetAdapter* adapter = new DataSetAdapter(ds, isOwner);
661 
662  for(std::size_t i = 0; i < type->size(); ++i)
663  {
664  te::dt::Property* p = type->getProperty(i);
665  assert(p);
666 
667  adapter->add(p->getName(), p->getType(), indexes[i], funcs[i]);
668  }
669 
670  return adapter;
671 }
672 
673 void te::da::AssociateDataSetTypeConverterSRID(DataSetTypeConverter* converter, const int& inputSRID, const int& outputSRID)
674 {
675  te::da::DataSetType* dsType = converter->getConvertee();
676 
678 
679  if (gmProp)
680  {
681  //remove default converter property for geometry property
682  converter->remove(gmProp->getName());
683 
684  std::size_t pos = dsType->getPropertyPosition(gmProp->getName());
685 
686  te::gm::GeometryProperty* geomPropClone = dynamic_cast<te::gm::GeometryProperty*>(gmProp->clone());
687  geomPropClone->setSRID(inputSRID);
688 
689  //add geometry property converter
690  SRIDAssociation sridConverter(inputSRID, outputSRID);
691  converter->add(pos, geomPropClone, sridConverter);
692 
693  //fix output geometry property srid
694  te::da::DataSetType* dsTypeResult = converter->getResult();
695 
696  te::gm::GeometryProperty* gmPropResult = GetFirstGeomProperty(dsTypeResult);
697 
698  if (gmPropResult)
699  {
700  if (outputSRID != TE_UNKNOWN_SRS)
701  {
702  gmPropResult->setSRID(outputSRID);
703  }
704  else
705  {
706  gmPropResult->setSRID(inputSRID);
707  }
708  }
709  }
710 }
711 
713 {
714  std::string valueNames("(");
715 
716  const std::size_t np = dt->size();
717 
718  for(std::size_t i = 0; i != np; ++i)
719  {
720  if(i != 0)
721  valueNames += ",";
722 
723  valueNames += dt->getProperty(i)->getName();
724  }
725 
726  valueNames += ")";
727 
728  return valueNames;
729 }
730 
731 std::string te::da::GetSQLValueNames(const te::da::DataSet* dataset)
732 {
733  std::string valueNames("(");
734 
735  const std::size_t np = dataset->getNumProperties();
736 
737  for(std::size_t i = 0; i != np; ++i)
738  {
739  if(i != 0)
740  valueNames += ",";
741 
742  valueNames += dataset->getPropertyName(i);
743  }
744 
745  valueNames += ")";
746 
747  return valueNames;
748 }
749 
750 std::vector<int> te::da::GetPropertyDataTypes(const te::da::DataSet* dataset)
751 {
752  std::vector<int> properties;
753 
754  const std::size_t np = dataset->getNumProperties();
755 
756  for(std::size_t i = 0; i != np; ++i)
757  {
758  properties.push_back(dataset->getPropertyDataType(i));
759  }
760 
761  return properties;
762 }
763 
764 std::unique_ptr<te::da::Expression> te::da::BuildSpatialOp(Expression* e1,
765  Expression* e2,
767 
768 {
769  std::unique_ptr<te::da::Expression> op;
770  switch(r)
771  {
772  case te::gm::INTERSECTS:
773  op.reset(new ST_Intersects(e1, e2));
774  break;
775 
776  case te::gm::DISJOINT:
777  op.reset(new ST_Disjoint(e1, e2));
778  break;
779 
780  case te::gm::TOUCHES:
781  op.reset(new ST_Touches(e1, e2));
782  break;
783 
784  case te::gm::OVERLAPS:
785  op.reset(new ST_Overlaps(e1, e2));
786  break;
787 
788  case te::gm::CROSSES:
789  op.reset(new ST_Crosses(e1, e2));
790  break;
791 
792  case te::gm::WITHIN:
793  op.reset(new ST_Within(e1, e2));
794  break;
795 
796  case te::gm::CONTAINS:
797  op.reset(new ST_Contains(e1, e2));
798  break;
799 
800  case te::gm::EQUALS:
801  op.reset(new ST_Equals(e1, e2));
802  break;
803 
804  default:
805  throw;
806  }
807 
808  return op;
809 }
810 
811 std::unique_ptr<te::da::Fields> te::da::BuildFields(const std::vector<std::string>& properties)
812 {
813  std::unique_ptr<Fields> fields(new Fields);
814 
815  for(std::size_t i = 0; i < properties.size(); ++i)
816  fields->push_back(new te::da::Field(properties[i]));
817 
818  return fields;
819 }
820 
821 std::unique_ptr<te::da::Select> te::da::BuildSelect(const std::string& dsname)
822 {
823  return BuildSelect(dsname, "*");
824 }
825 
826 std::unique_ptr<te::da::Select> te::da::BuildSelect(const std::string& dsname, const std::string& propertyName)
827 {
828  std::vector<std::string> p;
829  p.push_back(propertyName);
830 
831  return BuildSelect(dsname, p);
832 }
833 
834 std::unique_ptr<te::da::Select> te::da::BuildSelect(const std::string& dsname, const std::vector<std::string>& properties)
835 {
836  // Fields
837  std::unique_ptr<Fields> fields = BuildFields(properties);
838 
839  // From
840  FromItem* fi = new DataSetName(dsname);
841  From* from = new From;
842  from->push_back(fi);
843 
844  // Select
845  std::unique_ptr<Select> select(new Select(fields.release(), from));
846 
847  return select;
848 }
849 
850 std::unique_ptr<te::da::Select> te::da::BuildSelect(const std::string& dsname,
851  const std::vector<std::string>& properties,
852  const std::string& geometryProperty,
853  const te::gm::Envelope* e,
854  int srid,
856 {
857  // Fields
858  std::unique_ptr<Fields> fields = BuildFields(properties);
859 
860  // Adding the geometry property
861  fields->push_back(new Field(geometryProperty));
862 
863  // From
864  FromItem* fi = new DataSetName(dsname);
865  From* from = new From;
866  from->push_back(fi);
867 
868  PropertyName* geomPropertyName = new PropertyName(geometryProperty);
869  LiteralEnvelope* lenv = new LiteralEnvelope(*e, srid);
870 
871  // The spatial restriction
872  std::unique_ptr<Expression> spatialOp = BuildSpatialOp(geomPropertyName, lenv, r);
873 
874  // Where
875  te::da::Where* filter = new Where(spatialOp.release());
876 
877  // Select
878  std::unique_ptr<Select> select(new Select(fields.release(), from, filter));
879 
880  return select;
881 }
882 
883 std::unique_ptr<te::da::Select> te::da::BuildSelect(const std::string& dsname,
884  const std::vector<std::string>& properties,
885  const std::string& geometryProperty,
886  te::gm::Geometry* g,
888 {
889  // Fields
890  std::unique_ptr<Fields> fields = BuildFields(properties);
891 
892  // Adding the geometry property
893  fields->push_back(new Field(geometryProperty));
894 
895  // From
896  FromItem* fi = new DataSetName(dsname);
897  From* from = new From;
898  from->push_back(fi);
899 
900  PropertyName* geomPropertyName = new PropertyName(geometryProperty);
901  LiteralGeom* lgeom = new LiteralGeom(g);
902 
903  // The spatial restriction
904  std::unique_ptr<Expression> spatialOp = BuildSpatialOp(geomPropertyName, lgeom, r);
905 
906  // Where
907  te::da::Where* filter = new Where(spatialOp.release());
908 
909  // Select
910  std::unique_ptr<Select> select(new Select(fields.release(), from, filter));
911 
912  return select;
913 }
914 
915 std::unique_ptr<te::da::Select> te::da::BuildSelect(const std::string& dsname,
916  const std::vector<std::string>& properties,
917  const ObjectIdSet* oids)
918 {
919  // OIDS restriction
920  Expression* exp = oids->getExpression();
921  assert(exp);
922 
923  // Where
924  Where* filter = new Where(exp);
925 
926  // Fields
927  std::unique_ptr<Fields> fields = BuildFields(properties);
928 
929  // Adding the oids properties case not included
930  const std::vector<std::string>& oidsProperties = oids->getPropertyNames();
931  for(std::size_t i = 0; i < oidsProperties.size(); ++i)
932  {
933  const std::string& oidPropertyName = oidsProperties[i];
934 
935  bool alreadyIncluded = false;
936 
937  for(std::size_t j = 0; j < properties.size(); ++j)
938  {
939  if(oidPropertyName == properties[j])
940  {
941  alreadyIncluded = true;
942  break;
943  }
944  }
945 
946  if(!alreadyIncluded)
947  fields->push_back(new Field(oidPropertyName));
948  }
949 
950  // From
951  FromItem* fromItem = new DataSetName(dsname);
952  From* from = new From;
953  from->push_back(fromItem);
954 
955  // Select
956  std::unique_ptr<Select> select(new Select(fields.release(), from, filter));
957 
958  return select;
959 }
960 
961 int te::da::GetPropertyIndex(te::da::DataSet* dataSet, const std::string propName)
962 {
963  int index = 0;
964 
965  for(std::size_t i = 0; i < dataSet->getNumProperties(); ++i)
966  {
967  if(propName == dataSet->getPropertyName(i))
968  {
969  index = (int)i;
970  return index;
971  }
972  }
973  return -1;
974 }
975 
976 bool te::da::IsValidName(const std::string& name, std::string& invalidChar)
977 {
978  if(name.empty())
979  {
980  return false;
981  }
982 
983  if(name[0] >= 0x30 && name[0] <= 0x39)
984  {
985  invalidChar = "begin with a numeric character\n";
986  return false;
987  }
988  if(name[0] == '_')
989  {
990  invalidChar += "begin with a invalid character: underscore _\n";
991  return false;
992  }
993 
994  int ff = (int)name.find(" ");
995  if(ff >= 0)
996  {
997  invalidChar += "invalid character: blank space\n";
998  return false;
999  }
1000 
1001  ff = (int)name.find(".");
1002  if(ff >= 0)
1003  {
1004  invalidChar += "invalid character: dot '.'\n";
1005  return false;
1006  }
1007 
1008  ff = (int)name.find("*");
1009  if(ff >= 0)
1010  {
1011  invalidChar += "invalid character: mathematical symbol '*'\n";
1012  return false;
1013  }
1014 
1015  ff = (int)name.find("/");
1016  if(ff >= 0)
1017  {
1018  invalidChar += "invalid character: mathematical symbol '/'\n";
1019  return false;
1020  }
1021 
1022  ff = (int)name.find("(");
1023  if(ff >= 0)
1024  {
1025  invalidChar += "invalid character: parentheses '('\n";
1026  return false;
1027  }
1028 
1029  ff = (int)name.find(")");
1030  if(ff >= 0)
1031  {
1032  invalidChar += "invalid character: parentheses ')'\n";
1033  return false;
1034  }
1035 
1036  ff = (int)name.find("-");
1037  if(ff >= 0)
1038  {
1039  invalidChar += "invalid character: mathematical symbol '-'\n";
1040  return false;
1041  }
1042 
1043  ff = (int)name.find("+");
1044  if(ff >= 0)
1045  {
1046  invalidChar += "invalid character: mathematical symbol '+'\n";
1047  return false;
1048  }
1049 
1050  ff = (int)name.find("%");
1051  if(ff >= 0)
1052  {
1053  invalidChar += "invalid character: mathematical symbol '%'\n";
1054  return false;
1055  }
1056 
1057  ff = (int)name.find(">");
1058  if(ff >= 0)
1059  {
1060  invalidChar += "invalid character: mathematical symbol '>'\n";
1061  return false;
1062  }
1063 
1064  ff = (int)name.find("<");
1065  if(ff >= 0)
1066  {
1067  invalidChar += "invalid character: mathematical symbol '<'\n";
1068  return false;
1069  }
1070 
1071  ff = (int)name.find("&");
1072  if(ff >= 0)
1073  {
1074  invalidChar += "invalid character: mathematical symbol '&'\n";
1075  return false;
1076  }
1077 
1078  ff = (int)name.find("$");
1079  if(ff >= 0)
1080  {
1081  invalidChar += "invalid symbol: '$'\n";
1082  return false;
1083  }
1084 
1085  ff = (int)name.find(";");
1086  if(ff >= 0)
1087  {
1088  invalidChar += "invalid symbol: ';'\n";
1089  return false;
1090  }
1091 
1092  ff = (int)name.find("=");
1093  if(ff >= 0)
1094  {
1095  invalidChar += "invalid symbol: '='\n";
1096  return false;
1097  }
1098 
1099  ff = (int)name.find("!");
1100  if(ff >= 0)
1101  {
1102  invalidChar += "invalid symbol: '!'\n";
1103  return false;
1104  }
1105 
1106  ff = (int)name.find("?");
1107  if(ff >= 0)
1108  {
1109  invalidChar += "invalid symbol: '?'\n";
1110  return false;
1111  }
1112 
1113  ff = (int)name.find("#");
1114  if(ff >= 0)
1115  {
1116  invalidChar += "invalid symbol: '#'\n";
1117  return false;
1118  }
1119 
1120  ff = (int)name.find("¨");
1121  if(ff >= 0)
1122  {
1123  invalidChar += "invalid symbol: '¨'\n";
1124  return false;
1125  }
1126 
1127  ff = (int)name.find(",");
1128  if(ff >= 0)
1129  {
1130  invalidChar += "invalid symbol: ','\n";
1131  return false;
1132  }
1133 
1134  ff = (int)name.find("/");
1135  if(ff >= 0)
1136  {
1137  invalidChar += "invalid symbol: '/'\n";
1138  return false;
1139  }
1140 
1141  ff = (int)name.find("@");
1142  if(ff >= 0)
1143  {
1144  invalidChar += "invalid symbol: '@'\n";
1145  return false;
1146  }
1147 
1148  ff = (int)name.find("{");
1149  if(ff >= 0)
1150  {
1151  invalidChar += "invalid symbol: '{'\n";
1152  return false;
1153  }
1154 
1155  ff = (int)name.find("}");
1156  if(ff >= 0)
1157  {
1158  invalidChar += "invalid symbol: '}'\n";
1159  return false;
1160  }
1161 
1162  std::vector<std::string> vecInvalidChars;
1163  vecInvalidChars.push_back("ª");
1164  vecInvalidChars.push_back("º");
1165  vecInvalidChars.push_back("¹");
1166  vecInvalidChars.push_back("²");
1167  vecInvalidChars.push_back("³");
1168 
1169  for(unsigned int i = 0; i < vecInvalidChars.size(); ++i)
1170  {
1171  std::string invalidItem = vecInvalidChars[i];
1172 
1173  ff = (int)name.find(invalidItem);
1174  if(ff >= 0)
1175  {
1176  invalidChar += "invalid symbol: '" + invalidItem + "'\n";
1177  return false;
1178  }
1179  }
1180 
1181  for(unsigned int i = 0; i < name.size(); ++i)
1182  {
1183  char value = name[i];
1184  if(value < 0)
1185  {
1186  invalidChar += "invalid symbol\n";
1187  return false;
1188  }
1189  }
1190 
1191  std::string u = te::common::Convert2UCase(name);
1192  if(u=="OR" || u=="AND" || u=="NOT" || u=="LIKE" ||
1193  u=="SELECT" || u=="FROM" || u=="UPDATE" || u=="DELETE" ||u=="BY" || u=="GROUP" || u=="ORDER" ||
1194  u=="DROP" || u=="INTO" || u=="VALUE" || u=="IN" || u=="ASC" || u=="DESC"|| u=="COUNT" || u=="JOIN" ||
1195  u=="LEFT" || u=="RIGHT" || u=="INNER" || u=="UNION" || u=="IS" || u=="NULL" || u=="WHERE" ||
1196  u=="BETWEEN" || u=="DISTINCT" || u=="TRY" || u=="IT" || u=="INSERT" || u=="ALIASES" || u=="CREATE" ||
1197  u=="ALTER" || u=="TABLE" || u=="INDEX" || u=="ALL" || u=="HAVING" || u=="EXEC" || u== "SET" ||
1198  u == "AVG" || u == "MAX" || u == "MIN" || u == "SUM" || u == "FILTER" || u == "OFFSET" || u == "LENGHT" )
1199  {
1200  invalidChar += "invalid name: using reserved word " + u + "\n";
1201  return false;
1202  }
1203 
1204  std::string n = te::common::Convert2LCase(name);
1205  // reserved words
1206  if( (n=="zone") || (n=="comp") || (n=="no") || (n=="local") ||
1207  (n=="level") || (n=="long"))
1208  {
1209  invalidChar += "invalid name: using reserved word " + n + "\n";
1210  return false;
1211  }
1212 
1213  return true;
1214 }
1215 
1216 
1218 {
1219  assert(type);
1220  te::da::PrimaryKey* pk = type->getPrimaryKey();
1221  if(pk)
1222  {
1223  std::vector<te::dt::Property*> props = pk->getProperties();
1224  if(props.size() > 1)
1225  {
1226  size_t pksize = 0;
1227  while(++pksize < props.size())
1228  {
1229  if(props[pksize-1]->getDatasetName() != props[pksize]->getDatasetName())
1230  return true;
1231  }
1232  }
1233  }
1234 
1235  return false;
1236 }
1237 
1238 std::unique_ptr<te::da::DataSet> te::da::HideColumns(te::da::DataSet* ds, te::da::DataSetType* dst, const std::vector<std::string>& columns)
1239 {
1240  assert(ds);
1241  assert(dst);
1242 
1244  cap.setSupportAll();
1246  dtCap.setSupportAll();
1247  cap.setDataTypeCapabilities(dtCap);
1248 
1249  std::unique_ptr<te::da::DataSetTypeConverter> converter(new te::da::DataSetTypeConverter(dst, cap));
1250 
1251  for (std::size_t i = 0; i < columns.size(); ++i)
1252  {
1253  converter->remove(columns[i]);
1254  }
1255 
1256  std::unique_ptr<te::da::DataSet> result(te::da::CreateAdapter(ds, converter.get(), false));
1257 
1258  return result;
1259 }
1260 
1261 double te::da::GetSummarizedValue(std::vector<double>& values, const std::string& sumary)
1262 {
1263  double size = (double)values.size();
1264  if(size == 0)
1265  return 0;
1266 
1267  double d = 0, v = 0;
1268  std::vector<double>::const_iterator it;
1269 
1270  if(sumary == "MIN")
1271  {
1272  it = values.begin();
1273  v = *it;
1274 
1275  while(it != values.end())
1276  {
1277  d = *it++;
1278  v = std::min(v, d);
1279  }
1280  }
1281  else if(sumary == "MAX")
1282  {
1283  it = values.begin();
1284  v = *it;
1285 
1286  while(it != values.end())
1287  {
1288  d = *it++;
1289  v = std::max(v, d);
1290  }
1291  }
1292  else if(sumary == "SUM")
1293  {
1294  v = 0;
1295  for(it = values.begin(); it != values.end(); ++it)
1296  v += *it;
1297  }
1298  else if(sumary == "AVERAGE")
1299  {
1300  v = 0;
1301  for(it = values.begin(); it != values.end(); ++it)
1302  v += *it;
1303  v /= size;
1304  }
1305  else if(sumary == "STDDEV")
1306  {
1307  double m = 0;
1308  v = 0;
1309  if(size > 1)
1310  {
1311  for(it = values.begin(); it != values.end(); ++it)
1312  {
1313  d = *it;
1314  m += d;
1315  v += (d * d);
1316  }
1317  m /= size;
1318  v = (v - m) / (size - 1);
1319  v = sqrt(v);
1320  }
1321  }
1322  else if(sumary == "VARIANCE")
1323  {
1324  double m = 0;
1325  v = 0;
1326  if(size > 1)
1327  {
1328  for(it = values.begin(); it != values.end(); ++it)
1329  {
1330  d = *it;
1331  m += d;
1332  v += (d * d);
1333  }
1334  m /= size;
1335  v = (v - m) / (size - 1);
1336  }
1337  }
1338  else if(sumary == "MEDIAN")
1339  {
1340  if(size == 1)
1341  v = values[0];
1342  else
1343  {
1344  std::stable_sort(values.begin(), values.end());
1345  size_t meio = (size_t)size / 2;
1346  v = values[meio];
1347 
1348  if((size_t)size%2 == 0)
1349  v = (v + values[meio-1]) / 2.;
1350  }
1351  }
1352  else if(sumary == "MODE") // nao dá porque pode gerar nenhum ou vários valores
1353  {
1354  }
1355 
1356  return v;
1357 }
1358 
1359 std::string te::da::GetSummarizedValue(const std::vector<std::string>& values, const std::string& sumary)
1360 {
1361  double size = (double)values.size();
1362  if(size == 0)
1363  return nullptr;
1364 
1365  std::string v, d;
1366  std::vector<std::string>::const_iterator it;
1367 
1368  if(sumary == "MIN")
1369  {
1370  it = values.begin();
1371  v = *it;
1372 
1373  while(it != values.end())
1374  {
1375  d = *it++;
1376  v = std::min(v, d);
1377  }
1378  }
1379  else if(sumary == "MAX")
1380  {
1381  it = values.begin();
1382  v = *it;
1383 
1384  while(it != values.end())
1385  {
1386  d = *it++;
1387  v = std::max(v, d);
1388  }
1389  }
1390 
1391  return v;
1392 }
1393 
1394 double te::da::Round(const double& value, const size_t& precision)
1395 {
1396  double v = pow(10., (int)precision);
1397  double ret = boost::math::round(value * v);
1398  ret /= v;
1399  return ret;
1400 }
1401 
1402 double te::da::GetValueAsDouble(const te::da::DataSet* ds, const size_t idx)
1403 {
1404  size_t dataType = ds->getPropertyDataType(idx);
1405  switch(dataType)
1406  {
1407  case te::dt::CHAR_TYPE:
1408  return (double)ds->getChar(idx);
1409 
1410  case te::dt::UCHAR_TYPE:
1411  return (double)ds->getUChar(idx);
1412 
1413  case te::dt::INT16_TYPE:
1414  return (double)ds->getInt16(idx);
1415 
1416  case te::dt::UINT16_TYPE:
1417  return (double)ds->getInt16(idx);
1418 
1419  case te::dt::INT32_TYPE:
1420  return (double)ds->getInt32(idx);
1421 
1422  case te::dt::UINT32_TYPE:
1423  return (double)ds->getInt32(idx);
1424 
1425  case te::dt::INT64_TYPE:
1426  return (double)ds->getInt64(idx);
1427 
1428  case te::dt::UINT64_TYPE:
1429  return (double)ds->getInt64(idx);
1430 
1431  case te::dt::FLOAT_TYPE:
1432  return (double)ds->getFloat(idx);
1433 
1434  case te::dt::DOUBLE_TYPE:
1435  return (double)ds->getDouble(idx);
1436 
1437  case te::dt::NUMERIC_TYPE:
1438  return boost::lexical_cast<double>(ds->getNumeric(idx));
1439 
1440  default:
1441  return 0.;
1442  }
1443 }
TEDATAACCESSEXPORT DataSourcePtr GetDataSource(const std::string &datasourceId, const bool opened=true)
Search for a data source with the informed id in the DataSourceManager.
Property * getProperty(std::size_t i) const
It returns the i-th property.
virtual unsigned char getUChar(std::size_t i) const =0
Method for retrieving an unsigned character attribute value (1 byte long).
TEDATAACCESSEXPORT te::rst::RasterProperty * GetFirstRasterProperty(const DataSetType *dt)
void push_back(Curve *ring)
It adds the curve to the curve polygon.
Geometric property.
TEDATAACCESSEXPORT te::gm::Envelope * GetExtent(const std::string &datasetName, const std::string &propertyName, const std::string &datasourceId)
TEDATAACCESSEXPORT void LoadProperties(te::da::DataSetType *dataset, const std::string &datasourceId)
virtual double getDouble(std::size_t i) const =0
Method for retrieving a double attribute value.
const std::vector< std::vector< std::size_t > > & getConvertedPropertyIndexes() const
An abstract class that models a source of data in a query.
Definition: FromItem.h:50
The Field class can be used to model an expression that takes part of the output items of a SELECT...
TEDATAACCESSEXPORT void GetEmptyOIDSet(const DataSetType *type, ObjectIdSet *&set)
Returns an empty ObjectIdSet, with the definitions of fields that compose it.
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
Spatial within operator.
Definition: ST_Within.h:46
TEDATAACCESSEXPORT ObjectId * GenerateOID(DataSet *dataset, const std::vector< std::string > &names)
Spatial intersects operator.
Definition: ST_Intersects.h:46
A class that models the name of a dataset used in a From clause.
Definition: DataSetName.h:43
boost::shared_ptr< DataSource > DataSourcePtr
std::string Convert2LCase(const std::string &value)
It converts a string to lower case.
Definition: StringUtils.h:202
TEDATAACCESSEXPORT void AssociateDataSetTypeConverterSRID(DataSetTypeConverter *converter, const int &inputSRID, const int &outputSRID=TE_UNKNOWN_SRS)
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
TEDATAACCESSEXPORT bool HasLinkedTable(te::da::DataSetType *type)
It checks if the datasettype has a linked table.
A class that models the name of any property of an object.
Base exception class for plugin module.
A class that models the description of a dataset.
Definition: DataSetType.h:72
TEDATAACCESSEXPORT std::string GetDataSetCategoryName(int category)
virtual std::string getNumeric(std::size_t i) const =0
Method for retrieving a numeric attribute value.
std::size_t getNumberOfUniqueKeys() const
It returns the number of unique keys defined for the dataset type.
Definition: DataSetType.h:269
virtual float getFloat(std::size_t i) const =0
Method for retrieving a float attribute value.
TEDATAACCESSEXPORT std::unique_ptr< Select > BuildSelect(const std::string &dsname)
virtual void createDataSet(DataSetType *dt, const std::map< std::string, std::string > &options)
It creates the dataset schema definition in the target data source.
TEDATAACCESSEXPORT std::size_t GetPropertyPos(const DataSet *dataset, const std::string &name)
const boost::ptr_vector< te::dt::AbstractData > & getValue() const
It gets the properties values used to uniquely identify a data set element.
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.
PrimaryKey * getPrimaryKey() const
It returns the primary key associated to the dataset type.
Definition: DataSetType.h:214
std::string Convert2UCase(const std::string &value)
It converts a string to upper case.
Definition: StringUtils.h:168
SpatialRelation
Spatial relations between geometric objects.
A class that represents the known capabilities of a specific data source, i.e. this class informs all...
TEDATAACCESSEXPORT std::string GetSQLValueNames(const DataSetType *dt)
static te::dt::Date ds(2010, 01, 01)
TEDATAACCESSEXPORT double GetValueAsDouble(const te::da::DataSet *ds, const size_t pos)
It gets the value as double.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
Spatial crosses operator.
Definition: ST_Crosses.h:46
TEDATAACCESSEXPORT void GetOIDDatasetProps(const DataSetType *type, std::pair< std::string, int > &dsProps)
te::dt::Property * clone() const
It returns a clone of the object.
It models a property definition.
Definition: Property.h:59
TEDATAACCESSEXPORT int GetPropertyIndex(te::da::DataSet *dataSet, const std::string propName)
Raster property.
This is an abstract class that models a query expression.
DataSetType * getConvertee()
This method returns the pointer to the DataSetType that is handled by the converter.
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that take part of the primary key.
Definition: PrimaryKey.h:109
void DataSetAdapter()
DataSet Adapter example.
TEDATAACCESSEXPORT std::unique_ptr< te::da::DataSet > HideColumns(te::da::DataSet *ds, te::da::DataSetType *dst, const std::vector< std::string > &columns)
It hide columns of a DataSet using DataSetAdapter.
An converter for DataSetType.
const std::vector< AttributeConverter > & getConverters() const
A class that represents the supported data types of a specific data source.
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
TEDATAACCESSEXPORT std::size_t GetFirstSpatialPropertyPos(const te::da::DataSet *dataset)
It returns the first dataset spatial property or NULL if none is found.
const std::vector< Property * > & getProperties() const
It returns the list of properties describing the CompositeProperty.
virtual boost::int16_t getInt16(std::size_t i) const =0
Method for retrieving a 16-bit integer attribute value (2 bytes long).
static DataSourceManager & getInstance()
It returns a reference to the singleton instance.
virtual int getPropertyDataType(std::size_t i) const =0
It returns the underlying data type of the property at position pos.
Spatial overlaps operator.
Definition: ST_Overlaps.h:46
An Envelope defines a 2D rectangular region.
void ObjectId()
ObjectId example.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
TEDATAACCESSEXPORT void Create(DataSource *ds, DataSetType *dt, DataSet *d, std::size_t limit=0)
It creates the dataset definition in a data source and then fill it with data from the input dataset...
Spatial touches operator.
Definition: ST_Touches.h:46
This class represents an unique id for a data set element.
virtual boost::int32_t getInt32(std::size_t i) const =0
Method for retrieving a 32-bit integer attribute value (4 bytes long).
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
static te::dt::TimeDuration dt(20, 30, 50, 11)
boost::ptr_vector< Field > Fields
Fields is just a boost::ptr_vector of Field pointers.
Definition: Fields.h:37
TEDATAACCESSEXPORT DataSet * GetDataSet(const std::string &name, const std::string &datasourceId)
TEDATAACCESSEXPORT bool HasDataSet(const std::string &datasourceId)
A class that can be used to model a filter expression that can be applied to a query.
Definition: Where.h:47
TEDATAACCESSEXPORT double GetSummarizedValue(std::vector< double > &values, const std::string &summary)
It gets the summarized value.
te::gm::Polygon * p
It describes a unique key (uk) constraint.
Definition: UniqueKey.h:53
std::size_t size() const
It returns the number of properties of the CompositeProperty.
TEDATAACCESSEXPORT ObjectIdSet * GenerateOIDSet(DataSet *dataset, const DataSetType *type)
TEDATAACCESSEXPORT void GetDataSetNames(std::vector< std::string > &datasetNames, const std::string &datasourceId)
TEDATAACCESSEXPORT std::vector< int > GetPropertyDataTypes(const te::da::DataSet *dataset)
Utility functions for the data access module.
TEDATAACCESSEXPORT std::unique_ptr< Expression > BuildSpatialOp(Expression *e1, Expression *e2, te::gm::SpatialRelation r)
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:65
TEDATAACCESSEXPORT double Round(const double &value, const size_t &precision)
It gets the round value.
void add(const std::string &newPropertyName, int newPropertyType, const std::vector< std::size_t > &adaptedPropertyPos, AttributeConverter conv)
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
Definition: From.h:37
Spatial contains operator.
Definition: ST_Contains.h:46
int getType() const
It returns the property data type.
Definition: Property.h:161
void add(Constraint *c)
It adds a new constraint.
A dataset is the unit of information manipulated by the data access module of TerraLib.
virtual char getChar(std::size_t i) const =0
Method for retrieving a signed character attribute value (1 byte long).
const std::vector< te::dt::Property * > & getProperties() const
It returns the properties that form the unique key.
Definition: UniqueKey.h:110
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...
TEDATAACCESSEXPORT void GetOIDPropertyPos(const DataSetType *type, std::vector< std::size_t > &ppos)
virtual std::unique_ptr< te::dt::AbstractData > getValue(std::size_t i) const
Method for retrieving any other type of data value stored in the data source.
Spatial equals operator.
Definition: ST_Equals.h:46
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
void remove(const std::string &propertyName)
This method removes a property of DataSetTypeConverter.
void setDataTypeCapabilities(const DataTypeCapabilities &capabilities)
TEDATAACCESSEXPORT bool IsValidName(const std::string &name, std::string &invalidChar)
It checks if the name is not valid as the existence of invalid characters, reserved words...
A class that models a literal for Envelope values.
TEDATAACCESSEXPORT std::string getBasePkey(te::da::ObjectId *oid, std::pair< std::string, int > &dsProps)
const std::vector< std::string > & getPropertyNames() const
It returns the property names used to generated the oids.
std::size_t getPropertyPosition(const std::string &name) const
It returns the property position based on its name.
TEDATAACCESSEXPORT void GetOIDPropertyNames(const DataSetType *type, std::vector< std::string > &pnames)
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
TEDATAACCESSEXPORT DataSetType * GetDataSetType(const std::string &name, const std::string &datasourceId)
Spatial Disjoint operator.
Definition: ST_Disjoint.h:46
void add(const std::string &propertyName, te::dt::Property *p, const std::string &attributeConverterName="GenericAttributeConverter")
It adds a conversions to the given property of the input data set type.
virtual boost::int64_t getInt64(std::size_t i) const =0
Method for retrieving a 64-bit integer attribute value (8 bytes long).
TEDATAACCESSEXPORT std::size_t GetFirstPropertyPos(const te::da::DataSet *dataset, int datatype)
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
virtual std::string getPropertyName(std::size_t i) const =0
It returns the property name at position pos.
TEDATAACCESSEXPORT std::unique_ptr< Fields > BuildFields(const std::vector< std::string > &properties)
const std::string & getDatasetName() const
It returns the name of the propery&#39;s dataset.
Definition: Property.h:144
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
TEDATAACCESSEXPORT DataSetAdapter * CreateAdapter(DataSet *ds, DataSetTypeConverter *converter, bool isOwner=false)
terralib_conf cmake set(SWIG_MAIN_FILE"${CMAKE_CURRENT_SOURCE_DIR}/../../../src/terralib/binding/swig/TerraLibLUA.i") file(GLOB TERRALIB_SWIG_SCRIPT_FILE $
TEDATAACCESSEXPORT void LoadFull(te::da::DataSetType *dataset, const std::string &datasourceId)
An adapter for DataSet.
Expression * getExpression() const
It returns the expression that can be used to retrieve the data set that contains the all indentified...
TEDATAACCESSEXPORT te::dt::Property * GetFirstSpatialProperty(const DataSetType *dt)
UniqueKey * getUniqueKey(std::size_t i) const
It returns the i-th unique key.
Definition: DataSetType.h:294
boost::shared_ptr< DataSourceInfo > DataSourceInfoPtr
TEDATAACCESSEXPORT void GetPropertyInfo(const DataSetType *const dt, std::vector< std::string > &pnames, std::vector< int > &ptypes)
A class that models a literal for Geometry values.
Definition: LiteralGeom.h:46
const std::string & getName() const
It returns the property name.
Definition: Property.h:127