src/terralib/qt/plugins/mobile/geopackage/Transactor.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 // TerraLib
21 #include "../../../../core/translator/Translator.h"
22 #include "../../../../dataaccess/dataset/ObjectId.h"
23 #include "../../../../dataaccess/dataset/ObjectIdSet.h"
24 #include "../../../../dataaccess/query/DataSetName.h"
25 #include "../../../../dataaccess/query/Query.h"
26 #include "../../../../dataaccess/query/Select.h"
27 #include "../../../../dataaccess/utils/Utils.h"
28 #include "../../../../datatype/ByteArray.h"
29 #include "../../../../datatype/Date.h"
30 #include "../../../../datatype/TimeInstant.h"
31 #include "../../../../geometry/Envelope.h"
32 #include "../../../../geometry/GeometryProperty.h"
33 #include "../../../../srs/SpatialReferenceSystemManager.h"
34 #include "../../../../srs/Config.h"
35 #include "DataSource.h"
36 #include "DataSet.h"
37 #include "SQLVisitor.h"
38 #include "Transactor.h"
39 #include "Utils.h"
40 
41 // OGR
42 #include <ogrsf_frmts.h>
43 
44 OGRFieldType GetOGRType(int te_type)
45 {
46  switch (te_type)
47  {
48  case te::dt::CHAR_TYPE:
49  case te::dt::UCHAR_TYPE:
51  return OFTString;
52  break;
53 
54  case te::dt::INT16_TYPE:
56  case te::dt::INT32_TYPE:
58  case te::dt::INT64_TYPE:
60  return OFTInteger;
61  break;
62 
63  case te::dt::FLOAT_TYPE:
66  return OFTReal;
67  break;
68 
70  return OFTDateTime;
71  break;
72  };
73 
74  return OFTInteger;
75 }
76 
78  : te::da::DataSourceTransactor(),
79  m_ogrDs(ds),
80  m_fid(0)
81 {
82 }
83 
85 {
86 }
87 
89 {
90  return 0;
91 }
92 
94 {
95 }
96 
98 {
99  if (!m_ogrDs->getOGRDataSource())
100  return;
101 
102  m_ogrDs->getOGRDataSource()->FlushCache();
103 }
104 
106 {
107 }
108 
110 {
111  return false;
112 }
113 
114 std::auto_ptr<te::da::DataSet> te::gpkg::Transactor::getDataSet(const std::string& name,
115  te::common::TraverseType /*travType*/,
116  bool /*connected*/,
118 {
119  if (!m_ogrDs->getOGRDataSource())
120  return std::auto_ptr<te::da::DataSet>();
121 
122  GDALDataset *poDS = (GDALDataset*)GDALOpenEx(m_ogrDs->getOGRDataSource()->GetDescription(), GDAL_OF_READONLY | GDAL_OF_VECTOR, NULL, NULL, NULL);
123 
124  std::string sql = "SELECT FID, * FROM \"" + name + "\"";
125  OGRLayer* l = poDS->ExecuteSQL(sql.c_str(), 0, 0);
126 
127  if(l == 0)
128  throw Exception(TE_TR("The informed data set could not be found in the data source."));
129 
130  return std::auto_ptr<te::da::DataSet>(new DataSet(poDS, l));
131 }
132 
133 std::auto_ptr<te::da::DataSet> te::gpkg::Transactor::getDataSet(const std::string& name,
134  const std::string& /*propertyName*/,
135  const te::gm::Envelope* e,
137  te::common::TraverseType /*travType*/,
138  bool /*connected*/,
140 {
141  if (!m_ogrDs->getOGRDataSource())
142  return std::auto_ptr<te::da::DataSet>();
143 
144  GDALDataset *ds = (GDALDataset*)GDALOpenEx(m_ogrDs->getOGRDataSource()->GetDescription(), GDAL_OF_READONLY | GDAL_OF_VECTOR, NULL, NULL, NULL);
145 
146  if (!ds)
147  return std::auto_ptr<te::da::DataSet>();
148 
149  std::string sql = "SELECT FID, * FROM \"" + name + "\"";
150  OGRLayer* layer = ds->ExecuteSQL(sql.c_str(), 0, 0);
151 
152  if(layer == 0)
153  throw Exception(TE_TR("The informed data set could not be found in the data source."));
154 
155  layer->SetSpatialFilterRect(e->m_llx, e->m_lly, e->m_urx, e->m_ury);
156 
157  return std::auto_ptr<te::da::DataSet>(new DataSet(ds, layer));
158 }
159 
160 std::auto_ptr<te::da::DataSet> te::gpkg::Transactor::getDataSet(const std::string& name,
161  const std::string& /*propertyName*/,
162  const te::gm::Geometry* g,
164  te::common::TraverseType /*travType*/,
165  bool /*connected*/,
167 {
168  if (!m_ogrDs->getOGRDataSource())
169  return std::auto_ptr<te::da::DataSet>();
170 
171  GDALDataset *ds = (GDALDataset*)GDALOpenEx(m_ogrDs->getOGRDataSource()->GetDescription(), GDAL_OF_READONLY | GDAL_OF_VECTOR, NULL, NULL, NULL);
172 
173  if (!ds)
174  return std::auto_ptr<te::da::DataSet>();
175 
176  std::string sql = "SELECT FID, * FROM \"" + name + "\"";
177  OGRLayer* layer = ds->ExecuteSQL(sql.c_str(), 0, 0);
178 
179  if(layer == 0)
180  throw Exception(TE_TR("The informed data set could not be found in the data source."));
181 
182  OGRGeometry* ogrg = Convert2OGR(g);
183 
184  layer->SetSpatialFilter(ogrg);
185 
186  OGRGeometryFactory::destroyGeometry(ogrg);
187 
188  return std::auto_ptr<te::da::DataSet>(new DataSet(ds, layer));
189 }
190 
191 std::auto_ptr<te::da::DataSet> te::gpkg::Transactor::query(const te::da::Select& q,
192  te::common::TraverseType /*travType*/,
193  bool /*connected*/,
195 {
196  if (!m_ogrDs->getOGRDataSource())
197  return std::auto_ptr<te::da::DataSet>();
198 
199  GDALDataset* ds = (GDALDataset*)GDALOpenEx(m_ogrDs->getOGRDataSource()->GetDescription(), GDAL_OF_UPDATE, NULL, NULL, NULL);
200 
201  std::string sql;
202 
203  SQLVisitor visitor(*m_ogrDs->getDialect(), sql);
204 
205  q.accept(visitor);
206 
207  sql = RemoveSpatialSql(sql);
208 
209  OGRLayer* layer = ds->ExecuteSQL(sql.c_str(), 0, 0);
210 
211  if(layer == 0)
212  throw Exception(TE_TR("Could not retrieve the DataSet from data source."));
213 
214  te::gm::Envelope* e = visitor.getMBR();
215 
216  if(e != 0)
217  layer->SetSpatialFilterRect(e->m_llx, e->m_lly, e->m_urx, e->m_ury);
218 
219  return std::auto_ptr<te::da::DataSet>(new DataSet(ds, layer));
220 }
221 
222 std::auto_ptr<te::da::DataSet> te::gpkg::Transactor::query(const std::string& query,
223  te::common::TraverseType /*travType*/,
224  bool /*connected*/,
226 {
227  if (!m_ogrDs->getOGRDataSource())
228  return std::auto_ptr<te::da::DataSet>();
229 
230  //OGRDataSource* ds = OGRSFDriverRegistrar::Open(m_ogrDs->getOGRDataSource()->GetName());
231  GDALDataset* ds = (GDALDataset*)GDALOpenEx(m_ogrDs->getOGRDataSource()->GetDescription(), GDAL_OF_UPDATE, NULL, NULL, NULL);
232 
233  // Adding FID attribute case "SELECT *"
234  std::string queryCopy = query;
235  std::size_t pos = queryCopy.find("*");
236  if(pos != std::string::npos)
237  {
238  std::string fid = "FID, *";
239  queryCopy.replace(pos, 1, fid);
240  }
241 
242  OGRLayer* layer = ds->ExecuteSQL(queryCopy.c_str(), 0, 0);
243 
244  if(layer == 0)
245  throw Exception(TE_TR("Could not retrieve the DataSet from data source."));
246 
247  return std::auto_ptr<te::da::DataSet>(new DataSet(ds, layer));
248 }
249 
251 {
252  std::string sql;
253  SQLVisitor v(*m_ogrDs->getDialect(), sql);
254 
255  command.accept(v);
256 
257  execute(sql);
258 }
259 
260 void te::gpkg::Transactor::execute(const std::string& command)
261 {
262  if (!m_ogrDs->getOGRDataSource())
263  return;
264 
265  OGRLayer* layer = m_ogrDs->getOGRDataSource()->ExecuteSQL(command.c_str(), 0, "");
266 
267  if(layer != 0)
268  m_ogrDs->getOGRDataSource()->ReleaseResultSet(layer);
269 }
270 
271 std::auto_ptr<te::da::PreparedQuery> te::gpkg::Transactor::getPrepared(const std::string& /*qName*/)
272 {
273  return std::auto_ptr<te::da::PreparedQuery>(0);
274 }
275 
276 std::auto_ptr<te::da::BatchExecutor> te::gpkg::Transactor::getBatchExecutor()
277 {
278  return std::auto_ptr<te::da::BatchExecutor>(0);
279 }
280 
282 {
283 }
284 
286 {
287  return m_fid;
288 }
289 
290 std::string te::gpkg::Transactor::escape(const std::string& value)
291 {
292  return value;
293 }
294 
295 std::vector<std::string> te::gpkg::Transactor::getDataSetNames()
296 {
297  std::vector<std::string> names;
298 
299  if (!m_ogrDs->getOGRDataSource())
300  return names;
301 
302  for(int i=0; i<m_ogrDs->getOGRDataSource()->GetLayerCount(); i++)
303  names.push_back(m_ogrDs->getOGRDataSource()->GetLayer(i)->GetName());
304 
305  return names;
306 }
307 
309 {
310  if (!m_ogrDs->getOGRDataSource())
311  return 0;
312 
313  return m_ogrDs->getOGRDataSource()->GetLayerCount();
314 }
315 
316 std::auto_ptr<te::da::DataSetType> te::gpkg::Transactor::getDataSetType(const std::string& name)
317 {
318  if (!m_ogrDs->getOGRDataSource())
319  return std::auto_ptr<te::da::DataSetType>();
320 
321  GDALDataset *poDS = (GDALDataset*)GDALOpenEx(m_ogrDs->getOGRDataSource()->GetDescription(), GDAL_OF_READONLY | GDAL_OF_VECTOR, NULL, NULL, NULL);
322 
323  std::string sql("SELECT FID, * FROM \"");
324  sql += name + "\"";
325 
326  OGRLayer* l = m_ogrDs->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
327 
328  if(l==0)
329  return std::auto_ptr<te::da::DataSetType>();
330 
331  const char* colIdName = l->GetFIDColumn();
332 
333  if (colIdName == 0 || colIdName[0] == '\0')
334  colIdName = "FID";
335 
336  int pos = l->GetLayerDefn()->GetFieldIndex(colIdName);
337 
338  std::auto_ptr<te::da::DataSetType> type(Convert2TerraLib(l->GetLayerDefn()));
339 
340  type->setName(name);
341 
342  if(pos >= 0)
343  {
344  te::da::PrimaryKey* pk = new te::da::PrimaryKey(colIdName, type.get());
345  pk->add(type->getProperty(pos));
346  }
347 
348  int srs = te::gpkg::Convert2TerraLibProjection(l->GetSpatialRef());
349 
351 
352  if(gp != 0)
353  gp->setSRID(srs);
354 
355  m_ogrDs->getOGRDataSource()->ReleaseResultSet(l);
356 
357  return type;
358 }
359 
360 std::auto_ptr<te::da::DataSetTypeCapabilities> te::gpkg::Transactor::getCapabilities(const std::string &name)
361 {
362  std::auto_ptr<te::da::DataSetTypeCapabilities> cap(new te::da::DataSetTypeCapabilities);
363 
364  OGRLayer* l = m_ogrDs->getOGRDataSource()->GetLayerByName(name.c_str());
365 
366  if(l != 0)
367  {
368  cap->setSupportAddColumn((l->TestCapability(OLCCreateField) == 0) ? false : true);
369  cap->setSupportRemoveColumn((l->TestCapability(OLCDeleteField) == 0) ? false : true);
370  cap->setSupportDataEdition((l->TestCapability(OLCRandomWrite) == 0) ? false : true);
371  }
372 
373  return cap;
374 }
375 
376 boost::ptr_vector<te::dt::Property> te::gpkg::Transactor::getProperties(const std::string& datasetName)
377 {
378  boost::ptr_vector<te::dt::Property> ps;
379 
380  if (!m_ogrDs->getOGRDataSource())
381  return ps;
382 
383  std::string sql("SELECT FID, * FROM \"");
384  sql += datasetName + "\"";
385 
386  OGRLayer* l = m_ogrDs->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
387 
388  if(l!=0)
389  {
390  int srs = te::gpkg::Convert2TerraLibProjection(l->GetSpatialRef());
391  std::auto_ptr<te::da::DataSetType> dt(Convert2TerraLib(l->GetLayerDefn(),srs));
392  std::vector<te::dt::Property*> props = dt->getProperties();
393  std::vector<te::dt::Property*>::iterator it;
394 
395  for(it=props.begin(); it!=props.end(); ++it)
396  ps.push_back((*it)->clone());
397  }
398 
399  m_ogrDs->getOGRDataSource()->ReleaseResultSet(l);
400 
401  return ps;
402 }
403 
404 std::auto_ptr<te::dt::Property> te::gpkg::Transactor::getProperty(const std::string& datasetName, const std::string& name)
405 {
406  if (!m_ogrDs->getOGRDataSource())
407  return std::auto_ptr<te::dt::Property>();
408 
409  int idx = -1;
410  std::string sql("SELECT FID, * FROM \"");
411  sql += datasetName + "\"";
412 
413  OGRLayer* l = m_ogrDs->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
414 
415  if(l != 0)
416  idx = l->GetLayerDefn()->GetFieldIndex(name.c_str());
417 
418  m_ogrDs->getOGRDataSource()->ReleaseResultSet(l);
419 
420  return getProperty(datasetName, idx);
421 }
422 
423 std::auto_ptr<te::dt::Property> te::gpkg::Transactor::getProperty(const std::string& datasetName, std::size_t propertyPos)
424 {
425  //OGRDataSource* ogrds = m_ogrDs->getOGRDataSource();
426  GDALDataset* ogrds = m_ogrDs->getOGRDataSource();
427  if (!ogrds)
428  return std::auto_ptr<te::dt::Property>();
429 
430  std::auto_ptr<te::dt::Property> res;
431  std::string sql("SELECT FID, * FROM \"");
432  sql += datasetName + "\"";
433 
434  OGRLayer* l = ogrds->ExecuteSQL(sql.c_str(), 0, 0);
435 
436  if(l != 0)
437  {
438  OGRFeatureDefn* def = l->GetLayerDefn();
439  OGRFieldDefn* fdef = def->GetFieldDefn(propertyPos);
440 
441  if(fdef != 0)
442  res.reset(Convert2TerraLib(fdef));
443  }
444 
445  m_ogrDs->getOGRDataSource()->ReleaseResultSet(l);
446 
447  return res;
448 }
449 
450 std::vector<std::string> te::gpkg::Transactor::getPropertyNames(const std::string& datasetName)
451 {
452  //OGRDataSource* ogrds = m_ogrDs->getOGRDataSource();
453  GDALDataset* ogrds = m_ogrDs->getOGRDataSource();
454  if (!ogrds)
455  return std::vector<std::string>();
456 
457  std::vector<std::string> res;
458  std::string sql("SELECT FID, * FROM \"");
459  sql += datasetName + "\"";
460 
461  OGRLayer* l = ogrds->ExecuteSQL(sql.c_str(), 0, 0);
462 
463  if(l != 0)
464  {
465  OGRFeatureDefn* def = l->GetLayerDefn();
466 
467  for(int i=0; i<def->GetFieldCount(); i++)
468  res.push_back(def->GetFieldDefn(i)->GetNameRef());
469  }
470 
471  ogrds->ReleaseResultSet(l);
472 
473  return res;
474 }
475 
476 std::size_t te::gpkg::Transactor::getNumberOfProperties(const std::string& datasetName)
477 {
478  //OGRDataSource* ogrds = m_ogrDs->getOGRDataSource();
479  GDALDataset* ogrds = m_ogrDs->getOGRDataSource();
480  if (!ogrds)
481  return 0;
482 
483  std::string sql("SELECT FID, * FROM \"");
484  sql += datasetName + "\"";
485 
486  OGRLayer* l = ogrds->ExecuteSQL(sql.c_str(), 0, 0);
487 
488  int res = 0;
489 
490  if(l != 0)
491  {
492  res = l->GetLayerDefn()->GetFieldCount();
493  ogrds->ReleaseResultSet(l);
494  }
495 
496  return res;
497 }
498 
499 bool te::gpkg::Transactor::propertyExists(const std::string& datasetName, const std::string& name)
500 {
501  //OGRDataSource* ogrds = m_ogrDs->getOGRDataSource();
502  GDALDataset* ogrds = m_ogrDs->getOGRDataSource();
503  if (!ogrds)
504  return false;
505 
506  std::string sql("SELECT FID, * FROM \"");
507  sql += datasetName + "\"";
508  bool res = false;
509 
510  OGRLayer* l = ogrds->ExecuteSQL(sql.c_str(), 0, 0);
511 
512  if(l != 0)
513  {
514  res = (l->GetLayerDefn()->GetFieldIndex(name.c_str()) != -1);
515  ogrds->ReleaseResultSet(l);
516  }
517 
518  return res;
519 }
520 
521 void te::gpkg::Transactor::addProperty(const std::string& datasetName, te::dt::Property* p)
522 {
523  if (!m_ogrDs->getOGRDataSource())
524  return;
525 
526  OGRLayer* l = m_ogrDs->getOGRDataSource()->GetLayerByName(datasetName.c_str());
527 
528  if(l != 0)
529  {
530  if(p->getType() != te::dt::GEOMETRY_TYPE)
531  {
532 // if(!l->TestCapability(OLCCreateField))
533 // throw Exception(TE_TR("This dataset do not support add fields operation."));
534 
535  OGRFieldDefn* nField = Convert2OGR(p);
536  OGRErr error = l->CreateField(nField);
537 
538  delete nField;
539 
540  if(error != OGRERR_NONE)
541  throw Exception(TE_TR("Error when attempting add the property: " + p->getName() + "."));
542 
543  error = l->SyncToDisk();
544 
545  if(error != OGRERR_NONE)
546  throw Exception(TE_TR("Error saving changes on the file."));
547  }
548  }
549 }
550 
551 void te::gpkg::Transactor::dropProperty(const std::string& datasetName, const std::string& name)
552 {
553  OGRLayer* l = m_ogrDs->getOGRDataSource()->GetLayerByName(datasetName.c_str());
554 
555  if(l != 0)
556  {
557  if(!l->TestCapability(OLCDeleteField))
558  throw Exception(TE_TR("This dataset do not support remove properties operation."));
559 
560  int fPos = l->GetLayerDefn()->GetFieldIndex(name.c_str());
561 
562  if(fPos < 0)
563  throw Exception(TE_TR("Field not found."));
564 
565  OGRErr error = l->DeleteField(fPos);
566 
567  if(error != OGRERR_NONE)
568  throw Exception(TE_TR("Error when attempting remove the property."));
569 
570  error = l->SyncToDisk();
571 
572  if(error != OGRERR_NONE)
573  throw Exception(TE_TR("Error saving changes on the file."));
574  }
575 }
576 
577 void te::gpkg::Transactor::renameProperty(const std::string& datasetName,
578  const std::string& propertyName,
579  const std::string& newPropertyName)
580 {
581  if (!m_ogrDs->getOGRDataSource())
582  return;
583 
584  OGRLayer* l = m_ogrDs->getOGRDataSource()->GetLayerByName(datasetName.c_str());
585 
586  if(l != 0)
587  {
588  int idx = l->GetLayerDefn()->GetFieldIndex(propertyName.c_str());
589 
590  if(idx == -1)
591  throw Exception(TE_TR("Field to be renamed does not exists."));
592 
593  OGRFieldDefn* df = l->GetLayerDefn()->GetFieldDefn(idx);
594 
595  OGRFieldDefn* dfn = new OGRFieldDefn(df);
596 
597  dfn->SetName(newPropertyName.c_str());
598 
599  OGRErr err = l->AlterFieldDefn(idx, dfn, ALTER_NAME_FLAG);
600 
601  if(err != OGRERR_NONE)
602  throw Exception(TE_TR("Fail to rename field."));
603  }
604 }
605 
606 void te::gpkg::Transactor::changePropertyDefinition(const std::string& datasetName, const std::string& propName, te::dt::Property* newProp)
607 {
608  if (!m_ogrDs->getOGRDataSource())
609  return;
610 
611  std::auto_ptr<te::dt::Property> p;
612 
613  p.reset(newProp);
614 
615  OGRLayer* l = m_ogrDs->getOGRDataSource()->GetLayerByName(datasetName.c_str());
616 
617  if(l != 0)
618  {
619  if(!l->TestCapability(OLCAlterFieldDefn))
620  throw Exception(TE_TR("This data source do not support the operation of alter columns type."));
621 
622  int idx = l->GetLayerDefn()->GetFieldIndex(propName.c_str());
623 
624  if(idx == -1)
625  throw Exception(TE_TR("Field to be renamed does not exists."));
626 
627  OGRFieldDefn* dfn = new OGRFieldDefn(l->GetLayerDefn()->GetFieldDefn(idx));
628 
629  dfn->SetType(GetOGRType(newProp->getType()));
630 
631  OGRErr err = l->AlterFieldDefn(idx, dfn, ALTER_TYPE_FLAG);
632 
633  if(err != OGRERR_NONE)
634  throw Exception(TE_TR("Fail to to change field type."));
635 
636  //std::string name = m_ogrDs->getOGRDataSource()->GetName();
637  std::string name = m_ogrDs->getOGRDataSource()->GetDescription();
638 
639  err = l->SyncToDisk();
640  }
641 }
642 
643 std::auto_ptr<te::da::PrimaryKey> te::gpkg::Transactor::getPrimaryKey(const std::string& datasetName)
644 {
645  if (!m_ogrDs->getOGRDataSource())
646  return std::auto_ptr<te::da::PrimaryKey>();
647 
648  std::auto_ptr<te::da::PrimaryKey> res;
649  std::string sql("SELECT FID, * FROM \"");
650  sql += datasetName + "\"";
651 
652  OGRLayer* layer = m_ogrDs->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
653 
654  if(layer != 0)
655  {
656  const char* colIdName = layer->GetFIDColumn();
657 
658  if(colIdName == 0 || colIdName[0] == '\0')
659  colIdName = "FID";
660 
661  int pos = layer->GetLayerDefn()->GetFieldIndex(colIdName);
662 
663  if(pos >= 0)
664  {
665  res.reset(new te::da::PrimaryKey);
666  res->add(getProperty(datasetName, pos).get());
667  }
668  }
669 
670  m_ogrDs->getOGRDataSource()->ReleaseResultSet(layer);
671 
672  return res;
673 }
674 
675 bool te::gpkg::Transactor::primaryKeyExists(const std::string& /*datasetName*/, const std::string& /*name*/)
676 {
677  return false;
678 }
679 
680 void te::gpkg::Transactor::addPrimaryKey(const std::string& /*datasetName*/, te::da::PrimaryKey* /*pk*/)
681 {
682 }
683 
684 void te::gpkg::Transactor::dropPrimaryKey(const std::string& /*datasetName*/)
685 {
686 }
687 
688 std::auto_ptr<te::da::ForeignKey> te::gpkg::Transactor::getForeignKey(const std::string& /*datasetName*/, const std::string& /*name*/)
689 {
690  return std::auto_ptr<te::da::ForeignKey>();
691 }
692 
693 std::vector<std::string> te::gpkg::Transactor::getForeignKeyNames(const std::string& /*datasetName*/)
694 {
695  return std::vector<std::string>();
696 }
697 
698 bool te::gpkg::Transactor::foreignKeyExists(const std::string& /*datasetName*/, const std::string& /*name*/)
699 {
700  return false;
701 }
702 
703 void te::gpkg::Transactor::addForeignKey(const std::string& /*datasetName*/, te::da::ForeignKey* /*fk*/)
704 {
705 }
706 
707 void te::gpkg::Transactor::dropForeignKey(const std::string& /*datasetName*/, const std::string& /*fkName*/)
708 {
709 }
710 
711 std::auto_ptr<te::da::UniqueKey> te::gpkg::Transactor::getUniqueKey(const std::string& /*datasetName*/, const std::string& /*name*/)
712 {
713  return std::auto_ptr<te::da::UniqueKey>();
714 }
715 
716 std::vector<std::string> te::gpkg::Transactor::getUniqueKeyNames(const std::string& /*datasetName*/)
717 {
718  return std::vector<std::string>();
719 }
720 
721 bool te::gpkg::Transactor::uniqueKeyExists(const std::string& /*datasetName*/, const std::string& /*name*/)
722 {
723  return false;
724 }
725 
726 void te::gpkg::Transactor::addUniqueKey(const std::string& /*datasetName*/, te::da::UniqueKey* /*uk*/)
727 {
728 }
729 
730 void te::gpkg::Transactor::dropUniqueKey(const std::string& /*datasetName*/, const std::string& /*name*/)
731 {
732 }
733 
734 std::auto_ptr<te::da::CheckConstraint> te::gpkg::Transactor::getCheckConstraint(const std::string& /*datasetName*/, const std::string& /*name*/)
735 {
736  return std::auto_ptr<te::da::CheckConstraint>();
737 }
738 
739 std::vector<std::string> te::gpkg::Transactor::getCheckConstraintNames(const std::string& /*datasetName*/)
740 {
741  return std::vector<std::string>();
742 }
743 
744 bool te::gpkg::Transactor::checkConstraintExists(const std::string& /*datasetName*/, const std::string& /*name*/)
745 {
746  return false;
747 }
748 
749 void te::gpkg::Transactor::addCheckConstraint(const std::string& /*datasetName*/, te::da::CheckConstraint* /*cc*/)
750 {
751 }
752 
753 void te::gpkg::Transactor::dropCheckConstraint(const std::string& /*datasetName*/, const std::string& /*name*/)
754 {
755 }
756 
757 std::auto_ptr<te::da::Index> te::gpkg::Transactor::getIndex(const std::string& /*datasetName*/, const std::string& /*name*/)
758 {
759  return std::auto_ptr<te::da::Index>();
760 }
761 
762 std::vector<std::string> te::gpkg::Transactor::getIndexNames(const std::string& /*datasetName*/)
763 {
764  return std::vector<std::string>();
765 }
766 
767 bool te::gpkg::Transactor::indexExists(const std::string& /*datasetName*/, const std::string& /*name*/)
768 {
769  return false;
770 }
771 
772 void te::gpkg::Transactor::addIndex(const std::string& /*datasetName*/, te::da::Index* /*idx*/,
773  const std::map<std::string, std::string>& /*options*/)
774 {
775 }
776 
777 void te::gpkg::Transactor::dropIndex(const std::string& /*datasetName*/, const std::string& /*idxName*/)
778 {
779 }
780 
781 std::auto_ptr<te::da::Sequence> te::gpkg::Transactor::getSequence(const std::string& /*name*/)
782 {
783  return std::auto_ptr<te::da::Sequence>();
784 }
785 
786 std::vector<std::string> te::gpkg::Transactor::getSequenceNames()
787 {
788  return std::vector<std::string>();
789 }
790 
791 bool te::gpkg::Transactor::sequenceExists(const std::string& /*name*/)
792 {
793  return false;
794 }
795 
797 {
798 }
799 
800 void te::gpkg::Transactor::dropSequence(const std::string& /*name*/)
801 {
802 }
803 
804 std::auto_ptr<te::gm::Envelope> te::gpkg::Transactor::getExtent(const std::string& datasetName,
805  const std::string& propertyName)
806 {
807  if (!m_ogrDs->getOGRDataSource())
808  return std::auto_ptr<te::gm::Envelope>();
809 
810  std::auto_ptr<te::gm::Envelope> res;
811  std::string sql("SELECT ");
812  sql += propertyName + " FROM \"";
813  sql += datasetName + "\"";
814 
815  OGRLayer* l = m_ogrDs->getOGRDataSource()->ExecuteSQL(sql.c_str(), 0, 0);
816 
817  if(l != 0)
818  {
819  std::auto_ptr<OGREnvelope> env(new OGREnvelope);
820 
821  if(l->GetExtent(env.get()) != OGRERR_NONE)
822  {
823  m_ogrDs->getOGRDataSource()->ReleaseResultSet(l);
824  throw Exception(TE_TR("Error when attempting get extent."));
825  }
826 
827  res.reset(Convert2TerraLib(env.get()));
828 
829  m_ogrDs->getOGRDataSource()->ReleaseResultSet(l);
830  }
831 
832  return res;
833 }
834 
835 std::auto_ptr<te::gm::Envelope> te::gpkg::Transactor::getExtent(const std::string& datasetName,
836  std::size_t /*propertyPos*/)
837 {
838  return getExtent(datasetName, "OGR_GEOMETRY");
839 }
840 
841 std::size_t te::gpkg::Transactor::getNumberOfItems(const std::string& datasetName)
842 {
843  if (!m_ogrDs->getOGRDataSource())
844  return 0;
845 
846  OGRLayer* l = m_ogrDs->getOGRDataSource()->GetLayerByName(datasetName.c_str());
847 
848  if(l != 0)
849  return l->GetFeatureCount();
850 
851  return 0;
852 }
853 
855 {
856  if (!m_ogrDs->getOGRDataSource())
857  return false;
858 
859  return (m_ogrDs->getOGRDataSource()->GetLayerCount() > 0);
860 }
861 
862 bool te::gpkg::Transactor::dataSetExists(const std::string& name)
863 {
864  if (!m_ogrDs->getOGRDataSource())
865  return false;
866 
867  return (m_ogrDs->getOGRDataSource()->GetLayerByName(name.c_str()) != 0);
868 }
869 
870 void te::gpkg::Transactor::createDataSet(te::da::DataSetType* dt, const std::map<std::string, std::string>& /*options*/)
871 {
872  if (!m_ogrDs->getOGRDataSource())
873  return;
874 
875  if(!m_ogrDs->getOGRDataSource()->TestCapability(ODsCCreateLayer))
876  throw Exception(TE_TR("This driver does not support dataset creation."));
877 
878  OGRwkbGeometryType geomType = wkbUnknown;
879  OGRSpatialReference* srs = 0;
880  if(dt->hasGeom())
881  {
882  geomType = Convert2OGR(te::da::GetFirstGeomProperty(dt)->getGeometryType());
883  int srid = te::da::GetFirstGeomProperty(dt)->getSRID();
884  if (srid != TE_UNKNOWN_SRS)
885  {
886  srs = Convert2OGRProjection( srid );
887  }
888  }
889 
890  char** papszOptions = 0;
891  std::map<std::string, std::string>::const_iterator it = m_ogrDs->getConnectionInfo().begin();
892  while(it != m_ogrDs->getConnectionInfo().end())
893  {
894  if(it->first == "URI" || it->first == "SOURCE" || it->first == "DRIVER")
895  {
896  ++it;
897  continue;
898  }
899  papszOptions = CSLSetNameValue(papszOptions, it->first.c_str(), it->second.c_str());
900  ++it;
901  }
902 
903  OGRLayer* newLayer = m_ogrDs->getOGRDataSource()->CreateLayer(dt->getName().c_str(), srs, geomType, papszOptions);
904 
905  if(papszOptions)
906  CSLDestroy(papszOptions);
907 
908  if(newLayer == 0)
909  throw Exception(TE_TR("Error when attempting create the dataset type."));
910 
911  dt->setName(newLayer->GetName());
912 
913 // add the properties
914  for(size_t i = 0; i < dt->size(); ++i)
915  addProperty(dt->getName(), dt->getProperty(i));
916 }
917 
918 void te::gpkg::Transactor::cloneDataSet(const std::string& name,
919  const std::string& cloneName,
920  const std::map<std::string, std::string>& /*options*/)
921 {
922  if (!m_ogrDs->getOGRDataSource())
923  return;
924 
925  if(!m_ogrDs->getOGRDataSource()->TestCapability(ODsCCreateLayer))
926  throw Exception(TE_TR("This driver does not support creates a dataset."));
927 
928  OGRLayer* l = m_ogrDs->getOGRDataSource()->GetLayerByName(name.c_str());
929 
930  if(l == 0)
931  throw Exception(TE_TR("Could not retrieve the DataSet from data source."));
932 
933  OGRLayer* cl = m_ogrDs->getOGRDataSource()->CopyLayer(l, cloneName.c_str());
934 
935  if(cl == 0)
936  throw Exception(TE_TR("Error when attempting clone the dataset."));
937 }
938 
939 void te::gpkg::Transactor::dropDataSet(const std::string& name)
940 {
941  if (!m_ogrDs->getOGRDataSource())
942  return;
943 
944  if(!m_ogrDs->getOGRDataSource()->TestCapability(ODsCDeleteLayer))
945  throw Exception(TE_TR("This driver does not support remove a dataset."));
946 
947  int i=0;
948 
949  for(; i<m_ogrDs->getOGRDataSource()->GetLayerCount(); i++)
950  if(name.compare(m_ogrDs->getOGRDataSource()->GetLayer(i)->GetName()) == 0)
951  break;
952 
953  if(i == m_ogrDs->getOGRDataSource()->GetLayerCount())
954  throw Exception(TE_TR("Could not retrieve the DataSet from data source."));
955 
956  if(m_ogrDs->getOGRDataSource()->DeleteLayer(i) != OGRERR_NONE)
957  throw Exception(TE_TR("Error when attempting to remove the dataset."));
958 }
959 
960 void te::gpkg::Transactor::renameDataSet(const std::string& /*name*/, const std::string& /*newName*/)
961 {
962 }
963 
964 void te::gpkg::Transactor::add(const std::string& datasetName,
966  const std::map<std::string, std::string>& options,
967  std::size_t limit)
968 {
969  if(limit == 0)
970  limit = std::string::npos;
971 
972  if (!m_ogrDs->getOGRDataSource())
973  return;
974 
975  OGRLayer* layer = m_ogrDs->getOGRDataSource()->GetLayerByName(datasetName.c_str());
976 
977  if(layer == 0)
978  throw Exception(TE_TR("Could not retrieve the DataSet from data source."));
979 
980  try
981  {
982  begin();
983 
984  std::size_t nproperties = d->getNumProperties();
985 
986  std::size_t nProcessedRows = 0;
987 
988  while(d->moveNext() && (nProcessedRows != limit))
989  {
990  OGRFeature* feat = OGRFeature::CreateFeature(layer->GetLayerDefn());
991 
992  std::size_t currfield = 0;
993 
994  for(std::size_t i = 0; i != nproperties; ++i)
995  {
996  if(d->isNull(i))
997  {
999  ++currfield;
1000 
1001  continue;
1002  }
1003 
1004  if(d->getPropertyName(i) == "FID")
1005  continue;
1006 
1007  switch(d->getPropertyDataType(i))
1008  {
1009  case te::dt::INT16_TYPE:
1010  feat->SetField(currfield, d->getInt16(i));
1011  ++currfield;
1012  break;
1013 
1014  case te::dt::INT32_TYPE:
1015  feat->SetField(currfield, d->getInt32(i));
1016  ++currfield;
1017  break;
1018 
1019  case te::dt::STRING_TYPE:
1020  feat->SetField(currfield, d->getAsString(i).c_str());
1021  ++currfield;
1022  break;
1023 
1024  case te::dt::DOUBLE_TYPE:
1025  feat->SetField(currfield, d->getDouble(i));
1026  ++currfield;
1027  break;
1028 
1029  case te::dt::NUMERIC_TYPE:
1030  feat->SetField(currfield, atof(d->getNumeric(i).c_str()));
1031  ++currfield;
1032  break;
1033 
1035  {
1036  std::auto_ptr<te::dt::ByteArray> ba(d->getByteArray(i));
1037  feat->SetField(currfield, ba->bytesUsed(), reinterpret_cast<unsigned char*>(ba->getData()));
1038  ++currfield;
1039  }
1040  break;
1041 
1042  case te::dt::DATETIME_TYPE:
1043  {
1044  std::auto_ptr<te::dt::DateTime> dtm(d->getDateTime(i));
1045 
1046  te::dt::Date* dtime = dynamic_cast<te::dt::Date*>(dtm.get());
1047 
1048  if(dtime)
1049  {
1050  feat->SetField(currfield,
1051  static_cast<int>(dtime->getYear()),
1052  static_cast<int>(dtime->getMonth()),
1053  static_cast<int>(dtime->getDay()));
1054  ++currfield;
1055  break;
1056  }
1057 
1058  te::dt::TimeDuration* tduration = dynamic_cast<te::dt::TimeDuration*>(dtm.get());
1059 
1060  if(tduration)
1061  {
1062  feat->SetField(currfield, 0, 0, 0,
1063  static_cast<int>(tduration->getHours()),
1064  static_cast<int>(tduration->getMinutes()),
1065  static_cast<int>(tduration->getSeconds()));
1066  ++currfield;
1067  break;
1068  }
1069 
1070  te::dt::TimeInstant* tinst = dynamic_cast<te::dt::TimeInstant*>(dtm.get());
1071 
1072  if(tinst)
1073  {
1074  feat->SetField(currfield,
1075  static_cast<int>(dtime->getYear()),
1076  static_cast<int>(dtime->getMonth()),
1077  static_cast<int>(dtime->getDay()),
1078  static_cast<int>(tduration->getHours()),
1079  static_cast<int>(tduration->getMinutes()),
1080  static_cast<int>(tduration->getSeconds()));
1081  ++currfield;
1082  break;
1083  }
1084 
1085  throw Exception (TE_TR("Unsupported date and time type by OGR."));
1086  }
1087  break;
1088 
1089  case te::dt::GEOMETRY_TYPE:
1090  {
1091  std::auto_ptr<te::gm::Geometry> geom(d->getGeometry(i));
1092  OGRGeometry* OGRgeom = Convert2OGR(geom.get());
1093  feat->SetGeometryDirectly(OGRgeom);
1094  }
1095  break;
1096 
1097  default:
1098  throw Exception(TE_TR("Unsupported data type by OGR."));
1099  }
1100  }
1101 
1102  if(layer->CreateFeature(feat) != OGRERR_NONE)
1103  {
1104  OGRFeature::DestroyFeature(feat);
1105  throw Exception(TE_TR("Fail to insert dataset item."));
1106  }
1107 
1108  m_fid = feat->GetFID();
1109 
1110  OGRFeature::DestroyFeature(feat);
1111  nProcessedRows++;
1112  }
1113 
1114  commit();
1115  }
1116  catch(Exception& e)
1117  {
1118  rollBack();
1119  throw e;
1120  }
1121 }
1122 
1123 void te::gpkg::Transactor::remove(const std::string& datasetName, const te::da::ObjectIdSet* oids)
1124 {
1125  if(!m_ogrDs->getOGRDataSource())
1126  return;
1127 
1128  OGRLayer* l = m_ogrDs->getOGRDataSource()->GetLayerByName(datasetName.c_str());
1129 
1130  if(l == 0)
1131  throw Exception(TE_TR("Could not retrieve the DataSet from data source."));
1132 
1133  if(!l->TestCapability(OLCDeleteFeature))
1134  throw Exception(TE_TR("Driver does not support removal of features."));
1135 
1136  std::set<te::da::ObjectId*, te::common::LessCmp<te::da::ObjectId*> >::const_iterator it = oids->begin();
1137 
1138  begin();
1139 
1140  while(it != oids->end())
1141  {
1142  std::string id = (*it)->getValueAsString();
1143 
1144  if(l->DeleteFeature(atoi(id.c_str())) != OGRERR_NONE)
1145  {
1146  rollBack();
1147  throw Exception(TE_TR("Error when attempting to remove the feature."));
1148  }
1149 
1150  ++it;
1151  }
1152 
1153  l->SyncToDisk();
1154 
1155  commit();
1156 
1157  m_ogrDs->getOGRDataSource()->ExecuteSQL(("REPACK " + datasetName).c_str(), NULL, NULL);
1158 }
1159 
1160 
1161 void te::gpkg::Transactor::update(const std::string& datasetName,
1162  te::da::DataSet* /*dataset*/,
1163  const std::vector<std::size_t>& properties,
1164  const te::da::ObjectIdSet* /*oids*/,
1165  const std::map<std::string, std::string>& /*options*/,
1166  std::size_t /*limit*/)
1167 {
1168 }
1169 
1170 void te::gpkg::Transactor::update(const std::string &datasetName, te::da::DataSet *dataset, const std::vector< std::set<int> >& properties,
1171  const std::vector<size_t>& ids)
1172 {
1173  if(m_ogrDs->getOGRDataSource() == 0)
1174  throw Exception(TE_TR("Data source failure"));
1175 
1176  OGRLayer* l = m_ogrDs->getOGRDataSource()->GetLayerByName(datasetName.c_str());
1177 
1178  if(l == 0)
1179  throw Exception(TE_TR("Could not retrieve dataset"));
1180 
1181  dataset->moveFirst();
1182  int i = 0;
1183 
1184  do
1185  {
1186  size_t id_pos = ids[0];
1187  int id = dataset->getInt32(id_pos);
1188 
1189  OGRFeature* feat = l->GetFeature(id)->Clone();
1190 
1191  std::set<int> ls = properties[i];
1192  std::set<int>::iterator it;
1193 
1194  for(it = ls.begin(); it != ls.end(); ++it)
1195  {
1196  int fpos = *it;
1197  int fpos_o = fpos - 1;
1198 
1199  switch(dataset->getPropertyDataType(fpos))
1200  {
1201  case te::dt::INT32_TYPE:
1202  feat->SetField(fpos_o, dataset->getInt32(fpos));
1203  break;
1204 
1205  case te::dt::DOUBLE_TYPE:
1206  case te::dt::NUMERIC_TYPE:
1207  feat->SetField(fpos_o, dataset->getDouble(fpos));
1208  break;
1209 
1210  case te::dt::STRING_TYPE:
1211  feat->SetField(fpos_o, dataset->getString(fpos).c_str());
1212  break;
1213 
1214  case te::dt::GEOMETRY_TYPE:
1215  {
1216  std::auto_ptr<te::gm::Geometry> gm = dataset->getGeometry(fpos);
1217  feat->SetGeometry(te::gpkg::Convert2OGR(gm.get()));
1218  }
1219  }
1220  }
1221 
1222  l->SetFeature(feat);
1223 
1224  i++;
1225  } while (dataset->moveNext());
1226 
1227  l->SyncToDisk();
1228 }
1229 
1230 void te::gpkg::Transactor::optimize(const std::map<std::string, std::string>& /*opInfo*/)
1231 {
1232 }
1233 
1235 {
1237 }
virtual std::unique_ptr< te::gm::Geometry > getGeometry(std::size_t i) const =0
Method for retrieving a geometric attribute value.
std::auto_ptr< te::gm::Envelope > getExtent(const std::string &datasetName, const std::string &propertyName)
It retrieves the bounding rectangle of the spatial property for the given dataset.
std::auto_ptr< te::dt::Property > getProperty(const std::string &datasetName, const std::string &name)
It retrieves the property with the given name from the dataset.
std::vector< std::string > getUniqueKeyNames(const std::string &datasetName)
It gets the unique key names of the given dataset.
Property * getProperty(std::size_t i) const
It returns the i-th property.
void DataSourceTransactor()
Definition: GDALExample.cpp:92
Geometric property.
void add(te::dt::Property *p)
It adds a property to the list of properties of the primary key.
Definition: PrimaryKey.h:123
virtual double getDouble(std::size_t i) const =0
Method for retrieving a double attribute value.
void rollBack()
It aborts the transaction. Any changes will be rolled-back.
A class that informs what kind of constraint and index is supported by a given data source...
void setSRID(int srid)
It sets the spatial reference system identifier associated to this property.
virtual std::unique_ptr< te::dt::ByteArray > getByteArray(std::size_t i) const =0
Method for retrieving a byte array.
bool dataSetExists(const std::string &name)
It checks if a dataset with the given name exists in the data source.
void dropSequence(const std::string &name)
It removes the sequence from the data source.
void addSequence(te::da::Sequence *sequence)
It creates a new sequence in the data source.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
std::vector< std::string > getSequenceNames()
It gets the sequence names available in the data source.
bool hasGeom() const
It returns true if the DataSetType has at least one geometry property; otherwise, it returns false...
Definition: DataSetType.h:655
void dropUniqueKey(const std::string &datasetName, const std::string &name)
It removes the unique key constraint from the dataset.
std::auto_ptr< te::da::Index > getIndex(const std::string &datasetName, const std::string &name)
It gets the index with the given name from the dataset.
boost::int64_t getLastGeneratedId()
It returns the last id generated by an insertion command.
Base exception class for plugin module.
A class that models the description of a dataset.
Definition: DataSetType.h:72
virtual std::string getNumeric(std::size_t i) const =0
Method for retrieving a numeric attribute value.
long getSeconds() const
It returns the seconds of a minute - from 0 to 59.
Definition: TimeDuration.h:105
void addProperty(const std::string &datasetName, te::dt::Property *p)
It adds a new property to the dataset schema.
std::auto_ptr< te::da::DataSet > query(const te::da::Select &q, te::common::TraverseType travType=te::common::FORWARDONLY, bool connected=false, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It executes a query that may return some data using a generic query. A dataset can be connected or di...
bool hasDataSets()
It checks if the data source has any dataset.
void dropForeignKey(const std::string &datasetName, const std::string &fkName)
It removes the foreign key constraint from the dataset schema.
const std::map< std::string, std::string > & getConnectionInfo() const
void cloneDataSet(const std::string &name, const std::string &cloneName, const std::map< std::string, std::string > &options)
It clones the dataset in the data source.
double m_urx
Upper right corner x-coordinate.
SpatialRelation
Spatial relations between geometric objects.
std::size_t getNumberOfDataSets()
It retrieves the number of data sets available in the data source.
It describes a sequence (a number generator).
virtual ReturnType accept(VisitorType &guest) const =0
It call the visit method from the guest object.
void remove(const std::string &datasetName, const te::da::ObjectIdSet *oids=0)
It removes all the informed items from the dataset.
static te::dt::Date ds(2010, 01, 01)
std::vector< std::string > getPropertyNames(const std::string &datasetName)
It gets the property names of the given dataset.
A class that describes a check constraint.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
bool checkConstraintExists(const std::string &datasetName, const std::string &name)
It checks if a check-constraint with the given name exists in the data source.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
std::vector< std::string > getIndexNames(const std::string &datasetName)
It gets the index names of the given dataset.
std::auto_ptr< te::da::CheckConstraint > getCheckConstraint(const std::string &datasetName, const std::string &name)
It gets the check constraint of the dataset with the given name.
void execute(const te::da::Query &command)
It executes the specified command using a generic query representation.
void addPrimaryKey(const std::string &datasetName, te::da::PrimaryKey *pk)
It adds a primary key constraint to the dataset schema.
It models a property definition.
Definition: Property.h:59
void dropDataSet(const std::string &name)
It removes the dataset schema from the data source.
A class to represent time instant.
Definition: TimeInstant.h:55
void dropProperty(const std::string &datasetName, const std::string &name)
It removes a property from the given dataset.
EncodingType
Supported character encodings.
Definition: CharEncoding.h:50
std::auto_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
std::vector< std::string > getCheckConstraintNames(const std::string &datasetName)
It gets the check constraint names of the given dataset.
virtual bool moveNext()=0
It moves the internal pointer to the next item of the collection.
AccessPolicy
Supported data access policies (can be used as bitfield).
bool propertyExists(const std::string &datasetName, const std::string &name)
It checks if a property with the given name exists in the dataset.
TraverseType
A dataset can be traversed in two ways:
std::vector< std::string > getDataSetNames()
It It gets the dataset names available in the data source.
void setName(const std::string &name)
It sets the property name.
Definition: Property.h:137
const te::da::SQLDialect * getDialect() const
It returns the data source SQL dialect, if there is one.
double m_llx
Lower left corner x-coordinate.
bool uniqueKeyExists(const std::string &datasetName, const std::string &name)
It checks if a unique key with the given name exists in the dataset.
virtual boost::int16_t getInt16(std::size_t i) const =0
Method for retrieving a 16-bit integer attribute value (2 bytes long).
int getSRID() const
It returns the spatial reference system identifier associated to this property.
void dropPrimaryKey(const std::string &datasetName)
It removes the primary key constraint from the dataset schema.
std::string escape(const std::string &value)
It escapes a string for using in commands and queries.
virtual int getPropertyDataType(std::size_t i) const =0
It returns the underlying data type of the property at position pos.
An Envelope defines a 2D rectangular region.
A base class for date data types.
Definition: Date.h:53
std::auto_ptr< te::da::BatchExecutor > getBatchExecutor()
It creates a batch command executor.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
URI C++ Library.
Definition: Attributes.h:37
virtual boost::int32_t getInt32(std::size_t i) const =0
Method for retrieving a 32-bit integer attribute value (4 bytes long).
void DataSet()
static te::dt::DateTime d(2010, 8, 9, 15, 58, 39)
static te::dt::TimeDuration dt(20, 30, 50, 11)
bool foreignKeyExists(const std::string &datasetName, const std::string &name)
It checks if a foreign key with the given name exists in the data source.
std::size_t getNumberOfItems(const std::string &datasetName)
It retrieves the number of items of the given dataset.
std::auto_ptr< te::da::ForeignKey > getForeignKey(const std::string &datasetName, const std::string &name)
It retrieves the foreign key from the given dataset.
std::auto_ptr< te::da::Sequence > getSequence(const std::string &name)
It gets the sequence with the given name in the data source.
TERRAMOBILEPLUGINSDLLEXPORT OGRGeometry * Convert2OGR(const te::gm::Geometry *teGeom)
It converts the TerraLib Geometry to OGR Geometry.
te::gm::Polygon * p
std::auto_ptr< te::da::PreparedQuery > getPrepared(const std::string &qName=std::string(""))
It creates a prepared query object that may be used for query commands (select, insert, update and delete) that are used repeatedly.
It models a foreign key constraint for a DataSetType.
Definition: ForeignKey.h:50
virtual std::string getAsString(std::size_t i, int precision=0) const
Method for retrieving a data value as a string plain representation.
TERRAMOBILEPLUGINSDLLEXPORT std::string RemoveSpatialSql(const std::string &sql)
TERRAMOBILEPLUGINSDLLEXPORT te::gm::Geometry * Convert2TerraLib(OGRGeometry *ogrGeom)
It converts the OGR Geometry to TerraLib Geometry.
void dropIndex(const std::string &datasetName, const std::string &idxName)
It removes the index from the dataset schema.
std::auto_ptr< te::da::DataSet > getDataSet(const std::string &name, te::common::TraverseType travType=te::common::FORWARDONLY, bool connected=false, const te::common::AccessPolicy accessPolicy=te::common::RAccess)
It gets the dataset identified by the given name. A dataset can be connected or disconnected. A connected dataset, after its creation through the data source transactor, continues to depend on the connection given by its associated data source. Differently, a disconnected dataset, after its creation, no more depends of the connection given by the data source, and it continues to live after the connection has been released to the data source.
void cancel()
It requests that the data source stop the processing of the current command.
void optimize(const std::map< std::string, std::string > &opInfo)
For some data access drivers, this method will perform some operations to optimize the data storage...
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.
void add(const std::string &datasetName, te::da::DataSet *d, const std::map< std::string, std::string > &options, std::size_t limit=0)
Utility functions for the data access module.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
A Select models a query to be used when retrieving data from a DataSource.
Definition: Select.h:65
void changePropertyDefinition(const std::string &datasetName, const std::string &propName, te::dt::Property *newProp)
std::vector< std::string > getForeignKeyNames(const std::string &datasetName)
It gets the foreign key names of the given dataset.
void dropCheckConstraint(const std::string &datasetName, const std::string &name)
It removes the check constraint from the dataset.
bool primaryKeyExists(const std::string &datasetName, const std::string &name)
It checks if a primary key exists in the dataset.
double m_lly
Lower left corner y-coordinate.
void renameProperty(const std::string &datasetName, const std::string &propertyName, const std::string &newPropertyName)
It renames a property of the given dataset.
int getType() const
It returns the property data type.
Definition: Property.h:161
void addCheckConstraint(const std::string &datasetName, te::da::CheckConstraint *cc)
It adds a check constraint to the dataset.
virtual std::unique_ptr< te::dt::DateTime > getDateTime(std::size_t i) const =0
Method for retrieving a date and time attribute value.
A dataset is the unit of information manipulated by the data access module of TerraLib.
void addForeignKey(const std::string &datasetName, te::da::ForeignKey *fk)
It adds a foreign key constraint to a dataset.
std::auto_ptr< te::da::DataSetTypeCapabilities > getCapabilities(const std::string &name)
It gets capabilities about a data set.
std::auto_ptr< te::da::PrimaryKey > getPrimaryKey(const std::string &datasetName)
It retrieves the primary key of the dataset.
std::auto_ptr< te::da::UniqueKey > getUniqueKey(const std::string &datasetName, const std::string &name)
It gets the unique key in the dataset with the given name.
bool sequenceExists(const std::string &name)
It checks if a sequence with the given name exists in the data source.
std::size_t getNumberOfProperties(const std::string &datasetName)
It gets the number of properties of the given dataset.
double m_ury
Upper right corner y-coordinate.
std::set< ObjectId *, te::common::LessCmp< ObjectId * > >::const_iterator end() const
Returns an iterator for the object ids in container.
A class to represent time duration with nano-second/micro-second resolution.
Definition: TimeDuration.h:51
It describes a primary key (pk) constraint.
Definition: PrimaryKey.h:52
void update(const std::string &datasetName, te::da::DataSet *dataset, const std::vector< std::size_t > &properties, const te::da::ObjectIdSet *oids, const std::map< std::string, std::string > &options, std::size_t limit=0)
It updates the contents of a dataset for the set of data items.
virtual bool isNull(std::size_t i) const =0
It checks if the attribute value is NULL.
boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset.
void createDataSet(te::da::DataSetType *dt, const std::map< std::string, std::string > &options)
It creates the dataset schema definition in the target data source.
TERRAMOBILEPLUGINSDLLEXPORT int Convert2TerraLibProjection(OGRSpatialReference *osrs)
It converts the OGR Projection to TerraLib Projection.
bool indexExists(const std::string &datasetName, const std::string &name)
It checks if an index with the given name exists in the dataset.
TERRAMOBILEPLUGINSDLLEXPORT OGRSpatialReference * Convert2OGRProjection(int srid)
It converts the TerraLib Projection to OGR Projection.
void addUniqueKey(const std::string &datasetName, te::da::UniqueKey *uk)
It adds a unique key constraint to the dataset.
long getMinutes() const
It returns the minutes of a hour - from 0 to 59.
Definition: TimeDuration.h:98
OGRFieldType GetOGRType(int te_type)
virtual std::size_t getNumProperties() const =0
It returns the number of properties that composes an item of the dataset.
virtual std::string getPropertyName(std::size_t i) const =0
It returns the property name at position pos.
TEDATAACCESSEXPORT te::gm::GeometryProperty * GetFirstGeomProperty(const DataSetType *dt)
std::set< ObjectId *, te::common::LessCmp< ObjectId * > >::const_iterator begin() const
Returns an iterator for the object ids in container.
virtual bool moveFirst()=0
It moves the internal pointer to the first item in the collection.
void addIndex(const std::string &datasetName, te::da::Index *idx, const std::map< std::string, std::string > &options)
It adds an index to the dataset.
bool isInTransaction() const
It returns true if a transaction is in progress, otherwise, it returns false.
A Query is independent from the data source language/dialect.
Definition: Query.h:46
It describes an index associated to a DataSetType.
long getHours() const
It returns the hours of a day - from 0 to 23.
Definition: TimeDuration.h:91
virtual std::string getString(std::size_t i) const =0
Method for retrieving a string value attribute.
te::da::DataSource * getDataSource() const
It returns the parent data source of the transactor.
const std::string & getName() const
It returns the property name.
Definition: Property.h:127
void renameDataSet(const std::string &name, const std::string &newName)
It renames a dataset.