src/terralib/raster/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/raster/Utils.cpp
22 
23  \brief Utility functions for the raster module.
24 */
25 
26 // TerraLib
27 #include "../datatype/Enums.h"
28 #include "../geometry/Coord2D.h"
29 #include "../common/MathUtils.h"
30 #include "BandIterator.h"
31 #include "Exception.h"
32 #include "PositionIterator.h"
33 #include "RasterFactory.h"
34 #include "Utils.h"
35 
36 // Boost
37 #include <boost/cstdint.hpp>
38 #include <boost/random.hpp>
39 #include <boost/random/uniform_int_distribution.hpp>
40 
41 // STL
42 #include <cassert>
43 #include <limits>
44 #include <vector>
45 
46 static int sg_pixelSize[] = { 0,
47  0,
48  0,
49  sizeof(char) * 8,
50  sizeof(unsigned char),
51  sizeof(boost::int16_t),
52  sizeof(boost::uint16_t),
53  sizeof(boost::int32_t),
54  sizeof(boost::uint32_t),
55  sizeof(boost::int64_t),
56  sizeof(boost::uint64_t),
57  sizeof(bool),
58  sizeof(float),
59  sizeof(double),
60  0,
61  0,
62  0,
63  0,
64  0,
65  0,
66  0,
67  0,
68  0,
69  sizeof(boost::int16_t) * 2,
70  sizeof(boost::int32_t) * 2,
71  sizeof(float) * 2,
72  sizeof(double) * 2,
73  0,
74  0,
75  0,
76  sizeof(unsigned char), // 4bits = 4/8 sizeof(unsigned char)
77  sizeof(unsigned char), // 2bits = 2/8 sizeof(unsigned char)
78  sizeof(unsigned char) // 1bit = 1/8 sizeof(unsigned char)
79  };
80 
81 int te::rst::GetPixelSize(int datatype)
82 {
83  return sg_pixelSize[datatype];
84 }
85 
86 std::vector<te::rst::BandProperty*> te::rst::GetBandProperties(const std::map<std::string, std::string>& rinfo)
87 {
88  std::size_t nBands;
89  int tBands;
90  std::vector<te::rst::BandProperty*> bprops;
91 
92  std::map<std::string, std::string>::const_iterator it = rinfo.find("NBANDS");
93 
94  if(it == rinfo.end())
95  throw Exception(("Number of bands must be set!"));
96 
97  nBands = atoi(it->second.c_str());
98 
99  it = rinfo.find("BANDSTYPE");
100 
101  if(it == rinfo.end())
102  throw Exception(("Data type of bands must be set!"));
103 
104  tBands = atoi(it->second.c_str());
105 
106  for (std::size_t b = 0; b < nBands; b++)
107  bprops.push_back(new te::rst::BandProperty(b, tBands));
108 
109  return bprops;
110 }
111 
112 te::rst::Grid* te::rst::GetGrid(const std::map<std::string, std::string>& rinfo)
113 {
114  unsigned nCols, nRows;
115  double resX = 1.0, resY = 1.0, ulX =0.0, ulY=0.0;
116  int srid = TE_UNKNOWN_SRS;
117  te::gm::Coord2D* ulc;
118 
119  std::map<std::string, std::string>::const_iterator it = rinfo.find("NCOLS");
120 
121  if(it == rinfo.end())
122  throw Exception(("Number of columns must be set!"));
123 
124  nCols = atoi(it->second.c_str());
125 
126  it = rinfo.find("NROWS");
127 
128  if(it == rinfo.end())
129  throw Exception(("Number of rows must be set!"));
130 
131  nRows = atoi(it->second.c_str());
132 
133  it = rinfo.find("RESX");
134  if(it != rinfo.end())
135  resX = atof(it->second.c_str());
136 
137  it = rinfo.find("RESY");
138  if(it != rinfo.end())
139  resY = atof(it->second.c_str());
140 
141  it = rinfo.find("SRID");
142  if(it != rinfo.end())
143  srid = atoi(it->second.c_str());
144 
145  it = rinfo.find("ULX");
146  if(it != rinfo.end())
147  ulX = atof(it->second.c_str());
148 
149  it = rinfo.find("ULY");
150  if(it != rinfo.end())
151  ulY = atof(it->second.c_str());
152 
153  ulc = new te::gm::Coord2D(ulX, ulY);
154 
155  return (new te::rst::Grid(nCols, nRows, resX, resY, ulc, srid));
156 }
157 
159 {
160  assert(rin.getNumberOfBands() == rout.getNumberOfBands());
162 
163  const std::size_t nbands = rin.getNumberOfBands();
164  const unsigned int nRows = rin.getNumberOfRows();
165  const unsigned int nCols = rin.getNumberOfColumns();
166  unsigned int row = 0;
167  unsigned int col = 0;
168  std::complex< double > value;
169 
170  for(std::size_t b = 0; b < nbands; b++)
171  {
172  if(rin.getBand(b)->getProperty()->getType() == rout.getBand(b)->getProperty()->getType())
173  {
174  Copy(*rin.getBand(b), *rout.getBand(b));
175  }
176  else
177  {
178  const te::rst::Band& bin = *rin.getBand(b);
179  te::rst::Band& bout = *rout.getBand(b);
180 
181  for(row = 0 ; row < nRows ; ++row)
182  for(col = 0 ; col < nCols ; ++col)
183  {
184  bin.getValue(col, row, value);
185 
186  bout.setValue(col, row, value);
187  }
188  }
189  }
190 }
191 
193 {
194  assert(*bin.getRaster()->getGrid() == *bout.getRaster()->getGrid());
195 
196 // when both bands have the same data type
197  if (bin.getProperty()->getType() == bout.getProperty()->getType())
198  {
199  unsigned char* buffer = new unsigned char[bin.getBlockSize()];
200 
201  int nblocksx = bin.getProperty()->m_nblocksx;
202  int nblocksy = bin.getProperty()->m_nblocksy;
203 
204  const int blkw = bin.getProperty()->m_blkw;
205  const int blkh = bin.getProperty()->m_blkh;
206 
207  // when both rasters have the same block size, copy the entire blocks from in to out
208  if((blkw == bout.getProperty()->m_blkw) &&
209  (blkh == bout.getProperty()->m_blkh))
210  {
211  for(int y = 0; y < nblocksy; ++y)
212  {
213  for(int x = 0; x < nblocksx; ++x)
214  {
215  bin.read(x, y, buffer);
216  bout.write(x, y, buffer);
217  }
218  }
219  }
220  // get all values from input block, and copy pixel by pixel to the output band
221  else
222  {
223  std::complex<double> value;
224 
225  const unsigned int ncols = bin.getRaster()->getNumberOfColumns();
226  const unsigned int nrows = bin.getRaster()->getNumberOfRows();
227 
228  for(int y = 0; y < nblocksy; ++y)
229  {
230  for(int x = 0; x < nblocksx; ++x)
231  {
232  unsigned int w = blkw * (x + 1);
233 
234  w = w > ncols ? ncols : w;
235 
236  unsigned int h = blkh * (y + 1);
237 
238  h = h > nrows ? nrows : h;
239 
240  for(int r = blkh * y; r < (int)h; ++r)
241  {
242  for(int c = blkw * x; c < (int)w; ++c)
243  {
244  bin.getValue(c, r, value);
245 
246  bout.setValue(c, r, value);
247  }
248  }
249  }
250  }
251  }
252 
253  delete [] buffer;
254  }
255 // if bands have different data types, use iterator
256  else
257  {
259 
261 
262  while(rit != ritend)
263  {
264  bout.setValue(rit.getColumn(), rit.getRow(), *rit);
265 
266  ++rit;
267  }
268  }
269 }
270 
271 void te::rst::Copy(unsigned int drow, unsigned int dcolumn, unsigned int height, unsigned int width, const Raster& rin, Raster& rout)
272 {
273  assert(drow + height <= rin.getNumberOfRows());
274  assert(dcolumn + width <= rin.getNumberOfColumns());
275 
276 // define variables for interpolation
277  std::vector<std::complex<double> > v;
278 
279  for (unsigned r = drow; r < drow + height; r++)
280  {
281  for (unsigned c = dcolumn; c < dcolumn + width; c++)
282  {
283  te::gm::Coord2D inputGeo = rin.getGrid()->gridToGeo(c, r);
284 
285  te::gm::Coord2D outputGrid = rout.getGrid()->geoToGrid(inputGeo.x, inputGeo.y);
286 
287  int x = Round(outputGrid.x);
288  int y = Round(outputGrid.y);
289 
290  if((x >=0 && x < (int)rout.getNumberOfColumns()) && (y >=0 && y < (int)rout.getNumberOfRows()))
291  {
292  rin.getValues(c, r, v);
293  rout.setValues(x, y, v);
294  }
295  }
296  }
297 }
298 
300  const std::string& uri,
301  const std::string &rType)
302 {
303  std::map<std::string, std::string> rasterInfo;
304  rasterInfo["URI"] = uri;
305 
306  std::vector<te::rst::BandProperty*> bandsProperties;
307 
308  unsigned int bandIndex = 0;
309 
310  for(bandIndex = 0; bandIndex < rin.getNumberOfBands(); ++bandIndex)
311  {
312  bandsProperties.push_back(new te::rst::BandProperty(*(rin.getBand(bandIndex )->getProperty())));
313  }
314 
315  te::rst::RasterPtr outRasterPtr;
316 
317  outRasterPtr.reset( te::rst::RasterFactory::make( rType, new te::rst::Grid(*(rin.getGrid())), bandsProperties, rasterInfo, nullptr, nullptr));
318 
319  if(outRasterPtr.get() == nullptr)
320  return outRasterPtr;
321 
322  Copy(rin, *outRasterPtr);
323 
324  return outRasterPtr;
325 }
326 
327 void te::rst::GetDataTypeRanges( const int& dataType, double& min, double& max )
328 {
329  switch( dataType )
330  {
331  case te::dt::R4BITS_TYPE:
332  min = 0;
333  max = 15;
334  break;
335 
336  case te::dt::R2BITS_TYPE:
337  min = 0;
338  max = 3;
339  break;
340 
341  case te::dt::R1BIT_TYPE:
342  min = 0;
343  max = 1;
344  break;
345 
346  case te::dt::UCHAR_TYPE:
347  min = 0;
348  max = 255;
349  break;
350 
351  case te::dt::CHAR_TYPE:
352  min = -127;
353  max = 127;
354  break;
355 
356  case te::dt::UINT16_TYPE:
357  min = 0;
358  max = (double)std::numeric_limits<unsigned short int>::max();
359  break;
360 
361  case te::dt::INT16_TYPE:
362  min = (double)std::numeric_limits<short int>::min();
363  max = (double)std::numeric_limits<short int>::max();
364  break;
365 
366  case te::dt::UINT32_TYPE:
367  min = 0;
368  max = (double)std::numeric_limits<unsigned int>::max();
369  break;
370 
371  case te::dt::INT32_TYPE:
372  min = (double)std::numeric_limits<int>::min();
373  max = (double)std::numeric_limits<int>::max();
374  break;
375 
376  case te::dt::FLOAT_TYPE:
377  min = -(double)std::numeric_limits< float >::max();
378  max = (double)std::numeric_limits< float >::max();
379  break;
380 
381  case te::dt::DOUBLE_TYPE:
382  min = -std::numeric_limits< double >::max();
383  max = std::numeric_limits< double >::max();
384  break;
385 
386  case te::dt::CINT16_TYPE:
387  min = (double)std::numeric_limits<short int>::min();
388  max = (double)std::numeric_limits<short int>::max();
389  break;
390 
391  case te::dt::CINT32_TYPE:
392  min = (double)std::numeric_limits<int>::min();
393  max = (double)std::numeric_limits<int>::max();
394  break;
395 
396  case te::dt::CFLOAT_TYPE:
397  min = -(double)std::numeric_limits< float >::max();
398  max = (double)std::numeric_limits< float >::max();
399  break;
400 
402  min = -std::numeric_limits< double >::max();
403  max = std::numeric_limits< double >::max();
404  break;
405 
406  default:
407  throw te::rst::Exception("Invalid data type");
408  }
409 }
410 
411 void te::rst::FillRaster(te::rst::Raster* rin, const std::complex<double>& value)
412 {
413  for (unsigned int b = 0; b < rin->getNumberOfBands(); b++)
414  te::rst::FillBand(rin->getBand(b), value);
415 }
416 
417 void te::rst::FillBand(te::rst::Band* bin, const std::complex<double>& value)
418 {
419  for (unsigned int r = 0; r < bin->getRaster()->getNumberOfRows(); r++)
420  for (unsigned int c = 0; c < bin->getRaster()->getNumberOfColumns(); c++)
421  bin->setValue(c, r, value);
422 }
423 
424 te::rst::RasterPtr te::rst::CropRaster(const te::rst::Raster& rin, const te::gm::Polygon& pin, const std::map<std::string, std::string>& rinfo, const std::string& rType)
425 {
426  std::vector< te::gm::Geometry const *> geometries;
427  geometries.push_back( &pin );
428 
429  return te::rst::RasterPtr( CropRaster( rin, geometries, rinfo, rType ).release() );
430 }
431 
432 std::unique_ptr< te::rst::Raster > te::rst::CropRaster(const te::rst::Raster& rin,
433  const std::vector< te::gm::Geometry const *> geometries,
434  const std::map<std::string, std::string>& rinfo,
435  const std::string& rType)
436 {
437  std::unique_ptr< te::rst::Raster > outRasterPtr;
438 
439  // Guessing the output envelope
440  // Checking input geometries
441 
442  te::gm::Envelope outEnvelope;
443 
444  {
445  outEnvelope.m_llx = outEnvelope.m_lly = std::numeric_limits< double >::max();
446  outEnvelope.m_urx = outEnvelope.m_ury = -1.0 * std::numeric_limits< double >::max();
447 
448  const std::size_t geometriesSize = geometries.size();
449  std::size_t geometriesIdx = 0;
450  te::gm::Geometry const * gPtr = nullptr;
451  te::gm::Envelope const * gEnvelopePtr = nullptr;
452 
453  for( geometriesIdx = 0 ; geometriesIdx < geometriesSize ; ++geometriesIdx )
454  {
455  gPtr = geometries[ geometriesIdx ];
456  if(gPtr == nullptr )
457  {
458  return outRasterPtr;
459  }
460 
461  if(
462  ( gPtr->getGeomTypeId() != te::gm::PolygonType )
463  &&
465  )
466  {
467  return outRasterPtr;
468  }
469 
470  gEnvelopePtr = gPtr->getMBR();
471 
472  outEnvelope.m_llx = std::min( outEnvelope.m_llx, gEnvelopePtr->m_llx );
473  outEnvelope.m_lly = std::min( outEnvelope.m_lly, gEnvelopePtr->m_lly );
474  outEnvelope.m_urx = std::max( outEnvelope.m_urx, gEnvelopePtr->m_urx );
475  outEnvelope.m_ury = std::max( outEnvelope.m_ury, gEnvelopePtr->m_ury );
476  }
477  }
478 
479  // Creating the output raster
480 
481  unsigned int firstInputRow = 0;
482  unsigned int firstInputCol = 0;
483 
484  {
485  te::gm::Coord2D cllenv(rin.getGrid()->geoToGrid(outEnvelope.m_llx,
486  outEnvelope.m_lly));
487  te::gm::Coord2D curenv(rin.getGrid()->geoToGrid(outEnvelope.m_urx,
488  outEnvelope.m_ury));
489 
490  firstInputRow =
491  te::common::Round< double, unsigned int >(
492  std::min(
493  (double)( rin.getGrid()->getNumberOfRows() - 1 )
494  ,
495  std::max(
496  0.0
497  ,
498  curenv.getY()
499  )
500  )
501  );
502  firstInputCol =
503  te::common::Round< double, unsigned int >(
504  std::min(
505  (double)( rin.getGrid()->getNumberOfColumns() - 1 )
506  ,
507  std::max(
508  0.0
509  ,
510  cllenv.getX()
511  )
512  )
513  );
514  const unsigned int lastInputRow =
515  te::common::Round< double, unsigned int >(
516  std::min(
517  (double)( rin.getGrid()->getNumberOfRows() - 1 )
518  ,
519  std::max(
520  0.0
521  ,
522  cllenv.getY()
523  )
524  )
525  );
526  const unsigned int lastInputCol =
527  te::common::Round< double, unsigned int >(
528  std::min(
529  (double)( rin.getGrid()->getNumberOfColumns() - 1 )
530  ,
531  std::max(
532  0.0
533  ,
534  curenv.getX()
535  )
536  )
537  );
538 
539  if( ( lastInputRow <= firstInputRow ) || ( lastInputCol <= firstInputCol ) )
540  {
541  return outRasterPtr;
542  }
543 
544  const unsigned int outputWidth = lastInputCol - firstInputCol + 1;
545  const unsigned int outputHeight = lastInputRow - firstInputRow + 1;
546 
547  if( ( outputHeight == 0 ) || ( outputHeight == 0 ) )
548  {
549  return outRasterPtr;
550  }
551 
552  te::gm::Coord2D ulc( rin.getGrid()->gridToGeo( ((double)firstInputCol) - 0.5,
553  ((double)firstInputRow) - 0.5 ) );
554 
555  te::rst::Grid* grid = new te::rst::Grid( outputWidth, outputHeight,
556  rin.getResolutionX(), rin.getResolutionY(), &ulc, rin.getSRID() );
557 
558  std::vector<te::rst::BandProperty*> bands;
559 
560  for (std::size_t b = 0; b < rin.getNumberOfBands(); b++)
561  {
562  bands.push_back(new te::rst::BandProperty(*(rin.getBand(b)->getProperty())));
563  bands[ b ]->m_nblocksx = 1;
564  bands[ b ]->m_nblocksy = outputHeight;
565  bands[ b ]->m_blkw = outputWidth;
566  bands[ b ]->m_blkh = 1;
567  }
568 
569  outRasterPtr.reset( te::rst::RasterFactory::make(rType, grid, bands, rinfo, nullptr, nullptr) );
570  if( outRasterPtr.get() == nullptr )
571  {
572  return outRasterPtr;
573  }
574 
575  FillRaster(outRasterPtr.get(), rin.getBand(0)->getProperty()->m_noDataValue);
576 
577  }
578 
579  // Data copy
580 
581  {
582  const std::size_t geometriesSize = geometries.size();
583  std::size_t geometriesIdx = 0;
584  std::vector< te::gm::Geometry * > singleGgeomsPtrs;
585  std::size_t singleGgeomsPtrsIdx = 0;
586  std::size_t singleGgeomsPtrsSize = 0;
587  std::vector<std::complex<double> > values;
588  unsigned int outRow = 0;
589  unsigned int outCol = 0;
590 
591  for( geometriesIdx = 0 ; geometriesIdx < geometriesSize ; ++geometriesIdx )
592  {
593  for(auto p : singleGgeomsPtrs)
594  delete p;
595  singleGgeomsPtrs.clear();
596  te::gm::Multi2Single( (te::gm::Geometry*)geometries[ geometriesIdx ], singleGgeomsPtrs );
597 
598  singleGgeomsPtrsSize = singleGgeomsPtrs.size();
599 
600  for( singleGgeomsPtrsIdx = 0 ; singleGgeomsPtrsIdx < singleGgeomsPtrsSize ;
601  ++singleGgeomsPtrsIdx )
602  {
603  assert( singleGgeomsPtrs[ singleGgeomsPtrsIdx ]->getGeomTypeId() ==
605 
607  outRasterPtr.get(), (te::gm::Polygon*)singleGgeomsPtrs[ singleGgeomsPtrsIdx ] );
609  outRasterPtr.get(), (te::gm::Polygon*)singleGgeomsPtrs[ singleGgeomsPtrsIdx ] );
610 
611  while( it != itEnd )
612  {
613  outRow = it.getRow();
614  outCol = it.getColumn();
615 
616  rin.getValues( outCol + firstInputCol, outRow + firstInputRow, values );
617  outRasterPtr->setValues( outCol, outRow, values );
618 
619  ++it;
620  }
621  }
622  }
623 
624  for(auto p : singleGgeomsPtrs)
625  delete p;
626  singleGgeomsPtrs.clear();
627  }
628 
629  return outRasterPtr;
630 }
631 
632 std::vector<te::gm::Point*> te::rst::GetRandomPointsInRaster(const te::rst::Raster& inputRaster, unsigned int numberOfPoints)
633 {
634  std::vector<te::gm::Point*> randomPoints;
635  double randX;
636  double randY;
637 
638  boost::random::mt19937 generator((boost::random::mt19937::result_type) time(nullptr));
639  boost::random::uniform_int_distribution<> random_rows(0, inputRaster.getNumberOfRows() - 1);
640  boost::random::uniform_int_distribution<> random_columns(0, inputRaster.getNumberOfColumns() - 1);
641 
642  for (unsigned int p = 0; p < numberOfPoints; p++)
643  {
644  inputRaster.getGrid()->gridToGeo(random_columns(generator), random_rows(generator), randX, randY);
645  randomPoints.push_back(new te::gm::Point(randX, randY, inputRaster.getSRID()));
646  }
647 
648  return randomPoints;
649 }
650 
652 {
653  if(ci == te::rst::UndefCInt)
654  return TE_TR("Undefined");
655  else if(ci == te::rst::GrayIdxCInt)
656  return TE_TR("Gray");
657  else if(ci == te::rst::PaletteIdxCInt)
658  return TE_TR("Palette");
659  else if(ci == te::rst::RedCInt)
660  return TE_TR("Red");
661  else if(ci == te::rst::GreenCInt)
662  return TE_TR("Green");
663  else if(ci == te::rst::BlueCInt)
664  return TE_TR("Blue");
665  else if(ci == te::rst::AlphaCInt)
666  return TE_TR("Alpha");
667  else if(ci == te::rst::HueCInt)
668  return TE_TR("Hue");
669  else if(ci == te::rst::SatCInt)
670  return TE_TR("Saturation");
671  else if(ci == te::rst::LigCInt)
672  return TE_TR("Lightness");
673  else if(ci == te::rst::CyanCInt)
674  return TE_TR("Cyan");
675  else if(ci == te::rst::MagentaCInt)
676  return TE_TR("Magenta");
677  else if(ci == te::rst::YellowCInt)
678  return TE_TR("Yellow");
679  else if(ci == te::rst::KeyCInt)
680  return TE_TR("Key");
681  else if(ci == te::rst::YCInt)
682  return TE_TR("Y");
683  else if(ci == te::rst::CbCInt)
684  return TE_TR("Cb");
685  else if(ci == te::rst::CrCInt)
686  return TE_TR("Cr");
687 
688  return "";
689 }
690 
692 {
693  if(pi == te::rst::UndefPalInt)
694  return TE_TR("Undefined");
695  else if(pi == te::rst::GrayPalInt)
696  return TE_TR("Gray");
697  else if(pi == te::rst::RGBPalInt)
698  return TE_TR("RGB");
699  else if(pi == te::rst::CMYKPalInt)
700  return TE_TR("CMYK");
701  else if(pi == te::rst::HSLPalInt)
702  return TE_TR("HSL");
703 
704  return "";
705 }
TERASTEREXPORT te::rst::RasterPtr CropRaster(const te::rst::Raster &rin, const te::gm::Polygon &pin, const std::map< std::string, std::string > &rinfo, const std::string &rType=std::string("GDAL"))
Creates a raster crop using a polygon delimiter.
An exception class for the Raster module.
HSL indexed palette interpretation.
unsigned int getNumberOfRows() const
Returns the grid number of rows.
virtual void setValues(unsigned int c, unsigned int r, const std::vector< double > &values)
Sets the imaginary attribute values in all complex bands of a cell.
unsigned int getRow() const
Returns the current row in iterator.
Definition: BandIterator.h:378
Palette indexes color interpretation.
Hue channel color interpretation.
Alpha channel color interpretation.
TERASTEREXPORT void FillBand(te::rst::Band *bin, const std::complex< double > &value)
Fill a Raster Band with provided value.
double y
y-coordinate.
Definition: Coord2D.h:114
TERASTEREXPORT void GetDataTypeRanges(const int &dataType, double &min, double &max)
Return the values range of a given data type.
Index into a lookup table.
unsigned int getColumn() const
Returns the current column in iterator.
Definition: BandIterator.h:383
Lightness color interpretation.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
ColorInterp
Color model component use.
A raster band description.
Definition: BandProperty.h:61
double x
x-coordinate.
Definition: Coord2D.h:113
RGB indexed palette interpretation.
Base exception class for plugin module.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
int m_nblocksx
The number of blocks in x.
Definition: BandProperty.h:145
Gray indexed palette interpretation.
TERASTEREXPORT te::rst::RasterPtr CreateCopy(const te::rst::Raster &rin, const std::string &uri, const std::string &rType=std::string("GDAL"))
Create a new raster from existing one.
GeomType getGeomTypeId() const _NOEXCEPT_OP(true)
It returns the geometry subclass type identifier.
int m_nblocksy
The number of blocks in y.
Definition: BandProperty.h:146
virtual void getValues(unsigned int c, unsigned int r, std::vector< double > &values) const
Returns the imaginary attribute values in all complex bands of a cell.
This class implements the strategy to iterate with spatial restriction, the iteration occurs inside a...
TERASTEREXPORT void Copy(const Raster &rin, Raster &rout)
Copies the pixel values from one raster to another.
double m_urx
Upper right corner x-coordinate.
Red channel color interpretation.
TERASTEREXPORT void FillRaster(te::rst::Raster *rin, const std::complex< double > &value)
Fill a Raster with provided value (all bands).
unsigned int getRow() const
Returns the current row in iterator.
An utility struct for representing 2D coordinates.
Definition: Coord2D.h:40
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits<double>::max().
Definition: BandProperty.h:136
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
Cyan color interpretation.
TERASTEREXPORT std::string ConvertColorInterpTypeToString(const te::rst::ColorInterp &ci)
Function used to convert from a Color Interp Enum to a string.
TEGEOMEXPORT void Multi2Single(const te::gm::Geometry *g, std::vector< te::gm::Geometry * > &geoms)
It will get a GeometryCollection and distribute in a vector.
This class implements an iterator to "navigate" over a single band (const).
Definition: BandIterator.h:219
void geoToGrid(const double &x, const double &y, double &col, double &row) const
Get the grid point associated to a spatial location.
static ConstBandIterator begin(const Band *b)
Returns an iterator referring to the first value of the band.
Definition: BandIterator.h:629
te::common::AccessPolicy getAccessPolicy() const
Returns the raster access policy.
Utility functions for the raster module.
unsigned int unsigned int nCols
boost::shared_ptr< Raster > RasterPtr
int b
Definition: TsRtree.cpp:32
This is the abstract factory for Rasters.
double m_llx
Lower left corner x-coordinate.
A point with x and y coordinate values.
Definition: Point.h:50
const Envelope * getMBR() const _NOEXCEPT_OP(true)
It returns the minimum bounding rectangle for the geometry in an internal representation.
YCbCr Cr Band color interpretation.
An Envelope defines a 2D rectangular region.
An abstract class for raster data strucutures.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
BandProperty * getProperty()
Returns the band property.
It implements an iterator to "navigate" over a single band (const or not const).
int m_blkw
Block width (pixels).
Definition: BandProperty.h:143
unsigned int getNumberOfColumns() const
Returns the grid number of columns.
double getResolutionX() const
Returns the raster horizontal (x-axis) resolution.
list bands
Definition: compose.py:2
virtual void write(int x, int y, void *buffer)=0
It writes a data block from the specified buffer.
void Copy(std::string dataSetName, std::unique_ptr< te::da::DataSource > inDs, te::da::DataSource *outDs)
Definition: CopyDataSet.cpp:68
te::gm::Polygon * p
No color interpretation is associated with the band.
A raster band description.
Undefined palette interpretation.
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
Grid * getGrid()
It returns the raster grid.
TERASTEREXPORT int GetPixelSize(int datatype)
Returns the byte size of a given datatype.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Key (black) color interpretation.
Yellow color interpretation.
OutputValueT Round(const InputValueT &inVal)
Round a value.
Definition: MathUtils.h:46
double m_lly
Lower left corner y-coordinate.
virtual void setValue(unsigned int c, unsigned int r, const double value)=0
Sets the cell attribute value.
virtual void read(int x, int y, void *buffer) const =0
It reads a data block to the specified buffer.
int getSRID() const
Returns the raster spatial reference system identifier.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
TERASTEREXPORT Grid * GetGrid(const std::map< std::string, std::string > &rinfo)
Returns a grid based on a given raster info.
double m_ury
Upper right corner y-coordinate.
static Raster * make()
It creates and returns an empty raster with default raster driver.
TERASTEREXPORT std::string ConvertPalleteInterpTypeToString(const te::rst::PaletteInterpretation &pi)
Function used to convert from a Pallete Interp Enum to a string.
void clear()
It deletes all the rings of the CurvePolygon and clear it.
virtual Raster * getRaster() const =0
Returns the associated raster.
void gridToGeo(const double &col, const double &row, double &x, double &y) const
Get the spatial location of a grid point.
double getResolutionY() const
Returns the raster vertical (y-axis) resolution.
TERASTEREXPORT std::vector< te::gm::Point * > GetRandomPointsInRaster(const te::rst::Raster &inputRaster, unsigned int numberOfPoints=1000)
Creates a vector of random positions (points) inside the raster.
YCbCr Y Band color interpretation.
int getType() const
It returns the data type of the elements in the band.
Definition: BandProperty.h:113
CMYK indexed palette interpretation.
Saturation color interpretation.
int m_blkh
Block height (pixels).
Definition: BandProperty.h:144
Blue channel color interpretation.
PaletteInterpretation
Palette interpratation types.
unsigned int getColumn() const
Returns the current column in iterator.
A rectified grid is the spatial support for raster data.
Definition: raster/Grid.h:68
static int sg_pixelSize[]
Green channel color interpretation.
virtual int getBlockSize() const
It returns the number of bytes ocuppied by a data block.
Magenta color interpretation.
YCbCr Cb Band color interpretation.
TERASTEREXPORT std::vector< BandProperty * > GetBandProperties(const std::map< std::string, std::string > &rinfo)
Returns a vector of band properties, based on a given raster info.
unsigned int col
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.
static ConstBandIterator end(const Band *b)
Returns an iterator referring to after the end of the iterator.
Definition: BandIterator.h:634