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 
670 void te::da::AssociateDataSetTypeConverterSRID(DataSetTypeConverter* converter, const int& inputSRID, const int& outputSRID)
671 {
672  te::da::DataSetType* dsType = converter->getConvertee();
673 
675 
676  if (gmProp)
677  {
678  //remove default converter property for geometry property
679  converter->remove(gmProp->getName());
680 
681  std::size_t pos = dsType->getPropertyPosition(gmProp->getName());
682 
683  //add geometry property converter
684  SRIDAssociation sridConverter(inputSRID, outputSRID);
685  converter->add(pos, gmProp->clone(), sridConverter);
686 
687  gmProp->setSRID(inputSRID);
688 
689  //fix output geometry property srid
690  te::da::DataSetType* dsTypeResult = converter->getResult();
691 
692  te::gm::GeometryProperty* gmPropResult = GetFirstGeomProperty(dsTypeResult);
693 
694  if (gmPropResult)
695  {
696  if (outputSRID != TE_UNKNOWN_SRS)
697  {
698  gmPropResult->setSRID(outputSRID);
699  }
700  else
701  {
702  gmPropResult->setSRID(inputSRID);
703  }
704  }
705  }
706 }
707 
709 {
710  std::string valueNames("(");
711 
712  const std::size_t np = dt->size();
713 
714  for(std::size_t i = 0; i != np; ++i)
715  {
716  if(i != 0)
717  valueNames += ",";
718 
719  valueNames += dt->getProperty(i)->getName();
720  }
721 
722  valueNames += ")";
723 
724  return valueNames;
725 }
726 
727 std::string te::da::GetSQLValueNames(const te::da::DataSet* dataset)
728 {
729  std::string valueNames("(");
730 
731  const std::size_t np = dataset->getNumProperties();
732 
733  for(std::size_t i = 0; i != np; ++i)
734  {
735  if(i != 0)
736  valueNames += ",";
737 
738  valueNames += dataset->getPropertyName(i);
739  }
740 
741  valueNames += ")";
742 
743  return valueNames;
744 }
745 
746 std::vector<int> te::da::GetPropertyDataTypes(const te::da::DataSet* dataset)
747 {
748  std::vector<int> properties;
749 
750  const std::size_t np = dataset->getNumProperties();
751 
752  for(std::size_t i = 0; i != np; ++i)
753  {
754  properties.push_back(dataset->getPropertyDataType(i));
755  }
756 
757  return properties;
758 }
759 
760 std::auto_ptr<te::da::Expression> te::da::BuildSpatialOp(Expression* e1,
761  Expression* e2,
763 
764 {
765  std::auto_ptr<te::da::Expression> op;
766  switch(r)
767  {
768  case te::gm::INTERSECTS:
769  op.reset(new ST_Intersects(e1, e2));
770  break;
771 
772  case te::gm::DISJOINT:
773  op.reset(new ST_Disjoint(e1, e2));
774  break;
775 
776  case te::gm::TOUCHES:
777  op.reset(new ST_Touches(e1, e2));
778  break;
779 
780  case te::gm::OVERLAPS:
781  op.reset(new ST_Overlaps(e1, e2));
782  break;
783 
784  case te::gm::CROSSES:
785  op.reset(new ST_Crosses(e1, e2));
786  break;
787 
788  case te::gm::WITHIN:
789  op.reset(new ST_Within(e1, e2));
790  break;
791 
792  case te::gm::CONTAINS:
793  op.reset(new ST_Contains(e1, e2));
794  break;
795 
796  case te::gm::EQUALS:
797  op.reset(new ST_Equals(e1, e2));
798  break;
799 
800  default:
801  throw;
802  }
803 
804  return op;
805 }
806 
807 std::auto_ptr<te::da::Fields> te::da::BuildFields(const std::vector<std::string>& properties)
808 {
809  std::auto_ptr<Fields> fields(new Fields);
810 
811  for(std::size_t i = 0; i < properties.size(); ++i)
812  fields->push_back(new te::da::Field(properties[i]));
813 
814  return fields;
815 }
816 
817 std::auto_ptr<te::da::Select> te::da::BuildSelect(const std::string& dsname)
818 {
819  return BuildSelect(dsname, "*");
820 }
821 
822 std::auto_ptr<te::da::Select> te::da::BuildSelect(const std::string& dsname, const std::string& propertyName)
823 {
824  std::vector<std::string> p;
825  p.push_back(propertyName);
826 
827  return BuildSelect(dsname, p);
828 }
829 
830 std::auto_ptr<te::da::Select> te::da::BuildSelect(const std::string& dsname, const std::vector<std::string>& properties)
831 {
832  // Fields
833  std::auto_ptr<Fields> fields = BuildFields(properties);
834 
835  // From
836  FromItem* fi = new DataSetName(dsname);
837  From* from = new From;
838  from->push_back(fi);
839 
840  // Select
841  std::auto_ptr<Select> select(new Select(fields.release(), from));
842 
843  return select;
844 }
845 
846 std::auto_ptr<te::da::Select> te::da::BuildSelect(const std::string& dsname,
847  const std::vector<std::string>& properties,
848  const std::string& geometryProperty,
849  const te::gm::Envelope* e,
850  int srid,
852 {
853  // Fields
854  std::auto_ptr<Fields> fields = BuildFields(properties);
855 
856  // Adding the geometry property
857  fields->push_back(new Field(geometryProperty));
858 
859  // From
860  FromItem* fi = new DataSetName(dsname);
861  From* from = new From;
862  from->push_back(fi);
863 
864  PropertyName* geomPropertyName = new PropertyName(geometryProperty);
865  LiteralEnvelope* lenv = new LiteralEnvelope(*e, srid);
866 
867  // The spatial restriction
868  std::auto_ptr<Expression> spatialOp = BuildSpatialOp(geomPropertyName, lenv, r);
869 
870  // Where
871  te::da::Where* filter = new Where(spatialOp.release());
872 
873  // Select
874  std::auto_ptr<Select> select(new Select(fields.release(), from, filter));
875 
876  return select;
877 }
878 
879 std::auto_ptr<te::da::Select> te::da::BuildSelect(const std::string& dsname,
880  const std::vector<std::string>& properties,
881  const std::string& geometryProperty,
882  te::gm::Geometry* g,
884 {
885  // Fields
886  std::auto_ptr<Fields> fields = BuildFields(properties);
887 
888  // Adding the geometry property
889  fields->push_back(new Field(geometryProperty));
890 
891  // From
892  FromItem* fi = new DataSetName(dsname);
893  From* from = new From;
894  from->push_back(fi);
895 
896  PropertyName* geomPropertyName = new PropertyName(geometryProperty);
897  LiteralGeom* lgeom = new LiteralGeom(g);
898 
899  // The spatial restriction
900  std::auto_ptr<Expression> spatialOp = BuildSpatialOp(geomPropertyName, lgeom, r);
901 
902  // Where
903  te::da::Where* filter = new Where(spatialOp.release());
904 
905  // Select
906  std::auto_ptr<Select> select(new Select(fields.release(), from, filter));
907 
908  return select;
909 }
910 
911 std::auto_ptr<te::da::Select> te::da::BuildSelect(const std::string& dsname,
912  const std::vector<std::string>& properties,
913  const ObjectIdSet* oids)
914 {
915  // OIDS restriction
916  Expression* exp = oids->getExpression();
917  assert(exp);
918 
919  // Where
920  Where* filter = new Where(exp);
921 
922  // Fields
923  std::auto_ptr<Fields> fields = BuildFields(properties);
924 
925  // Adding the oids properties case not included
926  const std::vector<std::string>& oidsProperties = oids->getPropertyNames();
927  for(std::size_t i = 0; i < oidsProperties.size(); ++i)
928  {
929  const std::string& oidPropertyName = oidsProperties[i];
930 
931  bool alreadyIncluded = false;
932 
933  for(std::size_t j = 0; j < properties.size(); ++j)
934  {
935  if(oidPropertyName == properties[j])
936  {
937  alreadyIncluded = true;
938  break;
939  }
940  }
941 
942  if(!alreadyIncluded)
943  fields->push_back(new Field(oidPropertyName));
944  }
945 
946  // From
947  FromItem* fromItem = new DataSetName(dsname);
948  From* from = new From;
949  from->push_back(fromItem);
950 
951  // Select
952  std::auto_ptr<Select> select(new Select(fields.release(), from, filter));
953 
954  return select;
955 }
956 
957 int te::da::GetPropertyIndex(te::da::DataSet* dataSet, const std::string propName)
958 {
959  int index = 0;
960 
961  for(std::size_t i = 0; i < dataSet->getNumProperties(); ++i)
962  {
963  if(propName == dataSet->getPropertyName(i))
964  {
965  index = i;
966  return index;
967  }
968  }
969  return -1;
970 }
971 
972 bool te::da::IsValidName(const std::string& name, std::string& invalidChar)
973 {
974  if(name.empty())
975  {
976  return false;
977  }
978 
979  if(name[0] >= 0x30 && name[0] <= 0x39)
980  {
981  invalidChar = "begin with a numeric character\n";
982  return false;
983  }
984  if(name[0] == '_')
985  {
986  invalidChar += "begin with a invalid character: underscore _\n";
987  return false;
988  }
989 
990  int ff = name.find(" ");
991  if(ff >= 0)
992  {
993  invalidChar += "invalid character: blank space\n";
994  return false;
995  }
996 
997  ff = name.find(".");
998  if(ff >= 0)
999  {
1000  invalidChar += "invalid character: dot '.'\n";
1001  return false;
1002  }
1003 
1004  ff = name.find("*");
1005  if(ff >= 0)
1006  {
1007  invalidChar += "invalid character: mathematical symbol '*'\n";
1008  return false;
1009  }
1010 
1011  ff = name.find("/");
1012  if(ff >= 0)
1013  {
1014  invalidChar += "invalid character: mathematical symbol '/'\n";
1015  return false;
1016  }
1017 
1018  ff = name.find("(");
1019  if(ff >= 0)
1020  {
1021  invalidChar += "invalid character: parentheses '('\n";
1022  return false;
1023  }
1024 
1025  ff = name.find(")");
1026  if(ff >= 0)
1027  {
1028  invalidChar += "invalid character: parentheses ')'\n";
1029  return false;
1030  }
1031 
1032  ff = name.find("-");
1033  if(ff >= 0)
1034  {
1035  invalidChar += "invalid character: mathematical symbol '-'\n";
1036  return false;
1037  }
1038 
1039  ff = name.find("+");
1040  if(ff >= 0)
1041  {
1042  invalidChar += "invalid character: mathematical symbol '+'\n";
1043  return false;
1044  }
1045 
1046  ff = name.find("%");
1047  if(ff >= 0)
1048  {
1049  invalidChar += "invalid character: mathematical symbol '%'\n";
1050  return false;
1051  }
1052 
1053  ff = name.find(">");
1054  if(ff >= 0)
1055  {
1056  invalidChar += "invalid character: mathematical symbol '>'\n";
1057  return false;
1058  }
1059 
1060  ff = name.find("<");
1061  if(ff >= 0)
1062  {
1063  invalidChar += "invalid character: mathematical symbol '<'\n";
1064  return false;
1065  }
1066 
1067  ff = name.find("&");
1068  if(ff >= 0)
1069  {
1070  invalidChar += "invalid character: mathematical symbol '&'\n";
1071  return false;
1072  }
1073 
1074  ff = name.find("$");
1075  if(ff >= 0)
1076  {
1077  invalidChar += "invalid symbol: '$'\n";
1078  return false;
1079  }
1080 
1081  ff = name.find(";");
1082  if(ff >= 0)
1083  {
1084  invalidChar += "invalid symbol: ';'\n";
1085  return false;
1086  }
1087 
1088  ff = name.find("=");
1089  if(ff >= 0)
1090  {
1091  invalidChar += "invalid symbol: '='\n";
1092  return false;
1093  }
1094 
1095  ff = name.find("!");
1096  if(ff >= 0)
1097  {
1098  invalidChar += "invalid symbol: '!'\n";
1099  return false;
1100  }
1101 
1102  ff = name.find("?");
1103  if(ff >= 0)
1104  {
1105  invalidChar += "invalid symbol: '?'\n";
1106  return false;
1107  }
1108 
1109  ff = name.find("#");
1110  if(ff >= 0)
1111  {
1112  invalidChar += "invalid symbol: '#'\n";
1113  return false;
1114  }
1115 
1116  ff = name.find("¨");
1117  if(ff >= 0)
1118  {
1119  invalidChar += "invalid symbol: '¨'\n";
1120  return false;
1121  }
1122 
1123  ff = name.find(",");
1124  if(ff >= 0)
1125  {
1126  invalidChar += "invalid symbol: ','\n";
1127  return false;
1128  }
1129 
1130  ff = name.find("/");
1131  if(ff >= 0)
1132  {
1133  invalidChar += "invalid symbol: '/'\n";
1134  return false;
1135  }
1136 
1137  ff = name.find("@");
1138  if(ff >= 0)
1139  {
1140  invalidChar += "invalid symbol: '@'\n";
1141  return false;
1142  }
1143 
1144  ff = name.find("{");
1145  if(ff >= 0)
1146  {
1147  invalidChar += "invalid symbol: '{'\n";
1148  return false;
1149  }
1150 
1151  ff = name.find("}");
1152  if(ff >= 0)
1153  {
1154  invalidChar += "invalid symbol: '}'\n";
1155  return false;
1156  }
1157 
1158  std::vector<std::string> vecInvalidChars;
1159  vecInvalidChars.push_back("ª");
1160  vecInvalidChars.push_back("º");
1161  vecInvalidChars.push_back("¹");
1162  vecInvalidChars.push_back("²");
1163  vecInvalidChars.push_back("³");
1164 
1165  for(unsigned int i = 0; i < vecInvalidChars.size(); ++i)
1166  {
1167  std::string invalidItem = vecInvalidChars[i];
1168 
1169  ff = name.find(invalidItem);
1170  if(ff >= 0)
1171  {
1172  invalidChar += "invalid symbol: '" + invalidItem + "'\n";
1173  return false;
1174  }
1175  }
1176 
1177  for(unsigned int i = 0; i < name.size(); ++i)
1178  {
1179  char value = name[i];
1180  if(value < 0)
1181  {
1182  invalidChar += "invalid symbol\n";
1183  return false;
1184  }
1185  }
1186 
1187  std::string u = te::common::Convert2UCase(name);
1188  if(u=="OR" || u=="AND" || u=="NOT" || u=="LIKE" ||
1189  u=="SELECT" || u=="FROM" || u=="UPDATE" || u=="DELETE" ||u=="BY" || u=="GROUP" || u=="ORDER" ||
1190  u=="DROP" || u=="INTO" || u=="VALUE" || u=="IN" || u=="ASC" || u=="DESC"|| u=="COUNT" || u=="JOIN" ||
1191  u=="LEFT" || u=="RIGHT" || u=="INNER" || u=="UNION" || u=="IS" || u=="NULL" || u=="WHERE" ||
1192  u=="BETWEEN" || u=="DISTINCT" || u=="TRY" || u=="IT" || u=="INSERT" || u=="ALIASES" || u=="CREATE" ||
1193  u=="ALTER" || u=="TABLE" || u=="INDEX" || u=="ALL" || u=="HAVING" || u=="EXEC" || u== "SET" ||
1194  u == "AVG" || u == "MAX" || u == "MIN" || u == "SUM" || u == "FILTER" || u == "OFFSET" || u == "LENGHT" )
1195  {
1196  invalidChar += "invalid name: using reserved word " + u + "\n";
1197  return false;
1198  }
1199 
1200  std::string n = te::common::Convert2LCase(name);
1201  // reserved words
1202  if( (n=="zone") || (n=="comp") || (n=="no") || (n=="local") ||
1203  (n=="level") || (n=="long"))
1204  {
1205  invalidChar += "invalid name: using reserved word " + n + "\n";
1206  return false;
1207  }
1208 
1209  return true;
1210 }
1211 
1212 
1214 {
1215  assert(type);
1216  te::da::PrimaryKey* pk = type->getPrimaryKey();
1217  if(pk)
1218  {
1219  std::vector<te::dt::Property*> props = pk->getProperties();
1220  if(props.size() > 1)
1221  {
1222  size_t pksize = 0;
1223  while(++pksize < props.size())
1224  {
1225  if(props[pksize-1]->getDatasetName() != props[pksize]->getDatasetName())
1226  return true;
1227  }
1228  }
1229  }
1230 
1231  return false;
1232 }
1233 
1234 double te::da::GetSummarizedValue(std::vector<double>& values, const std::string& sumary)
1235 {
1236  double size = values.size();
1237  if(size == 0)
1238  return 0;
1239 
1240  double d = 0, v = 0;
1241  std::vector<double>::const_iterator it;
1242 
1243  if(sumary == "MIN")
1244  {
1245  it = values.begin();
1246  v = *it;
1247 
1248  while(it != values.end())
1249  {
1250  d = *it++;
1251  v = std::min(v, d);
1252  }
1253  }
1254  else if(sumary == "MAX")
1255  {
1256  it = values.begin();
1257  v = *it;
1258 
1259  while(it != values.end())
1260  {
1261  d = *it++;
1262  v = std::max(v, d);
1263  }
1264  }
1265  else if(sumary == "SUM")
1266  {
1267  v = 0;
1268  for(it = values.begin(); it != values.end(); ++it)
1269  v += *it;
1270  }
1271  else if(sumary == "AVERAGE")
1272  {
1273  v = 0;
1274  for(it = values.begin(); it != values.end(); ++it)
1275  v += *it;
1276  v /= size;
1277  }
1278  else if(sumary == "STDDEV")
1279  {
1280  double m = 0;
1281  v = 0;
1282  if(size > 1)
1283  {
1284  for(it = values.begin(); it != values.end(); ++it)
1285  {
1286  d = *it;
1287  m += d;
1288  v += (d * d);
1289  }
1290  m /= size;
1291  v = (v - m) / (size - 1);
1292  v = sqrt(v);
1293  }
1294  }
1295  else if(sumary == "VARIANCE")
1296  {
1297  double m = 0;
1298  v = 0;
1299  if(size > 1)
1300  {
1301  for(it = values.begin(); it != values.end(); ++it)
1302  {
1303  d = *it;
1304  m += d;
1305  v += (d * d);
1306  }
1307  m /= size;
1308  v = (v - m) / (size - 1);
1309  }
1310  }
1311  else if(sumary == "MEDIAN")
1312  {
1313  if(size == 1)
1314  v = values[0];
1315  else
1316  {
1317  std::stable_sort(values.begin(), values.end());
1318  size_t meio = (size_t)size / 2;
1319  v = values[meio];
1320 
1321  if((size_t)size%2 == 0)
1322  v = (v + values[meio-1]) / 2.;
1323  }
1324  }
1325  else if(sumary == "MODE") // nao dá porque pode gerar nenhum ou vários valores
1326  {
1327  }
1328 
1329  return v;
1330 }
1331 
1332 std::string te::da::GetSummarizedValue(const std::vector<std::string>& values, const std::string& sumary)
1333 {
1334  double size = values.size();
1335  if(size == 0)
1336  return 0;
1337 
1338  std::string v, d;
1339  std::vector<std::string>::const_iterator it;
1340 
1341  if(sumary == "MIN")
1342  {
1343  it = values.begin();
1344  v = *it;
1345 
1346  while(it != values.end())
1347  {
1348  d = *it++;
1349  v = std::min(v, d);
1350  }
1351  }
1352  else if(sumary == "MAX")
1353  {
1354  it = values.begin();
1355  v = *it;
1356 
1357  while(it != values.end())
1358  {
1359  d = *it++;
1360  v = std::max(v, d);
1361  }
1362  }
1363 
1364  return v;
1365 }
1366 
1367 double te::da::Round(const double& value, const size_t& precision)
1368 {
1369  double v = pow(10., (int)precision);
1370  double ret = boost::math::round(value * v);
1371  ret /= v;
1372  return ret;
1373 }
1374 
1375 double te::da::GetValueAsDouble(const te::da::DataSet* ds, const size_t idx)
1376 {
1377  size_t dataType = ds->getPropertyDataType(idx);
1378  switch(dataType)
1379  {
1380  case te::dt::CHAR_TYPE:
1381  return (double)ds->getChar(idx);
1382 
1383  case te::dt::UCHAR_TYPE:
1384  return (double)ds->getUChar(idx);
1385 
1386  case te::dt::INT16_TYPE:
1387  return (double)ds->getInt16(idx);
1388 
1389  case te::dt::UINT16_TYPE:
1390  return (double)ds->getInt16(idx);
1391 
1392  case te::dt::INT32_TYPE:
1393  return (double)ds->getInt32(idx);
1394 
1395  case te::dt::UINT32_TYPE:
1396  return (double)ds->getInt32(idx);
1397 
1398  case te::dt::INT64_TYPE:
1399  return (double)ds->getInt64(idx);
1400 
1401  case te::dt::UINT64_TYPE:
1402  return (double)ds->getInt64(idx);
1403 
1404  case te::dt::FLOAT_TYPE:
1405  return (double)ds->getFloat(idx);
1406 
1407  case te::dt::DOUBLE_TYPE:
1408  return (double)ds->getDouble(idx);
1409 
1410  case te::dt::NUMERIC_TYPE:
1411  return boost::lexical_cast<double>(ds->getNumeric(idx));
1412 
1413  default:
1414  return 0.;
1415  }
1416 }
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
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
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:200
TEDATAACCESSEXPORT void AssociateDataSetTypeConverterSRID(DataSetTypeConverter *converter, const int &inputSRID, const int &outputSRID=TE_UNKNOWN_SRS)
Definition: Utils.cpp:670
TEDATAACCESSEXPORT std::auto_ptr< Select > BuildSelect(const std::string &dsname)
Definition: Utils.cpp:817
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:1213
TEDATAACCESSEXPORT std::auto_ptr< Expression > BuildSpatialOp(Expression *e1, Expression *e2, te::gm::SpatialRelation r)
Definition: Utils.cpp:760
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:166
SpatialRelation
Spatial relations between geometric objects.
Definition: Enums.h:122
TEDATAACCESSEXPORT std::string GetSQLValueNames(const DataSetType *dt)
Definition: Utils.cpp:708
TEDATAACCESSEXPORT double GetValueAsDouble(const te::da::DataSet *ds, const size_t pos)
It gets the value as double.
Definition: Utils.cpp:1375
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:346
Spatial crosses operator.
Definition: ST_Crosses.h:46
TEDATAACCESSEXPORT void GetOIDDatasetProps(const DataSetType *type, std::pair< std::string, int > &dsProps)
Definition: Utils.cpp:355
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)
Definition: Utils.cpp:957
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
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
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
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
Definition: Config.h:41
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:1234
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:746
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:1367
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
void remove(const std::string &propertyName)
This method removes a property of DataSetTypeConverter.
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:972
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
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.
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:807
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