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