src/terralib/gdal/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/gdal/Utils.cpp
22 
23  \brief Utility functions for GDAL.
24 */
25 
26 // TerraLib
27 #include "../common/StringUtils.h"
28 #include "../common/UnitOfMeasure.h"
29 #include "../common/UnitsOfMeasureManager.h"
30 #include "../core/uri/URI.h"
31 #include "../core/uri/Utils.h"
32 #include "../dataaccess/dataset/DataSetType.h"
33 #include "../geometry/Coord2D.h"
34 #include "../geometry/Envelope.h"
35 #include "../geometry/Geometry.h"
36 #include "../ogr/Utils.h"
37 #include "../raster/BandProperty.h"
38 #include "../raster/Grid.h"
39 #include "../raster/RasterFactory.h"
40 #include "../raster/RasterProperty.h"
41 #include "../srs/SpatialReferenceSystemManager.h"
42 #include "Band.h"
43 #include "Exception.h"
44 #include "Raster.h"
45 #include "Utils.h"
46 #include "../core/logger/Logger.h"
47 
48 // STL
49 #include <cmath>
50 #include <cstring>
51 #include <vector>
52 
53 // GDAL
54 #include <gdalwarper.h>
55 #include <ogr_api.h>
56 #include <ogr_spatialref.h>
57 #include <ogrsf_frmts.h>
58 
59 // Boost
60 #include <boost/algorithm/string.hpp>
61 #include <boost/format.hpp>
62 #include <boost/filesystem/path.hpp>
63 #include <boost/filesystem/operations.hpp>
64 #include <boost/graph/graph_concepts.hpp>
65 #include <boost/scoped_array.hpp>
66 
67 #define TL_B_PROP_DESC_KEY "TERRALIB_BAND_PROPERTY_GDAL_DESCRIPTION_KEY_TEXT"
68 #define TL_B_PROP_CATNAME_KEY "TERRALIB_BAND_PROPERTY_GDAL_CATEGORY_NAME_KEY_TEXT"
69 
70 std::string te::gdal::GetSubDataSetName(const std::string& name, const std::string& driverName)
71 {
72  std::vector<std::string> words;
73  boost::split(words, name, boost::is_any_of(":"), boost::token_compress_on);
74 
75  if (words.size() < 3)
76  return name;
77 
78  std::string sdname;
79 
80  if (driverName == "HDF4")
81  {
82  // HDF4_SDS:subdataset_type:file_name:subdataset_index
83  sdname = words[0] + ":" + words[1];
84  if (words.size()>1)
85  sdname = sdname + ":" + words[words.size() - 2] + ":" + words[words.size() - 1];
86  return sdname;
87  }
88  else if (driverName == "NITF")
89  {
90  // NITF_IM:image_index:file_name
91 
92  sdname = words[0] + ":" + words[1];
93  }
94  else if (driverName == "netCDF")
95  {
96  // NETCDF:filename:variable_name
97  sdname = words[0] + ":" + words[2];
98  }
99  else
100  {
101  // From GDAL documentation: "Currently, drivers which support subdatasets are: ADRG, ECRGTOC, GEORASTER,
102  // GTiff, HDF4, HDF5, netCDF, NITF, NTv2, OGDI, PDF, PostGISRaster, Rasterlite,
103  // RPFTOC, RS2, WCS, and WMS.". It seems that the default format is FORMAT:variable:file_name
104  for (size_t i=0; i<words.size()-1;++i)
105  sdname = sdname + ":" + words[i];
106  }
107 
108  return sdname;
109 }
110 
112 {
113  return GetGrid( gds, -1 );
114 }
115 
116 te::rst::Grid* te::gdal::GetGrid(GDALDataset* gds, const int multiResLevel)
117 {
118  if (!gds) return nullptr;
119  if( multiResLevel != -1 )
120  {
121  if( gds->GetRasterCount() <= 0 ) return nullptr;
122  if( multiResLevel >= gds->GetRasterBand( 1 )->GetOverviewCount() ) return nullptr;
123  }
124 
125  // Defining SRID
126 
127  int srid = TE_UNKNOWN_SRS;
128 
129  // The calling of GetProjectionRef isn't thread safe, even for distinct datasets
130  // under some linuxes
131  boost::unique_lock< boost::mutex > lockGuard( getStaticMutex() );
132  const char* projRef = gds->GetProjectionRef();
133  lockGuard.release();
134  getStaticMutex().unlock();
135 
136  if ( ( projRef != nullptr ) && ( std::strlen( projRef ) > 0 ) )
137  {
138  char* projRef2 = (char*)projRef;
139  char** projWKTPtr = &(projRef2);
140  OGRSpatialReference oSRS;
141 
142  OGRErr ogrReturn = oSRS.importFromWkt( projWKTPtr );
143 
144  if( ogrReturn == OGRERR_NONE )
145  {
147  }
148  }
149 
150  // Defining the number of rows / lines
151 
152  unsigned int NRows = 0;
153  unsigned int nCols = 0;
154 
155  if( multiResLevel == -1 )
156  {
157  nCols = (unsigned int)gds->GetRasterXSize();
158  NRows = (unsigned int)gds->GetRasterYSize();
159  }
160  else
161  {
162  nCols = (unsigned int)gds->GetRasterBand( 1 )->GetOverview( multiResLevel )->GetXSize();
163  NRows = (unsigned int)gds->GetRasterBand( 1 )->GetOverview( multiResLevel )->GetYSize();
164  }
165 
166  // Defining bounding box
167 
168  double gtp[6];
169  te::rst::Grid* grid = nullptr;
170 
171  if( gds->GetGeoTransform(gtp) == CE_Failure )
172  {
173  grid = new te::rst::Grid(nCols, NRows, 1.0, 1.0, (te::gm::Envelope*)nullptr, srid);
174  }
175  else
176  {
177  double gridAffineParams[ 6 ];
178  gridAffineParams[ 0 ] = gtp[ 1 ];
179  gridAffineParams[ 1 ] = gtp[ 2 ];
180  gridAffineParams[ 2 ] = gtp[ 0 ] + ( gtp[ 1 ] / 2.0 );
181  gridAffineParams[ 3 ] = gtp[ 4 ];
182  gridAffineParams[ 4 ] = gtp[ 5 ];
183  gridAffineParams[ 5 ] = gtp[ 3 ] + ( gtp[ 5 ] / 2.0 );
184 
185  if( multiResLevel == -1 )
186  {
187  grid = new te::rst::Grid(gridAffineParams, nCols, NRows, srid);
188  }
189  else
190  {
191  te::rst::Grid tempGrid(gridAffineParams, (unsigned int)gds->GetRasterXSize(),
192  (unsigned int)gds->GetRasterYSize(), srid);
193  grid = new te::rst::Grid( nCols, NRows, new te::gm::Envelope( *tempGrid.getExtent() ), srid );
194  }
195  }
196 
197  return grid;
198 }
199 
200 void te::gdal::GetBandProperties(GDALDataset* gds, std::vector<te::rst::BandProperty*>& bprops)
201 {
202  if (!gds)
203  return;
204 
205  bprops.clear();
206 
207  int nBands = 0;
208 
209  if( gds->GetRasterCount() > 0 )
210  {
211  nBands = gds->GetRasterCount();
212  }
213 
214  // retrieve the information about each band
215  for (int rasterIdx = 0; rasterIdx < nBands ; ++rasterIdx)
216  {
217  GDALRasterBand* rasterBand = gds->GetRasterBand( ( 1 + rasterIdx) );
218  bprops.push_back( GetBandProperty( rasterBand, rasterIdx ) );
219  }
220 }
221 
223  const unsigned int bandIndex )
224 {
225  if (!gband)
226  return nullptr;
227 
228  std::unique_ptr< te::rst::BandProperty > bprop( new te::rst::BandProperty(
229  gband->GetBand()-1, GetTeDataType(gband->GetRasterDataType()), "") );
230 
231  bprop->m_idx = bandIndex;
232 
233  // te::rst::BandProperty* rb = new te::rst::BandProperty(rasterIdx, dt);
234  bprop->m_colorInterp = GetTeColorInterpretation(gband->GetColorInterpretation());
235 
236  if( bprop->m_colorInterp == te::rst::PaletteIdxCInt )
237  {
238  GDALColorTable * gdalColorTablePtr = gband->GetColorTable();
239 
240  if( gdalColorTablePtr )
241  {
242  switch( gdalColorTablePtr->GetPaletteInterpretation() )
243  {
244  case GPI_Gray :
245  {
246  bprop->m_paletteInterp = te::rst::GrayPalInt;
247  break;
248  }
249  case GPI_RGB : // RGBA
250  {
251  bprop->m_paletteInterp = te::rst::RGBPalInt;
252  break;
253  }
254  case GPI_CMYK :
255  {
256  bprop->m_paletteInterp = te::rst::CMYKPalInt;
257  break;
258  }
259  case GPI_HLS :
260  {
261  bprop->m_paletteInterp = te::rst::HSLPalInt;
262  break;
263  }
264  default :
265  {
266  throw Exception(TE_TR("invalid palette interpretation"));
267  break;
268  }
269  }
270 
271  te::rst::BandProperty::ColorEntry auxTLColorEntry;
272 
273  for( int cTableIdx = 0 ; cTableIdx < gdalColorTablePtr->GetColorEntryCount() ;
274  ++cTableIdx )
275  {
276  auxTLColorEntry.c1 = (short)gdalColorTablePtr->GetColorEntry( cTableIdx )->c1;
277  auxTLColorEntry.c2 = (short)gdalColorTablePtr->GetColorEntry( cTableIdx )->c2;
278  auxTLColorEntry.c3 = (short)gdalColorTablePtr->GetColorEntry( cTableIdx )->c3;
279  auxTLColorEntry.c4 = (short)gdalColorTablePtr->GetColorEntry( cTableIdx )->c4;
280 
281  bprop->m_palette.push_back( auxTLColorEntry );
282  }
283 
284  }
285  }
286 
287  // find if there is a no data value
288 
289  int noDataValueIsUsed = 0;
290  double nodataval = gband->GetNoDataValue(&noDataValueIsUsed);
291  if (noDataValueIsUsed)
292  bprop->m_noDataValue = nodataval;
293 
294  // category names
295 
296  bool categoryNamesLoaded = false;
297 
298  {
299  char** categoriesListPtr = gband->GetCategoryNames();
300 
301  if( categoriesListPtr )
302  {
303  const int categoriesListSize = CSLCount( categoriesListPtr );
304 
305  for( int categoriesListIdx = 0 ; categoriesListIdx < categoriesListSize ;
306  ++categoriesListIdx )
307  {
308  bprop->m_categoryNames.push_back( std::string(
309  categoriesListPtr[ categoriesListIdx ] ) );
310 
311  categoryNamesLoaded = true;
312  }
313  }
314  }
315 
316  // Description
317 
318  bool descriptionLoaded = false;
319 
320  if( gband->GetDescription() )
321  {
322  bprop->m_description = std::string( gband->GetDescription() );
323 
324  descriptionLoaded = true;
325  }
326 
327  // Metadata & Description
328 
329  {
330  char** metadataDomainListPtr = gband->GetMetadataDomainList();
331 
332  char** metadataListPtr = gband->GetMetadata( ( metadataDomainListPtr ?
333  metadataDomainListPtr[ 0 ] : nullptr ) );
334 
335  if( metadataListPtr )
336  {
337  const int metadataListSize = CSLCount( metadataListPtr );
338  char* namePtr = nullptr;
339  const char* valuePtr = nullptr;
340  const std::size_t catNameKeySize = std::strlen( TL_B_PROP_CATNAME_KEY );
341 
342  for( int metadataListIdx = 0 ; metadataListIdx < metadataListSize ;
343  ++metadataListIdx )
344  {
345  valuePtr = CPLParseNameValue( metadataListPtr[ metadataListIdx ],
346  &namePtr );
347 
348  if( std::strcmp( namePtr, TL_B_PROP_DESC_KEY ) == 0 )
349  {
350  if( descriptionLoaded == false )
351  {
352  bprop->m_description = std::string( valuePtr );
353  }
354  }
355  else if( std::strncmp( namePtr, TL_B_PROP_CATNAME_KEY, catNameKeySize ) == 0 )
356  {
357  if( categoryNamesLoaded == false )
358  {
359  bprop->m_categoryNames.push_back( std::string( valuePtr ) );
360  }
361  }
362  else
363  {
364  bprop->m_metadata.push_back( std::pair<std::string, std::string>(
365  std::string( namePtr ), std::string( valuePtr ) ) );
366  }
367 
368  VSIFree( namePtr );
369  }
370  }
371 
372  if( metadataDomainListPtr ) CSLDestroy( metadataDomainListPtr );
373  }
374 
375  // unit
376 
377  std::string unitName = gband->GetUnitType();
378  if (!unitName.empty())
379  bprop->setUnitOfMeasure(te::common::UnitsOfMeasureManager::getInstance().find(unitName));
380 
381  // scale and offset
382 
383  bprop->m_valuesOffset = gband->GetOffset(nullptr);
384  bprop->m_valuesScale = gband->GetScale(nullptr);
385 
386  // blocking scheme
387 
388  gband->GetBlockSize(&bprop->m_blkw, &bprop->m_blkh);
389  bprop->m_nblocksx = (gband->GetXSize() + bprop->m_blkw - 1) / bprop->m_blkw;
390  bprop->m_nblocksy = (gband->GetYSize() + bprop->m_blkh - 1) / bprop->m_blkh;
391 
392  // statistics
393 
394  double min = 0;
395  double max = 0;
396  double mean = 0;
397  double stdDev = 0;
398 
399  if( gband->GetStatistics( false, false, &min, &max, &mean, &stdDev ) == CE_None )
400  {
401  bprop->m_min = min;
402  bprop->m_max = max;
403  bprop->m_mean = mean;
404  bprop->m_stdDev = stdDev;
405  }
406 
407  return bprop.release();
408 }
409 
410 void te::gdal::GetBands(te::gdal::Raster* rst, std::vector<te::gdal::Band*>& bands)
411 {
412  if( !GetBands( rst, -1, bands ) )
413  {
414  throw Exception(TE_TR("Internal error"));
415  }
416 }
417 
418 bool te::gdal::GetBands(te::gdal::Raster* rst, int multiResLevel, std::vector<te::gdal::Band*>& bands)
419 {
420  bands.clear();
421 
422  if( rst == nullptr ) return false;
423 
424  GDALDataset* gds = rst->getGDALDataset();
425 
426  if( gds == nullptr ) return false;
427 
428  if( ( gds->GetAccess() != GA_ReadOnly ) && ( gds->GetAccess() != GA_Update ) )
429  return false;
430 
431  // Defining the number of bands
432 
433  int terralibBandsNumber = 0;
434 
435  if( gds->GetRasterCount() > 0 )
436  {
437  terralibBandsNumber = rst->getGDALDataset()->GetRasterCount();
438  }
439 
440  // Creating terralib bands
441 
442  int gdalBandIndex = 1;
443  for (int terralibBandIndex = 0; terralibBandIndex < terralibBandsNumber; terralibBandIndex++)
444  {
445  if( multiResLevel == -1 )
446  {
447  bands.push_back(
448  new te::gdal::Band(
449  rst,
450  terralibBandIndex,
451  rst->getGDALDataset()->GetRasterBand( gdalBandIndex )
452  )
453  );
454  }
455  else
456  {
457  if( multiResLevel < gds->GetRasterBand( gdalBandIndex )->GetOverviewCount() )
458  {
459  bands.push_back(
460  new te::gdal::Band(
461  rst,
462  terralibBandIndex,
463  gds->GetRasterBand( gdalBandIndex )->GetOverview( multiResLevel )
464  )
465  );
466  }
467  else
468  {
469  while( ! bands.empty() )
470  {
471  delete( bands.back() );
472  bands.pop_back();
473  }
474 
475  return false;
476  }
477  }
478 
479  ++gdalBandIndex;
480  }
481 
482  return true;
483 }
484 
486 {
487  GDALDataset* gds = (GDALDataset*) GDALOpen(strAccessInfo.c_str(), GA_ReadOnly);
488  if (!gds)
489  return nullptr;
490 
491  te::rst::Grid* grid = GetGrid(gds);
492 
493  std::vector<te::rst::BandProperty*> bprops;
494 
495  te::gdal::GetBandProperties(gds, bprops);
496 
497  std::map<std::string, std::string> rinfo;
498 
499  te::rst::RasterProperty* rp = new te::rst::RasterProperty(grid, bprops, rinfo);
500 
501  GDALClose(gds);
502 
503  return rp;
504 }
505 
506 te::gm::Envelope* te::gdal::GetExtent(std::string strAccessInfo)
507 {
508  GDALDataset* gds = (GDALDataset*) GDALOpen(strAccessInfo.c_str(), GA_ReadOnly);
509  if (!gds)
510  return nullptr;
511  te::rst::Grid* grid = te::gdal::GetGrid(gds);
512  GDALClose(gds);
513  te::gm::Envelope* ext = new te::gm::Envelope(*grid->getExtent());
514  delete grid;
515  return ext;
516 }
517 
518 GDALDataset* te::gdal::CreateRaster(const std::string& name, te::rst::Grid* g, const std::vector<te::rst::BandProperty*>& bands,
519  const std::map<std::string, std::string>& optParams)
520 {
521  std::string driverName = GetDriverName(name);
522 
523  GDALDriverManager* dManPtr = GetGDALDriverManager();
524 
525  GDALDriver* driverPtr = dManPtr->GetDriverByName(driverName.c_str());
526 
527  if(!driverPtr)
528  throw Exception("Could not create raster because the underlying driver was not found!");
529 
530  GDALDataType targetGDataType = te::gdal::GetGDALDataType(bands[0]->m_type);
531 
532  if (targetGDataType == GDT_Unknown)
533  throw Exception("Could not create raster because of unknown band data type!");
534 
535  char** papszOptions = nullptr;
536 
537  std::map<std::string, std::string>::const_iterator it = optParams.begin();
538 
539  std::map<std::string, std::string>::const_iterator it_end = optParams.end();
540 
541  while(it != it_end)
542  {
543  if(it->first == "URI" || it->first == "SOURCE")
544  {
545  ++it;
546 
547  continue;
548  }
549 
550  papszOptions = CSLSetNameValue(papszOptions, it->first.c_str(), it->second.c_str());
551 
552  ++it;
553  }
554 
555  GDALDataset* poDataset;
556 
557  if (driverName == "JPEG" || driverName == "PNG")
558  {
559  GDALDriver* tmpDriverPtr = dManPtr->GetDriverByName("MEM");
560 
561  poDataset = tmpDriverPtr->Create(name.c_str(),
562  g->getNumberOfColumns(),
563  g->getNumberOfRows(),
564  static_cast<int>(bands.size()),
565  targetGDataType,
566  papszOptions);
567  }
568  else
569  poDataset = driverPtr->Create(name.c_str(),
570  g->getNumberOfColumns(),
571  g->getNumberOfRows(),
572  static_cast<int>(bands.size()),
573  targetGDataType,
574  papszOptions);
575 
576  if(papszOptions)
577  CSLDestroy(papszOptions);
578 
579  if(poDataset == nullptr)
580  throw Exception("Could not create raster!");
581 
582  const double* gridAffineParams = g->getGeoreference();
583 
584  double gtp[6];
585 
586  gtp[0] = gridAffineParams[2] - ( gridAffineParams[ 0 ] / 2.0 );
587  gtp[1] = gridAffineParams[0];
588  gtp[2] = gridAffineParams[1];
589  gtp[3] = gridAffineParams[5] - ( gridAffineParams[ 4 ] / 2.0 );
590  gtp[4] = gridAffineParams[3];
591  gtp[5] = gridAffineParams[4];
592 
593  poDataset->SetGeoTransform(gtp);
594 
595  OGRSpatialReference oSRS;
596 
597  OGRErr osrsErrorReturn = oSRS.importFromEPSG(g->getSRID());
598  CPLErr setProjErrorReturn = CE_Fatal;
599 
600  if( osrsErrorReturn == OGRERR_NONE )
601  {
602  // try to use a proj4 string
603 
604  char* proj4Ptr = nullptr;
605 
606  osrsErrorReturn = oSRS.exportToProj4(&proj4Ptr);
607 
608  if( osrsErrorReturn == OGRERR_NONE )
609  {
610  setProjErrorReturn = poDataset->SetProjection(proj4Ptr);
611  }
612 
613  CPLFree(proj4Ptr);
614 
615  // try to use a wkt string
616 
617  if( setProjErrorReturn != CE_None )
618  {
619  char* projWKTPtr = nullptr;
620 
621  osrsErrorReturn = oSRS.exportToWkt(&projWKTPtr);
622 
623  if( osrsErrorReturn == OGRERR_NONE )
624  {
625  setProjErrorReturn = poDataset->SetProjection(projWKTPtr);
626  }
627 
628  CPLFree(projWKTPtr);
629  }
630  }
631 
632  if( setProjErrorReturn != CE_None )
633  {
634  std::string proj4Str = te::srs::SpatialReferenceSystemManager::getInstance().getP4Txt(
635  g->getSRID() );
636 
637  if( !proj4Str.empty() )
638  {
639  setProjErrorReturn = poDataset->SetProjection(proj4Str.c_str());
640  }
641  }
642 
643  if( setProjErrorReturn != CE_None )
644  {
645  std::string wktStr = te::srs::SpatialReferenceSystemManager::getInstance().getWkt(
646  g->getSRID() );
647 
648  if( !wktStr.empty() )
649  {
650  setProjErrorReturn = poDataset->SetProjection(wktStr.c_str());
651  }
652  }
653 
654  int nb = static_cast<int>(bands.size());
655 
656  for(int dIdx = 0; dIdx < nb; ++dIdx)
657  {
658  GDALRasterBand* rasterBand = poDataset->GetRasterBand(1 + dIdx);
659 
660  GDALColorInterp ci = te::gdal::GetGDALColorInterpretation(bands[dIdx]->m_colorInterp);
661 
662  rasterBand->SetColorInterpretation(ci);
663 
664  if (ci == GCI_PaletteIndex)
665  {
666  GDALColorTable* gCTablePtr = new GDALColorTable(GPI_RGB);
667  GDALColorEntry gCEntry;
668 
669  for (unsigned int pIdx=0 ; pIdx < bands[dIdx]->m_palette.size(); ++pIdx)
670  {
671  gCEntry.c1 = (short)bands[dIdx]->m_palette[pIdx].c1;
672  gCEntry.c2 = (short)bands[dIdx]->m_palette[pIdx].c2;
673  gCEntry.c3 = (short)bands[dIdx]->m_palette[pIdx].c3;
674  gCEntry.c4 = (short)bands[dIdx]->m_palette[pIdx].c4;
675  gCTablePtr->SetColorEntry(pIdx, &gCEntry);
676  }
677 
678  rasterBand->SetColorTable(gCTablePtr);
679  delete gCTablePtr;
680  }
681  rasterBand->SetNoDataValue(bands[dIdx]->m_noDataValue);
682  rasterBand->SetOffset(bands[dIdx]->m_valuesOffset.real());
683  rasterBand->SetScale(bands[dIdx]->m_valuesScale.real());
684 
685  // category names
686 
687  bool categoryNamesSaved = false;
688 
689  {
690  char** categoryNamesListPtr = nullptr;
691 
692  for( std::size_t categoryNamesIdx = 0 ; categoryNamesIdx <
693  bands[ dIdx ]->m_categoryNames.size() ; ++categoryNamesIdx )
694  {
695  if( ! bands[ dIdx ]->m_categoryNames[ categoryNamesIdx ].empty() )
696  {
697  categoryNamesListPtr = CSLAddString( categoryNamesListPtr,
698  bands[ dIdx ]->m_categoryNames[ categoryNamesIdx ].c_str() );
699  }
700  }
701 
702  if( categoryNamesListPtr )
703  {
704  if( rasterBand->SetCategoryNames( categoryNamesListPtr ) == CE_None )
705  {
706  categoryNamesSaved = true;
707  }
708 
709  CSLDestroy(categoryNamesListPtr);
710  }
711  }
712 
713  // Description
714 
715  if( ! bands[ dIdx ]->m_description.empty() )
716  {
717  rasterBand->SetDescription( bands[ dIdx ]->m_description.c_str() );
718  }
719 
720  // Metadata
721 
722  {
723  char** metadataListPtr = nullptr;
724 
725  // If categoy names saving failed, it will be saved as metadata
726 
727  if(
728  ( ! bands[ dIdx ]->m_categoryNames.empty() )
729  &&
730  ( categoryNamesSaved == false )
731  )
732  {
733  for( std::size_t categoryNamesIdx = 0 ; categoryNamesIdx <
734  bands[ dIdx ]->m_categoryNames.size() ; ++categoryNamesIdx )
735  {
736  if( ! bands[ dIdx ]->m_categoryNames[ categoryNamesIdx ].empty() )
737  {
738  metadataListPtr = CSLAddNameValue( metadataListPtr,
739  ( std::string( TL_B_PROP_CATNAME_KEY ) +
740  boost::lexical_cast< std::string >( categoryNamesIdx ) ).c_str(),
741  bands[ dIdx ]->m_categoryNames[ categoryNamesIdx ].c_str() );
742  }
743  }
744  }
745 
746  // Band description will be also saved as metadata
747 
748  if( ! bands[ dIdx ]->m_description.empty() )
749  {
750  metadataListPtr = CSLAddNameValue( metadataListPtr,
752  bands[ dIdx ]->m_description.c_str() );
753  }
754 
755  // Other metadata
756 
757  for( std::size_t metadataIdx = 0 ; metadataIdx <
758  bands[ dIdx ]->m_metadata.size() ; ++metadataIdx )
759  {
760  if( !
761  ( bands[ dIdx ]->m_metadata[ metadataIdx ].first.empty() )
762  ||
763  ( bands[ dIdx ]->m_metadata[ metadataIdx ].second.empty() )
764  )
765  {
766  metadataListPtr = CSLAddString( metadataListPtr,
767  ( bands[ dIdx ]->m_metadata[ metadataIdx ].first + "=" +
768  bands[ dIdx ]->m_metadata[ metadataIdx ].second ).c_str() );
769  }
770  }
771 
772  if( metadataListPtr )
773  {
774  char** metadataDomainListPtr = rasterBand->GetMetadataDomainList();
775 
776  rasterBand->SetMetadata( metadataListPtr, ( metadataDomainListPtr ?
777  metadataDomainListPtr[ 0 ] : nullptr ) );
778  CSLDestroy(metadataListPtr);
779 
780  if( metadataDomainListPtr ) CSLDestroy( metadataDomainListPtr );
781  }
782  }
783 
784  // Statistics
785 
786  if(
787  ( bands[dIdx]->m_min != std::numeric_limits<double>::max() )
788  ||
789  ( bands[dIdx]->m_max != std::numeric_limits<double>::max() )
790  ||
791  ( bands[dIdx]->m_mean != std::numeric_limits<double>::max() )
792  ||
793  ( bands[dIdx]->m_stdDev != std::numeric_limits<double>::max() )
794  )
795  {
796  rasterBand->SetStatistics( bands[dIdx]->m_min, bands[dIdx]->m_max,
797  bands[dIdx]->m_mean, bands[dIdx]->m_stdDev );
798  }
799  }
800 
801  return poDataset;
802 
803 }
804 
806  const std::vector<te::rst::BandProperty*>& bands,
807  const std::map<std::string, std::string>& optParams)
808 {
809  assert(g);
810  assert(bands.size() > 0);
811 
812  std::string accessInfo = GetGDALConnectionInfo(optParams);
813  return te::gdal::CreateRaster(accessInfo, g, bands, optParams);
814 }
815 
816 GDALDataset* te::gdal::GetRasterHandle(const std::string strAccessInfo, te::common::AccessPolicy policy)
817 {
818  GDALAccess gpolicy = GA_ReadOnly;
819 
820  if(policy == te::common::WAccess || policy == te::common::RWAccess)
821  gpolicy = GA_Update;
822 
823  GDALDataset* gds = (GDALDataset*) GDALOpen(strAccessInfo.c_str(), gpolicy);
824 
825  return gds;
826 }
827 
828 std::string te::gdal::MakePGConnectionStr(const te::core::URI& connInfo)
829 {
830  /*PG":host='<host>' port:'<port>' dbname='<dbname>' user='<user>' password='<password>' [schema='<schema>'] [table='<raster_table>'] [where='<sql_where>'] [mode='<working_mode>']"*/
831 
832  std::string aux;
833  std::string connStr = "PG:";
834 
835  std::map<std::string, std::string> kvp = te::core::Expand(connInfo.query());
836  std::map<std::string, std::string>::const_iterator it = kvp.begin();
837  std::map<std::string, std::string>::const_iterator itend = kvp.end();
838 
839  aux = connInfo.host();
840  if (!aux.empty())
841  connStr += "host=" + aux;
842 
843  aux = connInfo.port();
844  if (!aux.empty())
845  connStr += " port=" + aux;
846 
847  aux = te::core::URIDecode(connInfo.path().substr(1, connInfo.path().length()));
848  if (!aux.empty())
849  {
850  connStr += " dbname='" + aux;
851  connStr += "'";
852  }
853 
854  aux = connInfo.user();
855  if (!aux.empty())
856  {
857  connStr += " user='" + aux;
858  connStr += "'";
859  }
860 
861  aux = connInfo.password();
862  if (!aux.empty())
863  {
864  connStr += " password='" + aux;
865  connStr += "'";
866  }
867 
868 
869  it = kvp.find("schema");
870  if (it != itend && !it->second.empty())
871  {
872  connStr += " schema='" + it->second;
873  connStr += "'";
874  }
875 
876  it = kvp.find("table");
877  if (it != itend && !it->second.empty())
878  connStr += " table=" + it->second;
879 
880  it = kvp.find("where");
881  if (it != itend && !it->second.empty())
882  connStr += " where = " + it->second;
883 
884  it = kvp.find("mode");
885  if (it != itend && !it->second.empty())
886  connStr += " mode=" + it->second;
887 
888  return connStr;
889 }
890 
891 bool te::gdal::RecognizesSRID(unsigned int srid)
892 {
893  OGRSpatialReference oSRS;
894  oSRS.importFromEPSG(srid);
895  char* coutWKT = nullptr;
896  oSRS.exportToWkt(&coutWKT);
897  std::string outwkt(coutWKT);
898  return (!outwkt.empty());
899 }
900 
901 /* This function is based on the WARP tutorial in http://www.gdal.org */
903 {
904  assert(rin);
905  assert(rout);
906 
907  te::gdal::Raster const* grin = static_cast<te::gdal::Raster const *>(rin);
908  te::gdal::Raster* grout = static_cast<te::gdal::Raster*>(rout);
909 
910  GDALDatasetH hSrcDS = grin->getGDALDataset();
911  if (hSrcDS == nullptr)
912  return false;
913 
914  GDALDatasetH hDstDS = grout->getGDALDataset();
915  if (hDstDS == nullptr)
916  return false;
917 
918  int nBands = GDALGetRasterCount(hSrcDS);
919 
920  /* Define warp options */
921  GDALWarpOptions *psWarpOptions = GDALCreateWarpOptions();
922  psWarpOptions->hSrcDS = hSrcDS;
923  psWarpOptions->hDstDS = hDstDS;
924  psWarpOptions->nBandCount = nBands;
925  psWarpOptions->panSrcBands = (int*)CPLMalloc(sizeof(int)*psWarpOptions->nBandCount);
926  psWarpOptions->panDstBands = (int*)CPLMalloc(sizeof(int)*psWarpOptions->nBandCount);
927  for (int b = 0; b < psWarpOptions->nBandCount; b++)
928  {
929  psWarpOptions->panSrcBands[b] = b+1;
930  psWarpOptions->panDstBands[b] = b+1;
931  }
932 
933  /* Establish reprojection transformer */
934  psWarpOptions->pTransformerArg = GDALCreateGenImgProjTransformer(hSrcDS, GDALGetProjectionRef(hSrcDS),
935  hDstDS, GDALGetProjectionRef(hDstDS),
936  FALSE, 0.0, 1);
937  psWarpOptions->pfnTransformer = GDALGenImgProjTransform;
938 
939  /* Initialize and execute the warp operation */
940  GDALWarpOperation oOperation;
941  oOperation.Initialize(psWarpOptions);
942  oOperation.WarpRegion(0, 0, GDALGetRasterXSize(hDstDS), GDALGetRasterYSize(hDstDS));
943 
944  /* Close transformer and images */
945  GDALDestroyGenImgProjTransformer(psWarpOptions->pTransformerArg);
946  GDALDestroyWarpOptions(psWarpOptions);
947 
948  return true;
949 }
950 
951 std::string te::gdal::GetDriverName(const std::string& name)
952 {
953 // check if it is a filename, and tries to use its extension
954  boost::filesystem::path mpath(name.c_str());
955 
956  std::string ext = te::common::Convert2UCase(mpath.extension().string());
957  if( ext[ 0 ] == '.' ) ext = ext.substr( 1, ext.size() - 1);
958 
959  std::multimap< std::string, std::string > extensionsMap = GetGDALAllDriversUCaseExt2DriversMap(
960  false );
961 
962  std::multimap< std::string, std::string >::const_iterator exttMapIt =
963  extensionsMap.find( ext );
964 
965  if( exttMapIt == extensionsMap.end() )
966  {
967  return std::string();
968  }
969  else
970  {
971  return exttMapIt->second;
972  }
973 }
974 
975 std::string te::gdal::GetGDALConnectionInfo(const std::map<std::string, std::string>& connInfo)
976 {
977  std::map<std::string, std::string>::const_iterator it = connInfo.find("URI");
978 
979  if(it != connInfo.end())
980  return it->second;
981 
982  it = connInfo.find("SOURCE");
983 
984  if(it != connInfo.end())
985  return it->second;
986 
987  throw Exception(TE_TR("Invalid data source connection information!."));
988 }
989 
990 void te::gdal::Vectorize(GDALRasterBand* band, std::vector<te::gm::Geometry*>& geometries)
991 {
992 // create data source of geometries in memory
993  //OGRSFDriver *ogrDriver = OGRSFDriverRegistrar::GetRegistrar()->GetDriverByName("Memory");
994  GDALDriver* ogrDriver = GetGDALDriverManager()->GetDriverByName("Memory");
995 
996  //OGRDataSource* ds = ogrDriver->CreateDataSource("ds_vectorize", NULL);
997  GDALDataset* ds = ogrDriver->Create("ds_vectorize", 0, 0, 0, GDT_Unknown, nullptr);
998 
999  OGRLayer* ogrLayer = ds->CreateLayer("vectorization", nullptr, wkbMultiPolygon, nullptr);
1000 
1001  ogrLayer->CreateField(new OGRFieldDefn("id", OFTInteger));
1002 
1003 // call polygonize function from gdal
1004  if (GDALPolygonize(band, nullptr , ogrLayer, 0, nullptr, nullptr, nullptr) == CE_Failure)
1005  return;
1006 
1007 // convert geometries to terralib
1008  for (int g = 0; g < ogrLayer->GetFeatureCount(); g++)
1009  geometries.push_back(te::ogr::Convert2TerraLib(ogrLayer->GetFeature(g)->GetGeometryRef()));
1010 
1011  //OGRDataSource::DestroyDataSource(ds);
1012  GDALClose(ds);
1013 }
1014 
1015 void te::gdal::Rasterize(std::vector<te::gm::Geometry*> geometries, GDALDataset* outraster)
1016 {
1017 // define list of bands (using single band)
1018  std::vector<int> bandList;
1019 
1020  bandList.push_back(1);
1021 
1022  std::vector<OGRGeometryH> ogrGeometries;
1023 
1024  std::vector<double> burnValues;
1025 
1026 // defining vector of ogr geometries and different values for each one in raster
1027  int bvalue = 254;
1028  for (std::size_t g = 0; g < geometries.size(); g++)
1029  {
1030  burnValues.push_back(bvalue % 255);
1031 
1032  bvalue = bvalue >= 127? bvalue - 126: bvalue > 255? 0: bvalue + 127;
1033 
1034  ogrGeometries.push_back(te::ogr::Convert2OGR(geometries[g]));
1035  }
1036 
1037  GDALRasterizeGeometries(outraster, static_cast<int>(bandList.size()), &(bandList[0]), static_cast<unsigned int>(ogrGeometries.size()), &(ogrGeometries[0]), nullptr, nullptr, &(burnValues[0]), nullptr, nullptr, nullptr);
1038 }
1039 
1040 bool te::gdal::IsSubDataSet( const std::string& uri )
1041 {
1042  std::size_t firstIdx = uri.find( ":" );
1043 
1044  if( firstIdx < uri.size() )
1045  {
1046  std::size_t secondIdx = uri.find( ":", firstIdx + 1 );
1047 
1048  if( secondIdx < uri.size() )
1049  {
1050  return true;
1051  }
1052  else
1053  {
1054  return false;
1055  }
1056  }
1057  else
1058  {
1059  return false;
1060  }
1061 }
1062 
1063 std::string te::gdal::GetParentDataSetName(const std::string& subDataSetName)
1064 {
1065  if( IsSubDataSet( subDataSetName ) )
1066  {
1067  std::size_t firstIdx = subDataSetName.find( ":" );
1068 
1069  if( firstIdx < subDataSetName.size() )
1070  {
1071  std::size_t secondIdx = subDataSetName.find( ":", firstIdx + 1 );
1072 
1073  if( secondIdx < subDataSetName.size() )
1074  {
1075  return subDataSetName.substr( secondIdx + 1, subDataSetName.size() - firstIdx - 1);
1076  }
1077  else
1078  {
1079  return subDataSetName;
1080  }
1081  }
1082  else
1083  {
1084  return subDataSetName;
1085  }
1086  }
1087  else
1088  {
1089  return subDataSetName;
1090  }
1091 }
1092 
1094 {
1095  static boost::mutex getStaticMutexStaticMutex;
1096  return getStaticMutexStaticMutex;
1097 }
1098 
1099 std::map< std::string, te::gdal::DriverMetadata >& te::gdal::GetGDALDriversMetadata()
1100 {
1101  static std::map< std::string, DriverMetadata > driversMetadataMap;
1102 
1103  if(driversMetadataMap.empty() )
1104  {
1105  GDALDriverManager* driverManagerPtr = GetGDALDriverManager();
1106 
1107  int driversCount = driverManagerPtr->GetDriverCount();
1108  const char* valuePtr = nullptr;
1109 
1110  for( int driverIndex = 0 ; driverIndex < driversCount ; ++driverIndex )
1111  {
1112  GDALDriver* driverPtr = driverManagerPtr->GetDriver(driverIndex);
1113 
1114  if( driverPtr )
1115  {
1116  DriverMetadata auxMD;
1117  auxMD.m_driverName = driverPtr->GetDescription();
1118 
1119  CPLStringList metaInfo( driverPtr->GetMetadata(), false );
1120  CPLStringList metaDomainList( driverPtr->GetMetadataDomainList(), true );
1121 
1122  valuePtr = metaInfo.FetchNameValue( GDAL_DMD_EXTENSIONS );
1123  if( valuePtr )
1124  {
1125  te::common::Tokenize( std::string( valuePtr ), auxMD.m_extensions, " " );
1126  }
1127 
1128  valuePtr = metaInfo.FetchNameValue( GDAL_DMD_LONGNAME );
1129  if( valuePtr ) auxMD.m_longName = valuePtr;
1130 
1131  valuePtr = metaInfo.FetchNameValue( GDAL_DMD_SUBDATASETS );
1132  if( ( valuePtr != nullptr ) && ( std::strcmp( "YES", valuePtr ) == 0 ) )
1133  {
1134  auxMD.m_subDatasetsSupport = true;
1135  }
1136  else
1137  {
1138  auxMD.m_subDatasetsSupport = false;
1139  }
1140 
1141  valuePtr = metaInfo.FetchNameValue( GDAL_DCAP_RASTER );
1142  if( ( valuePtr != nullptr ) && ( std::strcmp( "YES", valuePtr ) == 0 ) )
1143  {
1144  auxMD.m_isRaster = true;
1145  }
1146  else
1147  {
1148  auxMD.m_isRaster = false;
1149  }
1150 
1151  valuePtr = metaInfo.FetchNameValue( GDAL_DCAP_VECTOR );
1152  if( ( valuePtr != nullptr ) && ( std::strcmp( "YES", valuePtr ) == 0 ) )
1153  {
1154  auxMD.m_isVector = true;
1155  }
1156  else
1157  {
1158  auxMD.m_isVector = false;
1159  }
1160 
1161  valuePtr = metaInfo.FetchNameValue( GDAL_DCAP_CREATE );
1162  if( ( valuePtr != nullptr ) && ( std::strcmp( "YES", valuePtr ) == 0 ) )
1163  {
1164  auxMD.m_supportCreation = true;
1165  }
1166  else
1167  {
1168  auxMD.m_supportCreation = false;
1169  }
1170 
1171  driversMetadataMap[ auxMD.m_driverName ] = auxMD;
1172  }
1173  }
1174  }
1175 
1176  return driversMetadataMap;
1177 }
1178 
1179 std::multimap< std::string, std::string > te::gdal::GetGDALRasterDriversUCaseExt2DriversMap(
1180  const bool creationSupport )
1181 {
1182  std::multimap< std::string, std::string > extensionsMap;
1183 
1184  if(extensionsMap.empty() )
1185  {
1186  const std::map< std::string, DriverMetadata >& driversMetadata = GetGDALDriversMetadata();
1187 
1188  for( std::map< std::string, DriverMetadata >::const_iterator it = driversMetadata.begin() ;
1189  it != driversMetadata.end() ; ++it )
1190  {
1191  if(
1192  ( ! it->second.m_extensions.empty() )
1193  &&
1194  it->second.m_isRaster
1195  &&
1196  ( creationSupport ? it->second.m_supportCreation : true )
1197  )
1198  {
1199  for( std::size_t extensionsIdx = 0 ; extensionsIdx < it->second.m_extensions.size() ;
1200  ++extensionsIdx )
1201  {
1202  extensionsMap.insert( std::pair< std::string, std::string >(
1203  te::common::Convert2UCase( it->second.m_extensions[ extensionsIdx ] ), it->first ) );;
1204  }
1205  }
1206  }
1207  }
1208 
1209  return extensionsMap;
1210 }
1211 
1212 std::multimap< std::string, std::string > te::gdal::GetGDALVectorDriversUCaseExt2DriversMap(
1213  const bool creationSupport )
1214 {
1215  std::multimap< std::string, std::string > extensionsMap;
1216 
1217  if(extensionsMap.empty() )
1218  {
1219  const std::map< std::string, DriverMetadata >& driversMetadata = GetGDALDriversMetadata();
1220 
1221  for( std::map< std::string, DriverMetadata >::const_iterator it = driversMetadata.begin() ;
1222  it != driversMetadata.end() ; ++it )
1223  {
1224  if(
1225  ( ! it->second.m_extensions.empty() )
1226  &&
1227  it->second.m_isVector
1228  &&
1229  ( creationSupport ? it->second.m_supportCreation : true )
1230  )
1231  {
1232  for( std::size_t extensionsIdx = 0 ; extensionsIdx < it->second.m_extensions.size() ;
1233  ++extensionsIdx )
1234  {
1235  extensionsMap.insert( std::pair< std::string, std::string >(
1236  te::common::Convert2UCase( it->second.m_extensions[ extensionsIdx ] ), it->first ) );;
1237  }
1238  }
1239  }
1240  }
1241 
1242  return extensionsMap;
1243 }
1244 
1245 std::multimap< std::string, std::string > te::gdal::GetGDALAllDriversUCaseExt2DriversMap(
1246  const bool creationSupport )
1247 {
1248  std::multimap< std::string, std::string > extensionsMap( GetGDALVectorDriversUCaseExt2DriversMap(
1249  creationSupport ) );
1250  std::multimap< std::string, std::string > rastersExtensionsMap( GetGDALRasterDriversUCaseExt2DriversMap(
1251  creationSupport ) );
1252 
1253  std::multimap< std::string, std::string >::const_iterator it =
1254  rastersExtensionsMap.begin();
1255  std::multimap< std::string, std::string >::const_iterator itEnd =
1256  rastersExtensionsMap.end();
1257 
1258  while( it != itEnd )
1259  {
1260  extensionsMap.insert( std::pair< std::string, std::string >( it->first, it->second ) );
1261  ++it;
1262  }
1263 
1264  return extensionsMap;
1265 }
1266 
1267 void te::gdal::GDALErrorHandler(CPLErr /*eErrClass*/, int /*errNo*/,
1268  const char* msg)
1269 {
1270  TE_LOG_ERROR(msg);
1271 }
1272 
GDALDataset * getGDALDataset() const
Returns the raster GDAL handler.
GDALColorInterp GetGDALColorInterpretation(te::rst::ColorInterp ci)
It translates a TerraLib ColorInterpretation to a GDAL ColorInterpretation.
TEGDALEXPORT void Vectorize(GDALRasterBand *band, std::vector< te::gm::Geometry * > &geometries)
Vectorizes a given raster band, using GDALPolygonize function.
HSL indexed palette interpretation.
unsigned int getNumberOfRows() const
Returns the grid number of rows.
Palette indexes color interpretation.
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...
bool m_subDatasetsSupport
true if the driver has support for sub-datasets (GDAL_DMD_SUBDATASETS).
std::size_t m_idx
The band index.
Definition: BandProperty.h:132
unsigned int band
std::string path() const
Retrieving the path.
Definition: URI.cpp:118
void GDALErrorHandler(CPLErr eErrClass, int errNo, const char *msg)
GDALDataType GetGDALDataType(int tet)
It translates a TerraLib DataType to a GDAL DataType.
TEOGREXPORT OGRGeometry * Convert2OGR(const te::gm::Geometry *teGeom)
It converts the TerraLib Geometry to OGR Geometry.
void GetBands(te::gdal::Raster *rst, std::vector< te::gdal::Band * > &bands)
Gets the list of bands from a GDAL dataset.
std::string m_driverName
Driver name (driver description).
std::map< std::string, DriverMetadata > & GetGDALDriversMetadata()
Returns metadata from all registered GDAL drivers (key: driver name).
te::rst::ColorInterp GetTeColorInterpretation(GDALColorInterp gci)
It translates a GDAL ColorInterpretation to a TerraLib ColorInterpretation.
TEGDALEXPORT void GetBandProperties(GDALDataset *gds, std::vector< te::rst::BandProperty * > &bprops)
Gets the list of bands definition from a GDAL dataset.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
A raster band description.
Definition: BandProperty.h:61
RGB indexed palette interpretation.
This class represents Raster data.
int getSRID() const
Returns the grid spatial reference system identifier.
Base exception class for plugin module.
Gray indexed palette interpretation.
short c4
alpha or blackband.
Definition: BandProperty.h:75
te::rst::BandProperty * GetBandProperty(GDALRasterBand *gband, const unsigned int bandIndex)
Gets the properties of a single band from a GDAL dataset.
std::string Convert2UCase(const std::string &value)
It converts a string to upper case.
Definition: StringUtils.h:168
std::string password() const
Retrieving the password information.
Definition: URI.cpp:103
static te::dt::Date ds(2010, 01, 01)
This is a class that represents a GDAL Raster.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
Raster property.
std::string query() const
Retrieving the query.
Definition: URI.cpp:123
This class represents raster band description.
int GetTeDataType(GDALDataType gt)
It translates a GDAL DataType to a TerraLib DataType.
unsigned int unsigned int nCols
AccessPolicy
Supported data access policies (can be used as bitfield).
int b
Definition: TsRtree.cpp:32
void Tokenize(const std::string &str, std::vector< std::string > &tokens, const std::string &delimiters=" ")
It tokenizes a given string with a delimiter of your own choice.
Definition: StringUtils.h:221
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.
GDALDataset * GetRasterHandle(std::string strAccessInfo, te::common::AccessPolicy policy=te::common::RAccess)
Get a handle to a raster file.
te::gm::Envelope * GetExtent(std::string strAccessInfo)
Gets the extent of a raster data decoded by GDAL.
std::string MakePGConnectionStr(const te::core::URI &connInfo)
Returns a PostGIS connection string from the URI connection information. The connection string is to ...
static UnitsOfMeasureManager & getInstance()
It returns a reference to the singleton instance.
An Envelope defines a 2D rectangular region.
std::vector< std::string > m_extensions
List of extensions handled by the driver (GDAL_DMD_EXTENSIONS).
An abstract class for raster data strucutures.
const double * getGeoreference() const
Returns a list of 6 coefficients describing an affine transformation to georeference a grid...
std::string GetParentDataSetName(const std::string &subDataSetName)
It returns the parent dataset name from a Sub DataSet name.
TEOGREXPORT te::gm::Geometry * Convert2TerraLib(OGRGeometry *ogrGeom)
It converts the OGR Geometry to TerraLib Geometry.
unsigned int getNumberOfColumns() const
Returns the grid number of columns.
std::string port() const
Retrieving the port.
Definition: URI.cpp:113
list bands
Definition: compose.py:2
bool m_supportCreation
Capability set by a driver having vector capability (GDAL_DCAP_CREATE).
std::string host() const
Retrieving the host.
Definition: URI.cpp:108
bool m_isRaster
Capability set by a driver having raster capability (GDAL_DCAP_RASTER).
bool m_isVector
Capability set by a driver having vector capability (GDAL_DCAP_VECTOR).
std::string GetDriverName(const std::string &dsName)
It returns the GDAL driver name associated to a data source name.
A class for representing an Uniform Resource Identifier (URI).
Definition: URI.h:49
bool IsSubDataSet(const std::string &uri)
Returns true if the given URI is related to a sub-dataset.
bool ReprojectRaster(te::rst::Raster const *const rin, te::rst::Raster *rout)
Reprojects a raster to another SRS.
short c1
gray, red, cyan or hue.
Definition: BandProperty.h:72
std::multimap< std::string, std::string > GetGDALVectorDriversUCaseExt2DriversMap(const bool creationSupport)
Returns a map of all GDAL supported Upper-case vector extensions to their respective driver names...
This file contains utility functions used to manipulate data from a URI.
#define TL_B_PROP_DESC_KEY
bool RecognizesSRID(unsigned int srid)
It returns true if GDAL recognizes the given SRS id.
std::string GetGDALConnectionInfo(const std::map< std::string, std::string > &connInfo)
It returns a GDAL connection string from the given map.
TECOREEXPORT std::map< std::string, std::string > Expand(const std::string &query_str)
Split a query string into its components.
#define TL_B_PROP_CATNAME_KEY
te::gm::Envelope * getExtent()
Returns the geographic extension of the grid.
short c3
blue, yellow, or saturation.
Definition: BandProperty.h:74
#define TE_LOG_ERROR(message)
Use this tag in order to log a message to the TerraLib default logger with the ERROR level...
Definition: Logger.h:337
An structure to represent a color tuple.
Definition: BandProperty.h:70
TEGDALEXPORT void Rasterize(std::vector< te::gm::Geometry * > geometries, GDALDataset *outraster)
Rasterizes a given vector of geometries, using GDALRasterizeGeometries function.
CMYK indexed palette interpretation.
UnitOfMeasurePtr find(unsigned int id) const
Returns a unit of measure identified by its identificaton.
TECOREEXPORT std::string URIDecode(const std::string &srcUri)
Decodes an encoded URI. The algorithm implementation is based on http://www.codeguru.com/cpp/cpp/algorithms/strings/article.php/c12759/URI-Encoding-and-Decoding.htm.
It gives access to values in one band (dimension) of a raster.
TEGDALEXPORT boost::mutex & getStaticMutex()
Returns a reference to a static mutex initialized when this module is initialized.
A rectified grid is the spatial support for raster data.
Definition: raster/Grid.h:68
std::string m_longName
File long name (GDAL_DMD_LONGNAME).
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.
TEGDALEXPORT te::rst::Grid * GetGrid(GDALDataset *gds)
Gets the grid definition from a GDAL dataset.
short c2
green, magenta, or lightness.
Definition: BandProperty.h:73
std::string user() const
Retrieving the user information.
Definition: URI.cpp:98
TEOGREXPORT int Convert2TerraLibProjection(OGRSpatialReference *osrs)
It converts the OGR Projection to TerraLib Projection.
std::multimap< std::string, std::string > GetGDALRasterDriversUCaseExt2DriversMap(const bool creationSupport)
Returns a map of all GDAL supported Upper-case raster extensions to their respective driver names...
te::rst::RasterProperty * GetRasterProperty(std::string strAccessInfo)
Gets the complete description from a GDAL dataset.