src/terralib/gdal/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 /*!
21  \file terralib/gdal/Transactor.cpp
22 */
23 
24 
25 // Boost
26 #include <boost/algorithm/string.hpp>
27 #include <boost/format.hpp>
28 #include <boost/filesystem.hpp>
29 
30 // TerraLib
31 #include "../common/StringUtils.h"
32 #include "../core/filesystem/FileSystem.h"
33 #include "../core/translator/Translator.h"
34 #include "../dataaccess/dataset/DataSetType.h"
35 #include "../dataaccess/query/DataSetName.h"
36 #include "../dataaccess/query/Select.h"
37 #include "../dataaccess/query/From.h"
38 #include "../dataaccess/query/FromItem.h"
39 #include "../geometry/Envelope.h"
40 #include "../raster/Grid.h"
41 #include "../raster/Raster.h"
42 #include "../raster/RasterProperty.h"
43 #include "DataSet.h"
44 #include "DataSource.h"
45 #include "Exception.h"
46 #include "Transactor.h"
47 #include "Utils.h"
48 #include "DataSetUseCounter.h"
49 
50 // GDAL
51 #include <gdal_priv.h>
52 
53 // STL
54 #include <algorithm>
55 
56 std::unique_ptr<te::da::DataSetType> te::gdal::Transactor::getType(const std::string& dsfullname)
57 {
59 
60  GDALDataset* ds = static_cast<GDALDataset*>(GDALOpen(dsfullname.c_str(), GA_ReadOnly));
61  if (!ds)
62  {
63  return std::unique_ptr<te::da::DataSetType>(nullptr);
64  }
65 
66  te::da::DataSetType* ptr = new te::da::DataSetType("", 0);
67  ptr->setTitle("raster");
68 
69  te::rst::Grid* grid = GetGrid(ds);
70 
71  std::vector<te::rst::BandProperty*> bprops;
72 
73  GetBandProperties(ds, bprops);
74 
76  rp->set(grid);
77  for (size_t i=0; i<bprops.size(); ++i)
78  rp->add(bprops[i]);
79 
80  ptr->add(rp);
81 
82  GDALClose(ds);
83 
84  return std::unique_ptr<te::da::DataSetType>(ptr);
85 }
86 
87 te::gdal::Transactor::Transactor(const std::string& accessInfo)
88 {
89  m_source = accessInfo;
90 }
91 
93 
95 {
96  return nullptr;
97 }
98 
99 void te::gdal::Transactor::getDataSetNames(const std::string& source, std::vector<std::string>& dsnames)
100 {
101 
103  {
104  boost::filesystem::path path(source);
105 
106  std::string upcaseExtension = te::common::Convert2UCase( path.extension().string() );
107  if( upcaseExtension[ 0 ] == '.' ) upcaseExtension = upcaseExtension.substr( 1, upcaseExtension.size() - 1);
108 
109  std::multimap< std::string, std::string > extensionsMap =
111 
112  std::pair< std::multimap< std::string, std::string >::const_iterator,
113  std::multimap< std::string, std::string >::const_iterator > extensionsRangeIts =
114  extensionsMap.equal_range( upcaseExtension );
115 
116  if( extensionsRangeIts.first != extensionsRangeIts.second )
117  {
118  bool subDatasetsSupport = false;
119  std::map< std::string, DriverMetadata >::const_iterator metaIt;
120  while( extensionsRangeIts.first != extensionsRangeIts.second )
121  {
122  metaIt = GetGDALDriversMetadata().find( extensionsRangeIts.first->second );
123 
124  if( metaIt->second.m_subDatasetsSupport )
125  {
126  subDatasetsSupport = true;
127  break;
128  }
129  ++extensionsRangeIts.first;
130  }
131 
132  if( subDatasetsSupport )
133  {
134  DataSetUseCounter dsUseCounter( path.string(), DataSetsManager::MultipleAccessType );
135 
136  GDALDataset* gds = static_cast<GDALDataset*>(GDALOpen(path.string().c_str(), GA_ReadOnly));
137  if (!gds)
138  return;
139 
140  char** subDataSetsMetadataPtr = gds->GetMetadata("SUBDATASETS");
141  if(subDataSetsMetadataPtr == nullptr)
142  {
143  dsnames.push_back(path.filename().string());
144  GDALClose(gds);
145  return;
146  }
147 
148  const int subDataSetsMetadataSize = CSLCount( subDataSetsMetadataPtr );
149  const char* valuePtr = nullptr;
150  char* namePtr = nullptr;
151  std::string nameStr;
152  std::string valueStr;
153  std::string subdsname ;
154 
155  for( int subDataSetsMetadataIdx = 0 ; subDataSetsMetadataIdx < subDataSetsMetadataSize ;
156  ++subDataSetsMetadataIdx )
157  {
158  valuePtr = CPLParseNameValue( subDataSetsMetadataPtr[ subDataSetsMetadataIdx ],
159  &namePtr );
160 
161  nameStr = std::string( namePtr );
162 
163  if( nameStr.find( "_NAME" ) == ( nameStr.size() - 5 ) )
164  {
165  valueStr = std::string( valuePtr );
166  subdsname = GetSubDataSetName(valueStr, te::gdal::GetDriverName(path.string()));
167  dsnames.push_back(subdsname);
168  }
169  }
170 
171  GDALClose(gds);
172  }
173  else
174  {
175  dsnames.push_back(path.leaf().string());
176  return;
177  }
178  }
179  }
180  else if (te::core::FileSystem::isDirectory(source))
181  {
182  boost::filesystem::path path(source);
183 
184  for (boost::filesystem::directory_iterator it(path), itEnd; it !=itEnd; ++it)
185  getDataSetNames(it->path().string(),dsnames);
186  }
187  else
188  {
190 
191  GDALDataset* gds = static_cast<GDALDataset*>(GDALOpen(source.c_str(), GA_ReadOnly));
192  if (!gds)
193  return;
194 
195  dsnames.push_back("pg_raster");
196 
197  GDALClose(gds);
198  return;
199  }
200 
201  return;
202 }
203 
204 std::vector<std::string> te::gdal::Transactor::getDataSetNames()
205 {
206  std::vector<std::string> dsnames;
207 
208  getDataSetNames(m_source, dsnames);
209 
210  return dsnames;
211 }
212 
213 bool te::gdal::Transactor::hasDataSets(const std::string& source)
214 {
215  return (getNumberOfDataSets(source) > 0);
216 }
217 
219 {
220  return hasDataSets(m_source);
221 }
222 
223 size_t te::gdal::Transactor::getNumberOfDataSets(const std::string& source)
224 {
225  std::vector<std::string> dsnames;
226  getDataSetNames(source, dsnames);
227  return dsnames.size();
228 }
229 
231 {
233 }
234 
235 std::unique_ptr<te::da::DataSetType> te::gdal::Transactor::getDataSetType(const std::string& name)
236 {
237  std::string uri;
238  return getDataSetType(m_source, name, uri);
239 }
240 
241 std::unique_ptr<te::da::DataSetType> te::gdal::Transactor::getDataSetType(const std::string& source, const std::string& name, std::string& uri)
242 {
244  {
245  boost::filesystem::path path(source);
246 
247  if (path.leaf() == name)
248  {
249  // it is a regular file and the dataset we expect
250  std::unique_ptr<te::da::DataSetType> dsty = getType(path.string());
251  if (dsty.get())
252  {
253  dsty->setName(name);
254  dsty->setTitle(name);
255  uri = path.string();
256  return dsty;
257  }
258  else
259  return std::unique_ptr<te::da::DataSetType>(nullptr);
260  }
261  else
262  {
263  std::string upcaseExtension = te::common::Convert2UCase( path.extension().string() );
264  if( upcaseExtension[ 0 ] == '.' ) upcaseExtension = upcaseExtension.substr( 1, upcaseExtension.size() - 1);
265 
266  std::multimap< std::string, std::string > extensionsMap =
268 
269  std::pair< std::multimap< std::string, std::string >::const_iterator,
270  std::multimap< std::string, std::string >::const_iterator > extensionsRangeIts =
271  extensionsMap.equal_range( upcaseExtension );
272 
273  if( extensionsRangeIts.first != extensionsRangeIts.second )
274  {
275  bool subDatasetsSupport = false;
276  std::map< std::string, DriverMetadata >::const_iterator metaIt;
277  while( extensionsRangeIts.first != extensionsRangeIts.second )
278  {
279  metaIt = GetGDALDriversMetadata().find( extensionsRangeIts.first->second );
280 
281  if( metaIt->second.m_subDatasetsSupport )
282  {
283  subDatasetsSupport = true;
284  break;
285  }
286  ++extensionsRangeIts.first;
287  }
288 
289  if( subDatasetsSupport )
290  {
292 
293  // it might be one of its sub datasets
294  GDALDataset* gds = static_cast<GDALDataset*>(GDALOpen(path.string().c_str(), GA_ReadOnly));
295  if (!gds)
296  return std::unique_ptr<te::da::DataSetType>(nullptr);
297 
298  char** subdatasets = gds->GetMetadata("SUBDATASETS");
299  if(subdatasets == nullptr)
300  {
301  GDALClose(gds);
302  return std::unique_ptr<te::da::DataSetType>(nullptr); // it has no subdatasets
303  }
304 
305  for(char** i = subdatasets; *i != nullptr; i=i+2)
306  {
307  std::string sds_name = std::string(*i);
308  std::string sds_desc = std::string(*(i+1));
309 
310  unsigned pos = (unsigned)sds_name.find("=");
311  std::string val = sds_name.substr(++pos);
312  if(GetSubDataSetName(val, te::gdal::GetDriverName(path.string())) == name)
313  {
314  GDALClose(gds);
315 
316  uri = val;
317  std::unique_ptr<te::da::DataSetType> dsty = getType(val);
318  dsty->setName(name);
319 
320  pos = (unsigned)sds_desc.find("=");
321  val = sds_desc.substr(++pos);
322  dsty->setTitle(val);
323 
324  return dsty;
325  }
326  }
327  GDALClose(gds);
328  }
329  else
330  {
331  return std::unique_ptr<te::da::DataSetType>(nullptr); // it has no subdatasets
332  }
333  }
334  else
335  {
336  return std::unique_ptr<te::da::DataSetType>(nullptr);
337  }
338  }
339  }
340  else if (te::core::FileSystem::isDirectory(source))
341  {
342  boost::filesystem::path path(source);
343 
344  for (boost::filesystem::directory_iterator it(path), itEnd; it != itEnd; ++it)
345  {
346  std::unique_ptr<te::da::DataSetType> dsty = getDataSetType(it->path().string(),name,uri);
347  if (dsty.get())
348  return dsty;
349  }
350  }
351  else
352  {
353  std::unique_ptr<te::da::DataSetType> dsty = getType(source);
354  if (dsty.get())
355  {
356  dsty->setName(name);
357  dsty->setTitle(name);
358  uri = source;
359  return dsty;
360  }
361  else
362  return std::unique_ptr<te::da::DataSetType>(nullptr);
363  }
364 
365  return std::unique_ptr<te::da::DataSetType>(nullptr);
366 }
367 
368 std::unique_ptr<te::da::DataSet> te::gdal::Transactor::getDataSet(
369  const std::string& name, te::common::TraverseType /*travType*/,
370  bool /*connected*/, const te::common::AccessPolicy accessPolicy)
371 {
372  std::string uri;
373  std::unique_ptr<te::da::DataSetType> dsty = getDataSetType(m_source,name,uri);
374  if (!dsty.get())
375  return std::unique_ptr<te::da::DataSet>(nullptr);
376 
377  return std::unique_ptr<te::da::DataSet>(new DataSet(std::move(dsty),accessPolicy, uri));
378 }
379 
380 std::unique_ptr<te::da::DataSet> te::gdal::Transactor::getDataSet(const std::string& name,
381  const std::string& /*propertyName*/,
382  const te::gm::Envelope* /*e*/,
384  te::common::TraverseType travType,
385  bool connected,
386  const te::common::AccessPolicy accessPolicy)
387 {
388  return getDataSet(name, travType, connected, accessPolicy);
389 }
390 
391 std::unique_ptr<te::da::DataSet> te::gdal::Transactor::getDataSet(const std::string& name,
392  const std::string& /*propertyName*/,
393  const te::gm::Geometry* /*g*/,
395  te::common::TraverseType travType,
396  bool connected,
397  const te::common::AccessPolicy accessPolicy)
398 {
399  return getDataSet(name, travType, connected, accessPolicy);
400 }
401 
402 std::unique_ptr<te::da::DataSet> te::gdal::Transactor::getDataSet(const std::string& name,
403  const te::da::ObjectIdSet* /*oids*/,
404  te::common::TraverseType travType,
405  bool connected,
406  const te::common::AccessPolicy accessPolicy)
407 {
408  return getDataSet(name, travType, connected, accessPolicy);
409 }
410 
411 
412 boost::ptr_vector<te::dt::Property> te::gdal::Transactor::getProperties(const std::string& datasetName)
413 {
414  boost::ptr_vector<te::dt::Property> properties;
415 
416  std::unique_ptr<te::da::DataSetType> dsty = getDataSetType(datasetName);
417  if (!dsty.get())
418  return boost::ptr_vector<te::dt::Property>();
419 
420  const std::vector<te::dt::Property*>& props = dsty->getProperties();
421  for(std::size_t i = 0; i < props.size(); ++i)
422  properties.push_back(props[i]->clone());
423 
424  return properties;
425 }
426 
427 std::unique_ptr<te::dt::Property> te::gdal::Transactor::getProperty(const std::string& datasetName, const std::string& name)
428 {
429  boost::ptr_vector<te::dt::Property> properties;
430 
431  std::unique_ptr<te::da::DataSetType> dsty = getDataSetType(datasetName);
432  if (!dsty.get())
433  return std::unique_ptr<te::dt::Property>(nullptr);
434 
435  const std::vector<te::dt::Property*>& props = dsty->getProperties();
436  for(std::size_t i = 0; i < props.size(); ++i)
437  {
438  if (props[i]->getName() == name)
439  return std::unique_ptr<te::dt::Property>(props[i]->clone());
440  }
441 
442  return std::unique_ptr<te::dt::Property>(nullptr);
443 }
444 
445 std::unique_ptr<te::dt::Property> te::gdal::Transactor::getProperty(const std::string& datasetName, std::size_t propertyPos)
446 {
447  boost::ptr_vector<te::dt::Property> properties;
448 
449  std::unique_ptr<te::da::DataSetType> dsty = getDataSetType(datasetName);
450  if (!dsty.get())
451  return std::unique_ptr<te::dt::Property>(nullptr);
452 
453  const std::vector<te::dt::Property*>& props = dsty->getProperties();
454  if (propertyPos<props.size() && propertyPos>0)
455  return std::unique_ptr<te::dt::Property>(props[propertyPos]->clone());
456 
457  return std::unique_ptr<te::dt::Property>(nullptr);
458 }
459 
460 std::vector<std::string> te::gdal::Transactor::getPropertyNames(const std::string& datasetName)
461 {
462  std::vector<std::string> pNames;
463 
464  std::unique_ptr<te::da::DataSetType> dsty = getDataSetType(datasetName);
465  if (dsty.get())
466  {
467  const std::vector<te::dt::Property*>& props = dsty->getProperties();
468  for(std::size_t i = 0; i < props.size(); ++i)
469  pNames.push_back(props[i]->getName());
470  }
471  return pNames;
472 }
473 
474 std::size_t te::gdal::Transactor::getNumberOfProperties(const std::string& datasetName)
475 {
476  std::unique_ptr<te::da::DataSetType> dsty = getDataSetType(datasetName);
477  if (dsty.get())
478  return dsty->getProperties().size();
479 
480  return 0;
481 }
482 
483 bool te::gdal::Transactor::propertyExists(const std::string& datasetName, const std::string& name)
484 {
485  std::unique_ptr<te::da::DataSetType> dsty = getDataSetType(datasetName);
486  if (dsty.get())
487  {
488  const std::vector<te::dt::Property*>& props = dsty->getProperties();
489  for(std::size_t i = 0; i < props.size(); ++i)
490  if(props[i]->getName()==name)
491  return true;
492  }
493  return false;
494 }
495 
496 bool te::gdal::Transactor::propertyExists(const std::string& datasetName, size_t propertyPos)
497 {
498  std::unique_ptr<te::da::DataSetType> dsty = getDataSetType(datasetName);
499  if (dsty.get())
500  return (propertyPos < dsty->getProperties().size() && propertyPos>0);
501 
502  return false;
503 }
504 
505 std::unique_ptr<te::da::DataSet> te::gdal::Transactor::query(const te::da::Select& q,
507  bool,
508  const te::common::AccessPolicy accessPolicy)
509 {
510  const te::da::From& from = q.from();
511 
512  if (from.empty())
513  throw Exception(TE_TR("Can not process the Select object."));
514 
515  te::da::DataSetName* dsname = static_cast<te::da::DataSetName*>(from[0].clone());
516 
517  if (!dsname)
518  throw Exception(TE_TR("Can not process the Select object."));
519 
520  std::unique_ptr<te::da::DataSetType> dsty = getDataSetType(dsname->getName());
521 
522  delete dsname;
523 
524  if (!dsty.get())
525  throw Exception(TE_TR("Can not process the Select object: dataset not found."));
526 
527  std::string uri = dsty->getTitle();
528  return std::unique_ptr<te::da::DataSet>(new DataSet(std::move(dsty),accessPolicy,uri));
529 }
530 
531 std::unique_ptr<te::da::DataSet> te::gdal::Transactor::query(
532  const std::string& /*query*/, te::common::TraverseType, bool,
533  const te::common::AccessPolicy accessPolicy)
534 {
535  std::vector<std::string> words;
536  std::string s;
537  boost::split(words, s, boost::is_any_of(", "), boost::token_compress_on);
538 
539  std::vector<std::string>::const_iterator it = std::find(words.begin(), words.end(), "FROM");
540  if (it== words.end())
541  it = std::find(words.begin(), words.end(), "from");
542 
543  if (it== words.end())
544  throw Exception(TE_TR("Can not process the query expression."));
545 
546  ++it;
547  if (it== words.end())
548  throw Exception(TE_TR("Can not process the query expression."));
549 
550  std::string dsname = *it;
551 
552  std::unique_ptr<te::da::DataSetType> dsty = getDataSetType(dsname);
553  if (!dsty.get())
554  throw Exception(TE_TR("Can not process the Select object: dataset not found."));
555 
556  std::string uri = dsty->getTitle();
557  return std::unique_ptr<te::da::DataSet>(new DataSet(std::move(dsty),accessPolicy,uri));
558 }
559 
560 bool te::gdal::Transactor::dataSetExists(const std::string& name)
561 {
562  std::unique_ptr<te::da::DataSetType> dsty = getDataSetType(name);
563 
564  return (dsty.get() != nullptr);
565 }
566 
567 std::unique_ptr<te::gm::Envelope> te::gdal::Transactor::getExtent(const std::string& datasetName, std::size_t propertyPos)
568 {
569  std::unique_ptr<te::dt::Property> pp = getProperty(datasetName,propertyPos);
570 
571  if (pp.get())
572  {
573  te::rst::RasterProperty* rp = static_cast<te::rst::RasterProperty*>(pp.get());
574  te::gm::Envelope* env = rp->getGrid()->getExtent();
575  return std::unique_ptr<te::gm::Envelope>(new te::gm::Envelope(env->getLowerLeftX(), env->getLowerLeftY(),
576  env->getUpperRightX(), env->getUpperRightY()));
577  }
578  return std::unique_ptr<te::gm::Envelope>(nullptr);
579 }
580 
581 std::unique_ptr<te::gm::Envelope> te::gdal::Transactor::getExtent(const std::string& datasetName, const std::string& propertyName)
582 {
583  std::unique_ptr<te::dt::Property> pp = getProperty(datasetName,propertyName);
584 
585  if (pp.get())
586  {
587  te::rst::RasterProperty* rp = static_cast<te::rst::RasterProperty*>(pp.get());
588  te::gm::Envelope* env = rp->getGrid()->getExtent();
589  return std::unique_ptr<te::gm::Envelope>(new te::gm::Envelope(env->getLowerLeftX(), env->getLowerLeftY(),
590  env->getUpperRightX(), env->getUpperRightY()));
591  }
592  return std::unique_ptr<te::gm::Envelope>(nullptr);
593 }
594 
596  const std::map<std::string, std::string>& options)
597 {
599  throw Exception(TE_TR("Create operation supported just on directory data sources."));
600 
601  te::rst::RasterProperty* rstp = static_cast<te::rst::RasterProperty*>(dt->getProperty(0));
602 
603  boost::filesystem::path paux(m_source);
604  paux /= dt->getName();
605 
606  if (te::core::FileSystem::isRegularFile(paux.string()))
607  throw Exception((boost::format(TE_TR("This is not a valid file: (\"%1%\")!")) % dt->getName()).str());
608 
609  if (te::core::FileSystem::exists(paux.string()))
610  throw Exception((boost::format(TE_TR("The datasource already has a dataset with this name (\"%1%\")!")) % dt->getName()).str());
611 
612  DataSetUseCounter dsUseCounter( paux.string(), DataSetsManager::SingleAccessType );
613 
614  GDALDataset* gds = te::gdal::CreateRaster(paux.string(), rstp->getGrid(), rstp->getBandProperties(),options);
615 
616  if (!gds)
617  throw Exception(TE_TR("GDAL driver couldn't persist the raster file."));
618 
619  GDALClose(gds);
620 }
621 
623  const std::string& name, const std::string& cloneName,
624  const std::map<std::string, std::string>& /*options*/)
625 {
626  std::unique_ptr<te::da::DataSetType> dsty = getDataSetType(name);
627 
628  if (!dsty.get())
629  throw Exception(TE_TR("Dataset does not exist."));
630 
631  boost::filesystem::path mpath(dsty->getTitle());
632 
633  if (!te::core::FileSystem::isRegularFile(mpath.string()))
634  throw Exception(TE_TR("Can not clone a dataset that it is not a raster file."));
635 
636  boost::filesystem::path newpath(mpath.parent_path() /= cloneName);
637  te::core::FileSystem::copyFile(mpath.string(), newpath.string());
638 
639 }
640 
641 void te::gdal::Transactor::dropDataSet(const std::string& name)
642 {
643  std::unique_ptr<te::da::DataSetType> dsty = getDataSetType(name);
644 
645  if (!dsty.get())
646  throw Exception(TE_TR("Dataset does not exist."));
647 
648  boost::filesystem::path mpath(dsty->getTitle());
649  if (!te::core::FileSystem::isRegularFile(mpath.string()))
650  throw Exception(TE_TR("Can not drop a dataset that it is not a raster file."));
651 
652  te::core::FileSystem::remove(mpath.string());
653 }
654 
655 void te::gdal::Transactor::renameDataSet(const std::string& name, const std::string& newName)
656 {
657  std::unique_ptr<te::da::DataSetType> dsty = getDataSetType(name);
658 
659  if (!dsty.get())
660  throw Exception(TE_TR("Dataset does not exist."));
661 
662  boost::filesystem::path mpath(dsty->getTitle());
663  if (!te::core::FileSystem::isRegularFile(mpath.string()))
664  throw Exception(TE_TR("Can not rename a dataset that it is not a raster file."));
665 
666  boost::filesystem::path newpath(mpath.parent_path() /= newName);
667  te::core::FileSystem::rename(mpath.string(), newpath.string());
668 }
std::vector< std::string > getPropertyNames(const std::string &datasetName)
It gets the property names of the given dataset.
Property * getProperty(std::size_t i) const
It returns the i-th property.
The implementation of a DataSource that consists of datasets that can be decoded by the GDAL Library...
std::multimap< std::string, std::string > GetGDALAllDriversUCaseExt2DriversMap(const bool creationSupport)
Returns a map of all GDAL supported Upper-case ( vector and raster ) extensions to their respective d...
std::unique_ptr< te::da::DataSetType > getDataSetType(const std::string &name)
It gets information about the given dataset.
void set(te::rst::Grid *grid)
Sets the definition of the raster grid support.
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.
static bool exists(const std::string &path)
Checks if a given path in UTF-8 exists.
Definition: FileSystem.cpp:142
static bool isDirectory(const std::string &path)
Checks if a given path in UTF-8 is a directory.
Definition: FileSystem.cpp:87
std::map< std::string, DriverMetadata > & GetGDALDriversMetadata()
Returns metadata from all registered GDAL drivers (key: driver name).
A class that models the name of a dataset used in a From clause.
Definition: DataSetName.h:43
TEGDALEXPORT void GetBandProperties(GDALDataset *gds, std::vector< te::rst::BandProperty * > &bprops)
Gets the list of bands definition from a GDAL dataset.
Base exception class for plugin module.
A class that models the description of a dataset.
Definition: DataSetType.h:72
void renameDataSet(const std::string &name, const std::string &newName)
It renames a dataset.
std::unique_ptr< te::da::DataSetType > getType(const std::string &dsfullname)
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
std::string Convert2UCase(const std::string &value)
It converts a string to upper case.
Definition: StringUtils.h:168
SpatialRelation
Spatial relations between geometric objects.
static te::dt::Date ds(2010, 01, 01)
std::size_t getNumberOfDataSets()
It retrieves the number of data sets available in the data source.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
Raster property.
std::unique_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...
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.
static void rename(const std::string &old_p, const std::string &new_p)
Renames a file or directory from a given path in UTF-8.
Definition: FileSystem.cpp:171
AccessPolicy
Supported data access policies (can be used as bitfield).
TraverseType
A dataset can be traversed in two ways:
GDALDataset * CreateRaster(te::rst::Grid *g, const std::vector< te::rst::BandProperty * > &bands, const std::map< std::string, std::string > &optParams)
Creates a raster data using GDAL.
void add(te::rst::BandProperty *b)
It adds a new band information to the property.
static bool remove(const std::string &path)
Removes a file or directory from a given path in UTF-8.
Definition: FileSystem.cpp:166
bool propertyExists(const std::string &datasetName, const std::string &name)
It checks if a property with the given name exists in the dataset.
An Envelope defines a 2D rectangular region.
bool dataSetExists(const std::string &name)
It checks if a dataset with the given name exists in the data source.
std::vector< std::string > getDataSetNames()
It It gets the dataset names available in the data source.
This class represents a set of unique ids created in the same context. i.e. from the same data set...
Definition: ObjectIdSet.h:55
std::string GetParentDataSetName(const std::string &subDataSetName)
It returns the parent dataset name from a Sub DataSet name.
void DataSet()
static te::dt::TimeDuration dt(20, 30, 50, 11)
boost::ptr_vector< te::dt::Property > getProperties(const std::string &datasetName)
It retrieves the properties of the dataset.
te::da::DataSource * getDataSource() const
It returns the parent data source of the transactor.
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
static void copyFile(const std::string &from, const std::string &to)
Copies a file.
Definition: FileSystem.cpp:159
boost::ptr_vector< FromItem > From
It models the FROM clause for a query.
Definition: From.h:37
std::string GetDriverName(const std::string &dsName)
It returns the GDAL driver name associated to a data source name.
te::rst::Grid * getGrid()
Returns the definition of the raster grid support.
void dropDataSet(const std::string &name)
It removes the dataset schema from the data source.
std::unique_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::unique_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.
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
GDAL data set use counter.
te::gm::Envelope * getExtent()
Returns the geographic extension of the grid.
const std::string & getName() const
It returns the dataset name.
Definition: DataSetName.cpp:55
std::unique_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< te::rst::BandProperty * > & getBandProperties()
Returns a reference to the list of bands definitions.
A rectified grid is the spatial support for raster data.
Definition: raster/Grid.h:68
An exception class for the GDAL module.
std::string GetSubDataSetName(const std::string &name, const std::string &driverName)
It returns the Sub DataSet name from the given name or the same name.
static bool isRegularFile(const std::string &path)
Checks if a given path in UTF-8 is a regular file.
Definition: FileSystem.cpp:98
TEGDALEXPORT te::rst::Grid * GetGrid(GDALDataset *gds)
Gets the grid definition from a GDAL dataset.
std::size_t getNumberOfProperties(const std::string &datasetName)
It gets the number of properties of the given dataset.
Select & from(const FromItem &item)
Definition: Select.cpp:339
Utilitary functions to access GDAL and match some of its concepts to TerraLib concepts.
bool hasDataSets()
It checks if the data source has any dataset.
const std::string & getName() const
It returns the property name.
Definition: Property.h:127
Transactor(const std::string &accessInfo)