Functions.h
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/rp/Functions.h
22  \brief Raster Processing functions.
23  */
24 
25 #ifndef __TERRALIB_RP_INTERNAL_FUNCTIONS_H
26 #define __TERRALIB_RP_INTERNAL_FUNCTIONS_H
27 
28 #include "Config.h"
29 
30 #include "FeedersRaster.h"
31 #include "Matrix.h"
32 #include "Macros.h"
33 #include "RasterHandler.h"
34 #include "../dataaccess/datasource/DataSource.h"
35 #include "../raster/Raster.h"
36 #include "../raster/RasterFactory.h"
37 #include "../raster/Grid.h"
38 #include "../raster/BandProperty.h"
39 #include "../raster/RasterFactory.h"
40 #include "../raster/Interpolator.h"
41 #include "../raster/Utils.h"
42 #include "../srs/Converter.h"
43 #include "../geometry/LinearRing.h"
44 #include "../geometry/GTParameters.h"
45 #include "../geometry/MultiPoint.h"
46 #include "../geometry/Surface.h"
47 
48 // STL
49 #include <memory>
50 #include <map>
51 #include <vector>
52 #include <string>
53 #include <limits>
54 
55 // Boost
56 #include <boost/numeric/ublas/matrix.hpp>
57 #include <boost/shared_ptr.hpp>
58 
59 namespace te
60 {
61  namespace rst
62  {
63  class BandProperty;
64  class Grid;
65  }
66 
67  namespace rp
68  {
69  /*!
70  \brief Wavelet Atrous Filter types.
71  \ingroup rp_func
72  */
74  {
75  InvalidWAFilter, //!< Invalid filter type
76  B3SplineWAFilter, //!< Spline filter type.
77  TriangleWAFilter //!< Triangle filter type.
78  };
79 
80  /*!
81  \brief Create a new raster into the givem data source.
82  \param rasterGrid The template grid used to create the output raster.
83  \param bandsProperties The template band properties used to create the output raster.
84  \param outDataSetName The data set name to give to the created data set.
85  \param dataSourceType The data source type string (i.e. GDAL, MEM.)( See te::rst::RasterFactory dictionary for valid registered values ).
86  \param outRasterHandler The created raster handler.
87  \return true if OK, false on errors.
88  \note All bandsProperties pointed objects will be acquired by this function and must not be deleted.
89  \ingroup rp_func
90  */
91  bool TERPEXPORT CreateNewRaster( const te::rst::Grid& rasterGrid,
92  const std::vector< te::rst::BandProperty* >& bandsProperties,
93  const std::string& outDataSetName,
94  const std::string& dataSourceType,
95  RasterHandler& outRasterHandler );
96 
97  /*!
98  \brief Create a new raster into the givem data source.
99  \param rasterGrid The template grid used to create the output raster.
100  \param bandsProperties The template band properties used to create the output raster.
101  \param outDataSetName The data set name to give to the created data set.
102  \param outDataSource The data source to use when creating the output data set.
103  \param outRasterHandler The created raster handler.
104  \return true if OK, false on errors.
105  \note All bandsProperties pointed objects will be acquired by this function and must not be deleted.
106  \ingroup rp_func
107  */
108  bool TERPEXPORT CreateNewRaster( const te::rst::Grid& rasterGrid,
109  const std::vector< te::rst::BandProperty* >& bandsProperties,
110  const std::string& outDataSetName,
111  te::da::DataSource& outDataSource,
112  RasterHandler& outRasterHandler );
113 
114  /*!
115  \brief Create a new raster into the givem data source.
116  \param rasterGrid The template grid used to create the output raster.
117  \param bandsProperties The template band properties used to create the output raster.
118  \param rasterInfo The output raster info (specific driver info).
119  \param rasterType The output raster type (specific driver name - See te::rst::RasterFactory dictorary for more info).
120  \param outRasterPtr The created raster pointer.
121  \return true if OK, false on errors.
122  \note All bandsProperties pointed objects will be acquired by this function and must not be deleted.
123  \ingroup rp_func
124  */
125  bool TERPEXPORT CreateNewRaster( const te::rst::Grid& rasterGrid,
126  const std::vector< te::rst::BandProperty* >& bandsProperties,
127  const std::map< std::string, std::string>& rasterInfo,
128  const std::string& rasterType,
129  std::auto_ptr< te::rst::Raster >& outRasterPtr );
130 
131  /*!
132  \brief Create a new raster into a new memory datasource.
133  \param rasterGrid The template grid used to create the output raster.
134  \param bandsProperties The template band properties used to create the output raster.
135  \param outRasterHandler The created raster handler.
136  \return true if OK, false on errors.
137  \note All bandsProperties pointed objects will be acquired by this function and must not be deleted.
138  \ingroup rp_func
139  */
140  bool TERPEXPORT CreateNewMemRaster( const te::rst::Grid& rasterGrid,
141  std::vector< te::rst::BandProperty* > bandsProperties,
142  RasterHandler& outRasterHandler );
143 
144  /*!
145  \brief Create a new raster into a GDAL datasource.
146  \param rasterGrid The template grid used to create the output raster.
147  \param bandsProperties The template band properties used to create the output raster.
148  \param fileName The output tif file name.
149  \param outRasterHandler The created raster handler.
150  \return true if OK, false on errors.
151  \note All bandsProperties pointed objects will be acquired by this function and must not be deleted.
152  \ingroup rp_func
153  */
154  bool TERPEXPORT CreateNewGdalRaster( const te::rst::Grid& rasterGrid,
155  std::vector< te::rst::BandProperty* > bandsProperties,
156  const std::string& fileName,
157  RasterHandler& outRasterHandler );
158 
159  /*!
160  \brief Create a new raster into a GDAL datasource.
161  \param rasterGrid The template grid used to create the output raster.
162  \param bandsProperties The template band properties used to create the output raster.
163  \param fileName The output tif file name.
164  \param outRasterPtr The created raster pointer.
165  \return true if OK, false on errors.
166  \note All bandsProperties pointed objects will be acquired by this function and must not be deleted.
167  \ingroup rp_func
168  */
169  bool TERPEXPORT CreateNewGdalRaster( const te::rst::Grid& rasterGrid,
170  std::vector< te::rst::BandProperty* > bandsProperties,
171  const std::string& fileName,
172  std::auto_ptr< te::rst::Raster >& outRasterPtr );
173 
174  /*!
175  \brief Create a new raster into a GDAL datasource.
176  \param rasterGrid The template grid used to create the output raster.
177  \param bandsProperties The template band properties used to create the output raster.
178  \param fileName The output tif file name.
179  \param outRasterHandler The created raster handler.
180  \return true if OK, false on errors.
181  \note All bandsProperties pointed objects will be acquired by this function and must not be deleted.
182  \ingroup rp_func
183  */
185  const te::rst::Raster& inputRaster,
186  const std::string& fileName );
187 
188  /*!
189  \brief Returns the real data type range (all values that can be represented by the given data type).
190  \param dataType The data type.
191  \param min The minimum value.
192  \param max The maximum value.
193  \note The types are listed in terralib/datatype/DataTypes.h
194  \ingroup rp_func
195  */
196  inline void TERPEXPORT GetDataTypeRange( const int dataType, double& min, double& max )
197  {
198  te::rst::GetDataTypeRanges( dataType, min, max );
199  }
200 
201  /*!
202  \brief Convert vector elements.
203  \param inputVector Input vector.
204  \param inputVectorDataType Input vector data type.
205  \param inputVectorSize The numer of input vector elements.
206  \param outputVector A pré-allocated output vector.
207  \note The types are listed in terralib/datatype/DataTypes.h
208  \ingroup rp_func
209  */
210  void TERPEXPORT Convert2DoublesVector( void* inputVector, const int inputVectorDataType,
211  unsigned int inputVectorSize, double* outputVector );
212 
213  /*!
214  \brief Convert a doubles vector.
215  \param inputVector Input vector.
216  \param inputVectorSize The numer of input vector elements.
217  \param inputVectorDataType Input vector data type.
218  \param outputVector A pré-allocated output vector.
219  \note The types are listed in terralib/datatype/DataTypes.h
220  \ingroup rp_func
221  */
222  void TERPEXPORT ConvertDoublesVector( double* inputVector,
223  unsigned int inputVectorSize, const int outputVectorDataType,
224  void* outputVector );
225 
226  /*!
227  \brief Create a tiff file from a matrix.
228  \param matrix The matrix.
229  \param normalize Enable/disable pixel normalization (8bit);
230  \param tifFileName Tif file name.
231  \param return true if OK, false on errors.
232  \ingroup rp_func
233  */
234  template< typename MatrixElementT >
236  const bool normalize, const std::string& fileName )
237  {
238  std::map<std::string, std::string> rInfo;
239  rInfo["URI"] = fileName;
240 
241  std::vector<te::rst::BandProperty*> bandsProperties;
242  if( normalize )
243  bandsProperties.push_back(new te::rst::BandProperty( 0, te::dt::UCHAR_TYPE, "" ));
244  else
245  bandsProperties.push_back(new te::rst::BandProperty( 0, te::dt::DOUBLE_TYPE, "" ));
246  bandsProperties[0]->m_colorInterp = te::rst::GrayIdxCInt;
247  bandsProperties[0]->m_noDataValue = -1.0 * std::numeric_limits<double>::max();
248 
249  te::rst::Grid* newgrid = new te::rst::Grid( matrix.getColumnsNumber(),
250  matrix.getLinesNumber(), 0, -1 );
251 
252  std::auto_ptr< te::rst::Raster > outputRasterPtr(
253  te::rst::RasterFactory::make( "GDAL", newgrid, bandsProperties, rInfo, 0, 0));
254  TERP_TRUE_OR_RETURN_FALSE( outputRasterPtr.get(), "Output raster creation error");
255 
256  unsigned int line = 0;
257  unsigned int col = 0;
258  const unsigned int nLines = matrix.getLinesNumber();
259  const unsigned int nCols = matrix.getColumnsNumber();
260  MatrixElementT matrixValue = 0;
261 
262  MatrixElementT gain = 1.0;
263  MatrixElementT offset = 0.0;
264  if( normalize )
265  {
266  MatrixElementT matrixValueMin = std::numeric_limits< MatrixElementT >::max();
267  MatrixElementT matrixValueMax = -1.0 * matrixValueMin;
268  for( line = 0 ; line < nLines ; ++line )
269  {
270  for( col = 0 ; col < nCols ; ++col )
271  {
272  matrixValue = matrix[ line ][ col ];
273  if( matrixValue < matrixValueMin )
274  matrixValueMin = matrixValue;
275  if( matrixValue > matrixValueMax )
276  matrixValueMax = matrixValue;
277  }
278  }
279 
280  if( matrixValueMax == matrixValueMin )
281  {
282  gain = 0.0;
283  offset = 0.0;
284  }
285  else
286  {
287  gain = 255.0 / ( matrixValueMax - matrixValueMin );
288  offset = -1.0 * ( matrixValueMin );
289  }
290  }
291 
292  const MatrixElementT min0 = 0;
293  const MatrixElementT max255 = 255;
294 
295  for( line = 0 ; line < nLines ; ++line )
296  {
297  for( col = 0 ; col < nCols ; ++col )
298  {
299  matrixValue = matrix[ line ][ col ];
300 
301  if( normalize )
302  {
303  matrixValue += offset;
304  matrixValue *= gain;
305  matrixValue = std::max( min0, matrixValue );
306  matrixValue = std::min( max255, matrixValue );
307  }
308 
309  outputRasterPtr->setValue( col, line, (double)matrixValue, 0 );
310  }
311  }
312 
313  return true;
314  }
315 
316  /*!
317  \brief Returns a vector os with band's names.
318  \ingroup rp_func
319  */
320  TERPEXPORT std::vector<std::string> GetBandNames();
321 
322  /*!
323  \brief Returns the maximun and minimum reflectance values of a given sensor/band.
324  \ingroup rp_func
325  */
326  TERPEXPORT std::pair<double, double> GetSpectralBandInfo(std::string bandName);
327 
328  /*!
329  \brief Returns the minimum reflectance value of a given sensor/band.
330  \ingroup rp_func
331  */
332  TERPEXPORT double GetSpectralBandMin(std::string bandName);
333 
334  /*!
335  \brief Returns the maximum reflectance value of a given sensor/band.
336  \ingroup rp_func
337  */
338  TERPEXPORT double GetSpectralBandMax(std::string bandName);
339 
340  /*!
341  \brief Returns the maximun and minimum digital numbers of a given sensor/band.
342  \ingroup rp_func
343  */
344  TERPEXPORT std::pair<double, double> GetDigitalNumberBandInfo(std::string bandName);
345 
346  /*!
347  \brief Returns the maximum digital number of a given sensor/band.
348  \ingroup rp_func
349  */
350  TERPEXPORT double GetDigitalNumberBandMax(std::string bandName);
351 
352  /*!
353  \brief Returns the minimum digital number of a given sensor/band.
354  \ingroup rp_func
355  */
356  TERPEXPORT double GetDigitalNumberBandMin(std::string bandName);
357 
358  /*!
359  \brief Normalizes one raster in a given interval.
360 
361  \param inputRaster The given raster.
362  \param nmin The new minimum value (default = 0.0).
363  \param nmax The new maximum value (default = 255.0).
364 
365  \return true if normalization occurs and false otherwise.
366  \ingroup rp_func
367  */
368  TERPEXPORT bool NormalizeRaster(te::rst::Raster& inputRaster, double nmin = 0.0, double nmax = 255.0);
369 
370  /*!
371  \brief RGB to IHS conversion.
372  \param inputRGBRaster The input raster.
373  \param redBandIdx The red band index.
374  \param greenBandIdx The red band index.
375  \param blueBandIdx The red band index.
376  \param rgbRangeMin The minimum RGB value.
377  \param rgbRangeMax The maximum RGB value.
378  \param outputIHSRaster An output pré-initiated raster (with the same dimensions of inputRGBRaster) where the IHS data will be written (double or float as the data type).
379  \return true if OK, false on errors.
380  \note The outputIHSRaster mas have a float or double data type.
381  \note IHS data with the following channels ranges: I:[0,1] H:[0,2pi] (radians) S:[0,1].
382  \ingroup rp_func
383  */
384  TERPEXPORT bool ConvertRGB2IHS( const te::rst::Raster& inputRGBRaster,
385  const unsigned int redBandIdx, const unsigned int greenBandIdx,
386  const unsigned int blueBandIdx, const double rgbRangeMin,
387  const double rgbRangeMax, te::rst::Raster& outputIHSRaster );
388 
389  /*!
390  \brief RGB to IHS conversion.
391  \param inputRedRaster The input red raster.
392  \param redBandIdx The red band index.
393  \param inputGreenRaster The input green raster.
394  \param greenBandIdx The green band index.
395  \param inputBlueRaster The input blue raster.
396  \param blueBandIdx The blue band index.
397  \param rgbRangeMin The minimum RGB value.
398  \param rgbRangeMax The maximum RGB value.
399  \param outputIHSRaster An output pré-initiated raster (with the same dimensions of inputRGBRaster) where the IHS data will be written (double or float as the data type).
400  \return true if OK, false on errors.
401  \note The outputIHSRaster mas have a float or double data type.
402  \note IHS data with the following channels ranges: I:[0,1] H:[0,2pi] (radians) S:[0,1].
403  \ingroup rp_func
404  */
405  TERPEXPORT bool ConvertRGB2IHS(const te::rst::Raster& inputRedRaster, const unsigned int redBandIdx,
406  const te::rst::Raster& inputGreenRaster, const unsigned int greenBandIdx,
407  const te::rst::Raster& inputBlueRaster, const unsigned int blueBandIdx,
408  const double rgbRangeMin, const double rgbRangeMax, te::rst::Raster& outputIHSRaster);
409 
410  /*!
411  \brief IHS to RGB conversion.
412  \param inputIHSRaster The input raster.
413  \param intensityBandIdx The intensity band index.
414  \param hueBandIdx The hue band index.
415  \param saturationBandIdx The saturation band index.
416  \param rgbRangeMin The minimum RGB value.
417  \param rgbRangeMax The maximum RGB value.
418  \param outputRGBRaster An output pré-initiated raster (with the same dimensions of inputIHSRaster) where the RGB data will be written.
419  \return true if OK, false on errors.
420  \note IHS data with the following channels ranges: I:[0,1] H:[0,2pi] (radians) S:[0,1].
421  \ingroup rp_func
422  */
423  TERPEXPORT bool ConvertIHS2RGB( const te::rst::Raster& inputIHSRaster,
424  const unsigned int intensityBandIdx, const unsigned int hueBandIdx,
425  const unsigned int saturationBandIdx, const double rgbRangeMin,
426  const double rgbRangeMax, te::rst::Raster& outputRGBRaster );
427 
428  /*!
429  \brief IHS to RGB conversion.
430  \param inputIRaster The input intensity raster.
431  \param intensityBandIdx The intensity band index.
432  \param inputHRaster The input hue raster.
433  \param hueBandIdx The hue band index.
434  \param inputSRaster The input saturation raster.
435  \param saturationBandIdx The saturation band index.
436  \param rgbRangeMin The minimum RGB value.
437  \param rgbRangeMax The maximum RGB value.
438  \param outputRGBRaster An output pré-initiated raster (with the same dimensions of inputIHSRaster) where the RGB data will be written.
439  \return true if OK, false on errors.
440  \note IHS data with the following channels ranges: I:[0,1] H:[0,2pi] (radians) S:[0,1].
441  \ingroup rp_func
442  */
443  TERPEXPORT bool ConvertIHS2RGB(const te::rst::Raster& inputIRaster, const unsigned int intensityBandIdx,
444  const te::rst::Raster& inputHRaster, const unsigned int hueBandIdx,
445  const te::rst::Raster& inputSRaster, const unsigned int saturationBandIdx,
446  const double rgbRangeMin, const double rgbRangeMax, te::rst::Raster& outputRGBRaster);
447 
448  /*!
449  \brief RGB to HLS conversion.
450  \param inputRGBRaster The input raster.
451  \param redBandIdx The red band index.
452  \param greenBandIdx The red band index.
453  \param blueBandIdx The red band index.
454  \param rgbRangeMin The minimum RGB value.
455  \param rgbRangeMax The maximum RGB value.
456  \param outputHLSRaster An output pré-initiated raster (with the same dimensions of inputRGBRaster) where the HLS data will be written (double or float as the data type).
457  \return true if OK, false on errors.
458  \note The outputHLSRaster mas have a float or double data type.
459  \ingroup rp_func
460  */
461  TERPEXPORT bool ConvertRGB2HLS(const te::rst::Raster& inputRGBRaster,
462  const unsigned int redBandIdx, const unsigned int greenBandIdx,
463  const unsigned int blueBandIdx, const double rgbRangeMin,
464  const double rgbRangeMax, te::rst::Raster& outputHLSRaster);
465 
466  /*!
467  \brief RGB to HLS conversion.
468  \param inputRedRaster The input red raster.
469  \param redBandIdx The red band index.
470  \param inputGreenRaster The input green raster.
471  \param greenBandIdx The green band index.
472  \param inputBlueRaster The input blue raster.
473  \param blueBandIdx The blue band index.
474  \param rgbRangeMin The minimum RGB value.
475  \param rgbRangeMax The maximum RGB value.
476  \param outputHLSRaster An output pré-initiated raster (with the same dimensions of inputRGBRaster) where the HLS data will be written (double or float as the data type).
477  \return true if OK, false on errors.
478  \note The outputHLSRaster mas have a float or double data type.
479  \ingroup rp_func
480  */
481  TERPEXPORT bool ConvertRGB2HLS(const te::rst::Raster& inputRedRaster, const unsigned int redBandIdx,
482  const te::rst::Raster& inputGreenRaster, const unsigned int greenBandIdx,
483  const te::rst::Raster& inputBlueRaster, const unsigned int blueBandIdx,
484  const double rgbRangeMin, const double rgbRangeMax, te::rst::Raster& outputHLSRaster);
485 
486  /*!
487  \brief HLS to RGB conversion.
488  \param inputHLSRaster The input raster.
489  \param hueBandIdx The hue band index.
490  \param lightBandIdx The light band index.
491  \param saturationBandIdx The saturation band index.
492  \param rgbRangeMin The minimum RGB value.
493  \param rgbRangeMax The maximum RGB value.
494  \param outputRGBRaster An output pré-initiated raster (with the same dimensions of inputHLSRaster) where the RGB data will be written.
495  \return true if OK, false on errors.
496  \ingroup rp_func
497  */
498  TERPEXPORT bool ConvertHLS2RGB(const te::rst::Raster& inputHLSRaster,
499  const unsigned int hueBandIdx, const unsigned int lightBandIdx,
500  const unsigned int saturationBandIdx, const double rgbRangeMin,
501  const double rgbRangeMax, te::rst::Raster& outputRGBRaster);
502 
503  /*!
504  \brief HLS to RGB conversion.
505  \param inputHRaster The input hue raster.
506  \param hueBandIdx The hue band index.
507  \param inputLRaster The input light raster.
508  \param lightBandIdx The light band index.
509  \param inputSRaster The input saturation raster.
510  \param saturationBandIdx The saturation band index.
511  \param rgbRangeMin The minimum RGB value.
512  \param rgbRangeMax The maximum RGB value.
513  \param outputRGBRaster An output pré-initiated raster (with the same dimensions of inputHLSRaster) where the RGB data will be written.
514  \return true if OK, false on errors.
515  \ingroup rp_func
516  */
517  TERPEXPORT bool ConvertHLS2RGB(const te::rst::Raster& inputHRaster, const unsigned int hueBandIdx,
518  const te::rst::Raster& inputLRaster, const unsigned int lightBandIdx,
519  const te::rst::Raster& inputSRaster, const unsigned int saturationBandIdx,
520  const double rgbRangeMin, const double rgbRangeMax, te::rst::Raster& outputRGBRaster);
521 
522  /*!
523  \brief Get the mean of band pixel values.
524  \param band The input raster band.
525  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
526  \param meanValue The calculated mean value.
527  \return true if OK, false on errors.
528  \note Optimized for rasters where the used bands have the same blocking scheme.
529  \ingroup rp_func
530  */
531  TERPEXPORT bool GetMeanValue(
532  const te::rst::Band& band,
533  const unsigned int maxThreads,
534  double& meanValue );
535 
536  /*!
537  \brief Get the standard deviation of band pixel values.
538  \param band The input raster band.
539  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
540  \param meanValuePtr A pointer to a pre-calculated band mean value or zero if it does not exist.
541  \param stdDevValue The calculated standard deviation value.
542  \return true if OK, false on errors.
543  \note Optimized for rasters where the used bands have the same blocking scheme.
544  \ingroup rp_func
545  */
547  const te::rst::Band& band,
548  const unsigned int maxThreads,
549  double const * const meanValuePtr,
550  double& stdDevValue );
551 
552  /*!
553  \brief Get the covariance of band pixel values.
554  \param band1 The input band 1.
555  \param band2 The input band 2.
556  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
557  \param mean1ValuePtr A pointer to a pre-calculated band1 mean value or zero if it does not exist.
558  \param mean2ValuePtr A pointer to a pre-calculated band2 mean value or zero if it does not exist.
559  \param covarianceValue The calculated covariance value.
560  \return true if OK, false on errors.
561  \note Optimized for rasters where the used bands have the same blocking scheme.
562  \ingroup rp_func
563  */
565  const te::rst::Band& band1,
566  const te::rst::Band& band2,
567  const unsigned int maxThreads,
568  double const * const mean1ValuePtr,
569  double const * const mean2ValuePtr,
570  double& covarianceValue );
571 
572  /*!
573  \brief Generate all principal components from the given input raster.
574  \param inputRaster Input raster.
575  \param inputRasterBands Input raster bands.
576  \param pcaMatrix The matrix generated over the principal components process.
577  \param pcaRaster The pré-initiated output PCA raster (with the same dimensions of inputRaster) and double as the data type.
578  \param pcaRasterBands Output raster bands.
579  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
580  \return true if OK, false on errors.
581  \note Optimized for rasters where the used bands have the same blocking scheme.
582  \ingroup rp_func
583  */
585  const te::rst::Raster& inputRaster,
586  const std::vector< unsigned int >& inputRasterBands,
587  boost::numeric::ublas::matrix< double >& pcaMatrix,
588  te::rst::Raster& pcaRaster,
589  const std::vector< unsigned int >& pcaRasterBands,
590  const unsigned int maxThreads );
591 
592  /*!
593  \brief Regenerate the original raster from its principal components.
594  \param pcaRaster The principal components raster (with the same dimensions of outputRaster).
595  \param pcaMatrix The matrix generated by the direct principal components process.
596  \param outputRaster The regenerated output raster (with the same dimentions.
597  \param outputRasterBands Output raster bands.
598  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
599  \return true if OK, false on errors.
600  \note Optimized for rasters where the used bands have the same blocking scheme.
601  \ingroup rp_func
602  */
604  const te::rst::Raster& pcaRaster,
605  const boost::numeric::ublas::matrix< double >& pcaMatrix,
606  te::rst::Raster& outputRaster,
607  const std::vector< unsigned int >& outputRasterBands,
608  const unsigned int maxThreads );
609 
610  /*!
611  \brief Remap pixel values using a remap function matrix.
612  \param inputRaster Input raster.
613  \param inputRasterBands Input raster bands.
614  \param remapMatrix The remap function matrix.
615  \param outputRaster The pré-initiated output raster (with the same dimentions of inputRaster).
616  \param outputRasterBands Output raster bands.
617  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
618  \return true if OK, false on errors.
619  \note Optimized for rasters where the used bands have the same blocking scheme.
620  \ingroup rp_func
621  */
622  TERPEXPORT bool RemapValues(
623  const te::rst::Raster& inputRaster,
624  const std::vector< unsigned int >& inputRasterBands,
625  const boost::numeric::ublas::matrix< double >& remapMatrix,
626  te::rst::Raster& outputRaster,
627  const std::vector< unsigned int >& outputRasterBands,
628  const unsigned int maxThreads );
629 
630  /*!
631  \brief Decompose a multi-band raster into a set of one-band rasters.
632  \param inputRaster Input raster.
633  \param inputRasterBands Input raster bands.
634  \param outputRastersInfos Output rasters connections infos. (one info for each decomposed band).
635  \param outputDataSourceType Output raster datasource type.
636  \param outputRastersPtrs Pointers to the generated outputs rasters.
637  \return true if OK, false on errors.
638  \ingroup rp_func
639  */
641  const te::rst::Raster& inputRaster,
642  const std::vector< unsigned int >& inputRasterBands,
643  const std::vector< std::map<std::string, std::string> > & outputRastersInfos,
644  const std::string& outputDataSourceType,
645  std::vector< boost::shared_ptr< te::rst::Raster > > & outputRastersPtrs );
646 
647  /*!
648  \brief Compose a set of bands into one multi-band raster.
649  \param feeder Input rasters feeder.
650  \param inputRasterBands Input raster bands (one band for each input raster).
651  \param interpMethod The interpolator method to use.
652  \param outputRasterInfo Output raster connection info.
653  \param outputDataSourceType Output raster datasource type.
654  \param outputRasterPtr A pointer to the generated output raster.
655  \return true if OK, false on errors.
656  \note The first raster Grid will be taken as reference for the composed raster.
657  \ingroup rp_func
658  */
659  TERPEXPORT bool ComposeBands(
661  const std::vector< unsigned int >& inputRasterBands,
662  const te::rst::Interpolator::Method& interpMethod,
663  const std::map<std::string, std::string>& outputRasterInfo,
664  const std::string& outputDataSourceType,
665  std::auto_ptr< te::rst::Raster >& outputRasterPtr );
666 
667  /*!
668  \brief Create a datailed extent from the given grid.
669  \param grid Input grid.
670  \param detailedExtent The created detailed extent.
671  \return true if ok, false on errors.
672  \ingroup rp_func
673  */
674  TERPEXPORT bool GetDetailedExtent( const te::rst::Grid& grid,
675  te::gm::LinearRing& detailedExtent );
676 
677  /*!
678  \brief Create a indexed (lines,columns) datailed extent from the given grid.
679  \param grid Input grid.
680  \param indexedDetailedExtent The created detailed extent.
681  \return true if ok, false on errors.
682  \ingroup rp_func
683  */
685  te::gm::LinearRing& indexedDetailedExtent );
686 
687  /*!
688  \brief Create a Wavele Atrous Filter.
689  \param filterType The filter type.
690  \return the created filter.
691  \ingroup rp_func
692  */
693  TERPEXPORT boost::numeric::ublas::matrix< double >
695 
696  /*!
697  \brief Generate all wavelet planes from the given input raster.
698  \param inputRaster Input raster.
699  \param inputRasterBands Input raster bands.
700  \param waveletRaster The pré-initiated output wavelet raster (with the same dimensions of inputRaster) and double as the data type.
701  \param levelsNumber The number of decomposed wavelet levels to generate for each input raster band;
702  \param filter The square filter to use.
703  \return true if OK, false on errors.
704  \note The band order of the generated wavelet levels: { [ band0-smoothed0, band0-wavelet0, ... , band0-smoothedN, band0-waveletN ], ... }
705  \note The number of bands of waveletRaster must be ( inputRasterBands.size() * 2 * levelsNumber ) at least.
706  \ingroup rp_func
707  */
709  const te::rst::Raster& inputRaster,
710  const std::vector< unsigned int >& inputRasterBands,
711  te::rst::Raster& waveletRaster,
712  const unsigned int levelsNumber,
713  const boost::numeric::ublas::matrix< double >& filter );
714 
715  /*!
716  \brief Regenerate the original raster from its wavelets planes.
717  \param waveletRaster The input wavelet raster (with the same dimensions of outputRaster).
718  \param levelsNumber The number of decomposed wavelet levels present inside the wavelet raster.
719  \param outputRaster The regenerated output raster.
720  \param outputRasterBands Output raster bands.
721  \return true if OK, false on errors.
722  \note The band order of the expected wavelet levels: { [ band0-smoothed0, band0-wavelet0, ... , band0-smoothedN, band0-waveletN ], ... }
723  \note The number of bands of waveletRaster must be ( outputRasterBands.size() * 2 * levelsNumber ) at least.
724  \note Only the wavelet bands and the last smoothed band are used.
725  \ingroup rp_func
726  */
728  const te::rst::Raster& waveletRaster,
729  const unsigned int levelsNumber,
730  te::rst::Raster& outputRaster,
731  const std::vector< unsigned int >& outputRasterBands );
732 
733  /*!
734  \brief Resample a subset of the raster, given a box.
735  \param inputRaster Input raster.
736  \param inputRasterBands Input raster bands to process.
737  \param interpMethod The method of interpolation. \sa te::rst::Interpolator
738  \param firstRow The starting row to make a subset of the image.
739  \param firstColumn The starting column to make a subset of the image.
740  \param height The height of the subset.
741  \param width The width of the subset.
742  \param newheight The resampled height of the new raster.
743  \param newwidth The resampled width of the new raster.
744  \param rinfo The parameters needed to build the output raster (see RasterFactory documentation).
745  \param dataSourceType Data source type (raster type. I.E. GDAL).
746  \param resampledRasterPtr The resampled raster pointer.
747  \return true if ok, false on errors.
748  */
750  const te::rst::Raster& inputRaster,
751  const std::vector< unsigned int >& inputRasterBands,
752  const te::rst::Interpolator::Method interpMethod,
753  const unsigned int firstRow,
754  const unsigned int firstColumn,
755  const unsigned int height,
756  const unsigned int width,
757  const unsigned int newheight,
758  const unsigned int newwidth,
759  const std::map<std::string, std::string>& rinfo,
760  const std::string& dataSourceType,
761  std::auto_ptr< te::rst::Raster >& resampledRasterPtr );
762 
763  /*!
764  \brief Returns the tie points converx hull area.
765  \param tiePoints Input tie-points (container of te::gm::GTParameters::TiePoint).
766  \param useTPSecondCoordPair If true the sencond tie-point component (te::gm::GTParameters::TiePoint::second) will be used for the area calcule, otherwize the first component will be used.
767  \return Returns the tie points converx hull area.
768  */
769  template< typename ContainerT >
770  double GetTPConvexHullArea( const ContainerT& tiePoints,
771  const bool useTPSecondCoordPair )
772  {
773  if( tiePoints.size() < 3 )
774  {
775  return 0;
776  }
777  else
778  {
780 
781  typename ContainerT::const_iterator it =
782  tiePoints.begin();
783  const typename ContainerT::const_iterator itE =
784  tiePoints.end();
785 
786  while( it != itE )
787  {
788  if( useTPSecondCoordPair )
789  points.add(new te::gm::Point(it->second.x, it->second.y));
790  else
791  points.add(new te::gm::Point(it->first.x, it->first.y));
792 
793  ++it;
794  }
795 
796  std::auto_ptr< te::gm::Geometry > convexHullPolPtr( points.convexHull() );
797 
798  if( dynamic_cast< te::gm::Surface* >( convexHullPolPtr.get() ) )
799  {
800  return ( (te::gm::Surface*)( convexHullPolPtr.get() ) )->getArea();
801  }
802  else
803  {
804  return 0.0;
805  }
806  }
807  }
808 
809  /*!
810  \brief Create a fixed step sequential color palette.
811  \param paletteSize The desired palette size.
812  \param palette The crated palette.
813  */
815  const double paletteSize,
816  const bool randomize,
817  std::vector< te::rst::BandProperty::ColorEntry >& palette );
818 
819  /*!
820  \brief Generate all wavelet planes from the given input raster.
821  \param inputRaster Input raster.
822  \param inputRasterBand Input raster band.
823  \param createPaletteRaster If true a paletted raster will be created instead of a multi-band raster..
824  \param slicesNumber The number of historgram slices to create;
825  \param eqHistogram If true, the input raster will historgram will be equalized before the slicing process.
826  \param rasterInfo The output raster info (specific driver info).
827  \param rasterType The output raster type (specific driver name - See te::rst::RasterFactory dictorary for more info).
828  \param enableProgress Enable/disable the progress interface.
829  \param palettePtr A pointer to an optional user given palette (if null, an fixed step pallete will be generated).
830  \param outRasterPtr The output sliced raster pointer.
831  \return true if OK, false on errors.
832  \ingroup rp_func
833  */
835  const te::rst::Raster& inputRaster,
836  const unsigned int inputRasterBand,
837  const bool createPaletteRaster,
838  const unsigned int slicesNumber,
839  const bool eqHistogram,
840  const std::map< std::string, std::string >& rasterInfo,
841  const std::string& rasterType,
842  const bool enableProgress,
843  std::vector< te::rst::BandProperty::ColorEntry > const * const palettePtr,
844  std::auto_ptr< te::rst::Raster >& outRasterPtr );
845 
846  } // end namespace rp
847 } // end namespace te
848 
849 #endif // __TERRALIB_RP_INTERNAL_FUNCTIONS_H
850 
TERPEXPORT bool GetMeanValue(const te::rst::Band &band, const unsigned int maxThreads, double &meanValue)
Get the mean of band pixel values.
TERPEXPORT double GetDigitalNumberBandMax(std::string bandName)
Returns the maximum digital number of a given sensor/band.
Index into a lookup table.
Definition: Enums.h:57
A raster band description.
Definition: BandProperty.h:61
virtual Geometry * convexHull() const
This method calculates the Convex Hull of a geometry.
double GetTPConvexHullArea(const ContainerT &tiePoints, const bool useTPSecondCoordPair)
Returns the tie points converx hull area.
Definition: Functions.h:770
Spline filter type.
Definition: Functions.h:76
Triangle filter type.
Definition: Functions.h:77
TERPEXPORT bool ConvertIHS2RGB(const te::rst::Raster &inputIHSRaster, const unsigned int intensityBandIdx, const unsigned int hueBandIdx, const unsigned int saturationBandIdx, const double rgbRangeMin, const double rgbRangeMax, te::rst::Raster &outputRGBRaster)
IHS to RGB conversion.
void TERPEXPORT GetDataTypeRange(const int dataType, double &min, double &max)
Returns the real data type range (all values that can be represented by the given data type)...
Definition: Functions.h:196
TERPEXPORT bool ComposeBands(te::rp::FeederConstRaster &feeder, const std::vector< unsigned int > &inputRasterBands, const te::rst::Interpolator::Method &interpMethod, const std::map< std::string, std::string > &outputRasterInfo, const std::string &outputDataSourceType, std::auto_ptr< te::rst::Raster > &outputRasterPtr)
Compose a set of bands into one multi-band raster.
bool TERPEXPORT CreateNewMemRaster(const te::rst::Grid &rasterGrid, std::vector< te::rst::BandProperty * > bandsProperties, RasterHandler &outRasterHandler)
Create a new raster into a new memory datasource.
TERPEXPORT std::vector< std::string > GetBandNames()
Returns a vector os with band's names.
TERASTEREXPORT void GetDataTypeRanges(const int &dataType, double &min, double &max)
Return the values range of a given data type.
TERPEXPORT std::pair< double, double > GetDigitalNumberBandInfo(std::string bandName)
Returns the maximun and minimum digital numbers of a given sensor/band.
An abstract class for data providers like a DBMS, Web Services or a regular file. ...
Definition: DataSource.h:119
TERPEXPORT bool DirectPrincipalComponents(const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, boost::numeric::ublas::matrix< double > &pcaMatrix, te::rst::Raster &pcaRaster, const std::vector< unsigned int > &pcaRasterBands, const unsigned int maxThreads)
Generate all principal components from the given input raster.
TERPEXPORT bool DecomposeBands(const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, const std::vector< std::map< std::string, std::string > > &outputRastersInfos, const std::string &outputDataSourceType, std::vector< boost::shared_ptr< te::rst::Raster > > &outputRastersPtrs)
Decompose a multi-band raster into a set of one-band rasters.
TERPEXPORT double GetDigitalNumberBandMin(std::string bandName)
Returns the minimum digital number of a given sensor/band.
InterpolationMethod
Allowed interpolation methods.
Definition: Enums.h:92
TERPEXPORT double GetSpectralBandMax(std::string bandName)
Returns the maximum reflectance value of a given sensor/band.
TERPEXPORT bool RemapValues(const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, const boost::numeric::ublas::matrix< double > &remapMatrix, te::rst::Raster &outputRaster, const std::vector< unsigned int > &outputRasterBands, const unsigned int maxThreads)
Remap pixel values using a remap function matrix.
TERPEXPORT std::pair< double, double > GetSpectralBandInfo(std::string bandName)
Returns the maximun and minimum reflectance values of a given sensor/band.
TERPEXPORT bool ConvertRGB2IHS(const te::rst::Raster &inputRGBRaster, const unsigned int redBandIdx, const unsigned int greenBandIdx, const unsigned int blueBandIdx, const double rgbRangeMin, const double rgbRangeMax, te::rst::Raster &outputIHSRaster)
RGB to IHS conversion.
#define TERP_TRUE_OR_RETURN_FALSE(value, message)
Checks if value is true. For false values a warning message will be logged and a return of context wi...
Definition: Macros.h:184
TERPEXPORT bool ConvertHLS2RGB(const te::rst::Raster &inputHLSRaster, const unsigned int hueBandIdx, const unsigned int lightBandIdx, const unsigned int saturationBandIdx, const double rgbRangeMin, const double rgbRangeMax, te::rst::Raster &outputRGBRaster)
HLS to RGB conversion.
bool CreateRasterFileFromMatrix(const te::rp::Matrix< MatrixElementT > &matrix, const bool normalize, const std::string &fileName)
Create a tiff file from a matrix.
Definition: Functions.h:235
bool TERPEXPORT Copy2DiskRaster(const te::rst::Raster &inputRaster, const std::string &fileName)
Create a new raster into a GDAL datasource.
A LinearRing is a LineString that is both closed and simple.
Definition: LinearRing.h:53
MultiPoint is a GeometryCollection whose elements are restricted to points.
Definition: MultiPoint.h:50
A point with x and y coordinate values.
Definition: Point.h:50
TERPEXPORT bool NormalizeRaster(te::rst::Raster &inputRaster, double nmin=0.0, double nmax=255.0)
Normalizes one raster in a given interval.
An abstract class for raster data strucutures.
Definition: Raster.h:71
unsigned int getColumnsNumber() const
The number of current matrix columns.
Definition: Matrix.h:681
TERPEXPORT bool InverseWaveletAtrous(const te::rst::Raster &waveletRaster, const unsigned int levelsNumber, te::rst::Raster &outputRaster, const std::vector< unsigned int > &outputRasterBands)
Regenerate the original raster from its wavelets planes.
WaveletAtrousFilterType
Wavelet Atrous Filter types.
Definition: Functions.h:73
URI C++ Library.
TERPEXPORT bool DirectWaveletAtrous(const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, te::rst::Raster &waveletRaster, const unsigned int levelsNumber, const boost::numeric::ublas::matrix< double > &filter)
Generate all wavelet planes from the given input raster.
#define TERPEXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:139
Raster tuple.
void TERPEXPORT Convert2DoublesVector(void *inputVector, const int inputVectorDataType, unsigned int inputVectorSize, double *outputVector)
Convert vector elements.
A raster band description.
Definition: Band.h:63
TERPEXPORT bool GetDetailedExtent(const te::rst::Grid &grid, te::gm::LinearRing &detailedExtent)
Create a datailed extent from the given grid.
Generic template matrix.
TERPEXPORT void CreateFixedStepPalette(const double paletteSize, const bool randomize, std::vector< te::rst::BandProperty::ColorEntry > &palette)
Create a fixed step sequential color palette.
TERPEXPORT bool ConvertRGB2HLS(const te::rst::Raster &inputRGBRaster, const unsigned int redBandIdx, const unsigned int greenBandIdx, const unsigned int blueBandIdx, const double rgbRangeMin, const double rgbRangeMax, te::rst::Raster &outputHLSRaster)
RGB to HLS conversion.
bool TERPEXPORT CreateNewRaster(const te::rst::Grid &rasterGrid, const std::vector< te::rst::BandProperty * > &bandsProperties, const std::string &outDataSetName, const std::string &dataSourceType, RasterHandler &outRasterHandler)
Create a new raster into the givem data source.
Invalid filter type.
Definition: Functions.h:75
TERPEXPORT boost::numeric::ublas::matrix< double > CreateWaveletAtrousFilter(const WaveletAtrousFilterType &filterType)
Create a Wavele Atrous Filter.
TERPEXPORT bool GetCovarianceValue(const te::rst::Band &band1, const te::rst::Band &band2, const unsigned int maxThreads, double const *const mean1ValuePtr, double const *const mean2ValuePtr, double &covarianceValue)
Get the covariance of band pixel values.
Configuration flags for the Raster Processing module of TerraLib.
TERPEXPORT double GetSpectralBandMin(std::string bandName)
Returns the minimum reflectance value of a given sensor/band.
Feeder from a input rasters.
Definition: FeedersRaster.h:46
void add(Geometry *g)
It adds the geometry into the collection.
A generic template matrix.
Definition: Matrix.h:54
TERPEXPORT bool GetIndexedDetailedExtent(const te::rst::Grid &grid, te::gm::LinearRing &indexedDetailedExtent)
Create a indexed (lines,columns) datailed extent from the given grid.
TERPEXPORT bool InversePrincipalComponents(const te::rst::Raster &pcaRaster, const boost::numeric::ublas::matrix< double > &pcaMatrix, te::rst::Raster &outputRaster, const std::vector< unsigned int > &outputRasterBands, const unsigned int maxThreads)
Regenerate the original raster from its principal components.
TERPEXPORT bool RasterResample(const te::rst::Raster &inputRaster, const std::vector< unsigned int > &inputRasterBands, const te::rst::Interpolator::Method interpMethod, const unsigned int firstRow, const unsigned int firstColumn, const unsigned int height, const unsigned int width, const unsigned int newheight, const unsigned int newwidth, const std::map< std::string, std::string > &rinfo, const std::string &dataSourceType, std::auto_ptr< te::rst::Raster > &resampledRasterPtr)
Resample a subset of the raster, given a box.
bool TERPEXPORT CreateNewGdalRaster(const te::rst::Grid &rasterGrid, std::vector< te::rst::BandProperty * > bandsProperties, const std::string &fileName, RasterHandler &outRasterHandler)
Create a new raster into a GDAL datasource.
static Raster * make()
It creates and returns an empty raster with default raster driver.
Raster objects feeders.
A rectified grid is the spatial support for raster data.
Definition: Grid.h:68
unsigned int getLinesNumber() const
The number of current matrix lines.
Definition: Matrix.h:674
TERPEXPORT bool GetStdDevValue(const te::rst::Band &band, const unsigned int maxThreads, double const *const meanValuePtr, double &stdDevValue)
Get the standard deviation of band pixel values.
TERPEXPORT bool RasterSlicing(const te::rst::Raster &inputRaster, const unsigned int inputRasterBand, const bool createPaletteRaster, const unsigned int slicesNumber, const bool eqHistogram, const std::map< std::string, std::string > &rasterInfo, const std::string &rasterType, const bool enableProgress, std::vector< te::rst::BandProperty::ColorEntry > const *const palettePtr, std::auto_ptr< te::rst::Raster > &outRasterPtr)
Generate all wavelet planes from the given input raster.
void TERPEXPORT ConvertDoublesVector(double *inputVector, unsigned int inputVectorSize, const int outputVectorDataType, void *outputVector)
Convert a doubles vector.
Surface is an abstract class that represents a 2-dimensional geometric objects.
Definition: Surface.h:54