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 "../dataaccess/datasource/DataSource.h"
34 #include "../raster/Raster.h"
35 #include "../raster/RasterFactory.h"
36 #include "../raster/Grid.h"
37 #include "../raster/BandProperty.h"
38 #include "../raster/RasterFactory.h"
39 #include "../raster/Interpolator.h"
40 #include "../raster/Utils.h"
41 #include "../srs/Converter.h"
42 #include "../geometry/LinearRing.h"
43 #include "../geometry/GTParameters.h"
44 #include "../geometry/MultiPoint.h"
45 #include "../geometry/Surface.h"
46 
47 // STL
48 #include <memory>
49 #include <map>
50 #include <vector>
51 #include <string>
52 #include <limits>
53 
54 // Boost
55 #include <boost/numeric/ublas/matrix.hpp>
56 #include <boost/shared_ptr.hpp>
57 
58 namespace te
59 {
60  namespace rst
61  {
62  class BandProperty;
63  class Grid;
64  }
65 
66  namespace rp
67  {
68  class RasterHandler;
69 
70  /*!
71  \brief Wavelet Atrous Filter types.
72  \ingroup rp_func
73  */
75  {
76  InvalidWAFilter, //!< Invalid filter type
77  B3SplineWAFilter, //!< Spline filter type.
78  TriangleWAFilter //!< Triangle filter type.
79  };
80 
81  /*!
82  \brief Create a new raster into the givem data source.
83  \param rasterGrid The template grid used to create the output raster.
84  \param bandsProperties The template band properties used to create the output raster.
85  \param outDataSetName The data set name to give to the created data set.
86  \param dataSourceType The data source type string (i.e. GDAL, MEM.)( See te::rst::RasterFactory dictionary for valid registered values ).
87  \param outRasterHandler The created raster handler.
88  \return true if OK, false on errors.
89  \note All bandsProperties pointed objects will be acquired by this function and must not be deleted.
90  \ingroup rp_func
91  */
92  bool TERPEXPORT CreateNewRaster( const te::rst::Grid& rasterGrid,
93  const std::vector< te::rst::BandProperty* >& bandsProperties,
94  const std::string& outDataSetName,
95  const std::string& dataSourceType,
96  RasterHandler& outRasterHandler );
97 
98  /*!
99  \brief Create a new raster into the givem data source.
100  \param rasterGrid The template grid used to create the output raster.
101  \param bandsProperties The template band properties used to create the output raster.
102  \param outDataSetName The data set name to give to the created data set.
103  \param outDataSource The data source to use when creating the output data set.
104  \param outRasterHandler The created raster handler.
105  \return true if OK, false on errors.
106  \note All bandsProperties pointed objects will be acquired by this function and must not be deleted.
107  \ingroup rp_func
108  */
109  bool TERPEXPORT CreateNewRaster( const te::rst::Grid& rasterGrid,
110  const std::vector< te::rst::BandProperty* >& bandsProperties,
111  const std::string& outDataSetName,
112  te::da::DataSource& outDataSource,
113  RasterHandler& outRasterHandler );
114 
115  /*!
116  \brief Create a new raster into a new memory datasource.
117  \param rasterGrid The template grid used to create the output raster.
118  \param bandsProperties The template band properties used to create the output raster.
119  \param outRasterHandler The created raster handler.
120  \return true if OK, false on errors.
121  \note All bandsProperties pointed objects will be acquired by this function and must not be deleted.
122  \ingroup rp_func
123  */
124  bool TERPEXPORT CreateNewMemRaster( const te::rst::Grid& rasterGrid,
125  std::vector< te::rst::BandProperty* > bandsProperties,
126  RasterHandler& outRasterHandler );
127 
128  /*!
129  \brief Create a new raster into a GDAL datasource.
130  \param rasterGrid The template grid used to create the output raster.
131  \param bandsProperties The template band properties used to create the output raster.
132  \param fileName The output tif file name.
133  \param outRasterHandler The created raster handler.
134  \return true if OK, false on errors.
135  \note All bandsProperties pointed objects will be acquired by this function and must not be deleted.
136  \ingroup rp_func
137  */
138  bool TERPEXPORT CreateNewGdalRaster( const te::rst::Grid& rasterGrid,
139  std::vector< te::rst::BandProperty* > bandsProperties,
140  const std::string& fileName,
141  RasterHandler& outRasterHandler );
142 
143  /*!
144  \brief Create a new raster into a GDAL datasource.
145  \param rasterGrid The template grid used to create the output raster.
146  \param bandsProperties The template band properties used to create the output raster.
147  \param fileName The output tif file name.
148  \param outRasterPtr The created raster pointer.
149  \return true if OK, false on errors.
150  \note All bandsProperties pointed objects will be acquired by this function and must not be deleted.
151  \ingroup rp_func
152  */
153  bool TERPEXPORT CreateNewGdalRaster( const te::rst::Grid& rasterGrid,
154  std::vector< te::rst::BandProperty* > bandsProperties,
155  const std::string& fileName,
156  std::auto_ptr< te::rst::Raster >& outRasterPtr );
157 
158  /*!
159  \brief Create a new raster into a GDAL datasource.
160  \param rasterGrid The template grid used to create the output raster.
161  \param bandsProperties The template band properties used to create the output raster.
162  \param fileName The output tif file name.
163  \param outRasterHandler The created raster handler.
164  \return true if OK, false on errors.
165  \note All bandsProperties pointed objects will be acquired by this function and must not be deleted.
166  \ingroup rp_func
167  */
169  const te::rst::Raster& inputRaster,
170  const std::string& fileName );
171 
172  /*!
173  \brief Returns the real data type range (all values that can be represented by the given data type).
174  \param dataType The data type.
175  \param min The minimum value.
176  \param max The maximum value.
177  \note The types are listed in terralib/datatype/DataTypes.h
178  \ingroup rp_func
179  */
180  inline void TERPEXPORT GetDataTypeRange( const int dataType, double& min, double& max )
181  {
182  te::rst::GetDataTypeRanges( dataType, min, max );
183  }
184 
185  /*!
186  \brief Convert vector elements.
187  \param inputVector Input vector.
188  \param inputVectorDataType Input vector data type.
189  \param inputVectorSize The numer of input vector elements.
190  \param outputVector A pré-allocated output vector.
191  \note The types are listed in terralib/datatype/DataTypes.h
192  \ingroup rp_func
193  */
194  void TERPEXPORT Convert2DoublesVector( void* inputVector, const int inputVectorDataType,
195  unsigned int inputVectorSize, double* outputVector );
196 
197  /*!
198  \brief Convert a doubles vector.
199  \param inputVector Input vector.
200  \param inputVectorSize The numer of input vector elements.
201  \param inputVectorDataType Input vector data type.
202  \param outputVector A pré-allocated output vector.
203  \note The types are listed in terralib/datatype/DataTypes.h
204  \ingroup rp_func
205  */
206  void TERPEXPORT ConvertDoublesVector( double* inputVector,
207  unsigned int inputVectorSize, const int outputVectorDataType,
208  void* outputVector );
209 
210  /*!
211  \brief Create a tiff file from a matrix.
212  \param matrix The matrix.
213  \param normalize Enable/disable pixel normalization (8bit);
214  \param tifFileName Tif file name.
215  \param return true if OK, false on errors.
216  \ingroup rp_func
217  */
218  template< typename MatrixElementT >
220  const bool normalize, const std::string& fileName )
221  {
222  std::map<std::string, std::string> rInfo;
223  rInfo["URI"] = fileName;
224 
225  std::vector<te::rst::BandProperty*> bandsProperties;
226  if( normalize )
227  bandsProperties.push_back(new te::rst::BandProperty( 0, te::dt::UCHAR_TYPE, "" ));
228  else
229  bandsProperties.push_back(new te::rst::BandProperty( 0, te::dt::DOUBLE_TYPE, "" ));
230  bandsProperties[0]->m_colorInterp = te::rst::GrayIdxCInt;
231  bandsProperties[0]->m_noDataValue = -1.0 * std::numeric_limits<double>::max();
232 
233  te::rst::Grid* newgrid = new te::rst::Grid( matrix.getColumnsNumber(),
234  matrix.getLinesNumber(), 0, -1 );
235 
236  std::auto_ptr< te::rst::Raster > outputRasterPtr(
237  te::rst::RasterFactory::make( "GDAL", newgrid, bandsProperties, rInfo, 0, 0));
238  TERP_TRUE_OR_RETURN_FALSE( outputRasterPtr.get(), "Output raster creation error");
239 
240  unsigned int line = 0;
241  unsigned int col = 0;
242  const unsigned int nLines = matrix.getLinesNumber();
243  const unsigned int nCols = matrix.getColumnsNumber();
244  MatrixElementT matrixValue = 0;
245 
246  MatrixElementT gain = 1.0;
247  MatrixElementT offset = 0.0;
248  if( normalize )
249  {
250  MatrixElementT matrixValueMin = std::numeric_limits< MatrixElementT >::max();
251  MatrixElementT matrixValueMax = -1.0 * matrixValueMin;
252  for( line = 0 ; line < nLines ; ++line )
253  {
254  for( col = 0 ; col < nCols ; ++col )
255  {
256  matrixValue = matrix[ line ][ col ];
257  if( matrixValue < matrixValueMin )
258  matrixValueMin = matrixValue;
259  if( matrixValue > matrixValueMax )
260  matrixValueMax = matrixValue;
261  }
262  }
263 
264  if( matrixValueMax == matrixValueMin )
265  {
266  gain = 0.0;
267  offset = 0.0;
268  }
269  else
270  {
271  gain = 255.0 / ( matrixValueMax - matrixValueMin );
272  offset = -1.0 * ( matrixValueMin );
273  }
274  }
275 
276  const MatrixElementT min0 = 0;
277  const MatrixElementT max255 = 255;
278 
279  for( line = 0 ; line < nLines ; ++line )
280  {
281  for( col = 0 ; col < nCols ; ++col )
282  {
283  matrixValue = matrix[ line ][ col ];
284 
285  if( normalize )
286  {
287  matrixValue += offset;
288  matrixValue *= gain;
289  matrixValue = std::max( min0, matrixValue );
290  matrixValue = std::min( max255, matrixValue );
291  }
292 
293  outputRasterPtr->setValue( col, line, (double)matrixValue, 0 );
294  }
295  }
296 
297  return true;
298  }
299 
300  /*!
301  \brief Returns a vector os with band's names.
302  \ingroup rp_func
303  */
304  TERPEXPORT std::vector<std::string> GetBandNames();
305 
306  /*!
307  \brief Returns the maximun and minimum reflectance values of a given sensor/band.
308  \ingroup rp_func
309  */
310  TERPEXPORT std::pair<double, double> GetSpectralBandInfo(std::string bandName);
311 
312  /*!
313  \brief Returns the minimum reflectance value of a given sensor/band.
314  \ingroup rp_func
315  */
316  TERPEXPORT double GetSpectralBandMin(std::string bandName);
317 
318  /*!
319  \brief Returns the maximum reflectance value of a given sensor/band.
320  \ingroup rp_func
321  */
322  TERPEXPORT double GetSpectralBandMax(std::string bandName);
323 
324  /*!
325  \brief Returns the maximun and minimum digital numbers of a given sensor/band.
326  \ingroup rp_func
327  */
328  TERPEXPORT std::pair<double, double> GetDigitalNumberBandInfo(std::string bandName);
329 
330  /*!
331  \brief Returns the maximum digital number of a given sensor/band.
332  \ingroup rp_func
333  */
334  TERPEXPORT double GetDigitalNumberBandMax(std::string bandName);
335 
336  /*!
337  \brief Normalizes one raster in a given interval.
338 
339  \param inputRaster The given raster.
340  \param nmin The new minimum value (default = 0.0).
341  \param nmax The new maximum value (default = 255.0).
342 
343  \return true if normalization occurs and false otherwise.
344  \ingroup rp_func
345  */
346  TERPEXPORT bool NormalizeRaster(te::rst::Raster& inputRaster, double nmin = 0.0, double nmax = 255.0);
347 
348  /*!
349  \brief RGB to IHS conversion.
350  \param inputRGBRaster The input raster.
351  \param redBandIdx The red band index.
352  \param greenBandIdx The red band index.
353  \param blueBandIdx The red band index.
354  \param rgbRangeMin The minimum RGB value.
355  \param rgbRangeMax The maximum RGB value.
356  \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).
357  \return true if OK, false on errors.
358  \note The outputIHSRaster mas have a float or double data type.
359  \note IHS data with the following channels ranges: I:[0,1] H:[0,2pi] (radians) S:[0,1].
360  \ingroup rp_func
361  */
362  TERPEXPORT bool ConvertRGB2IHS( const te::rst::Raster& inputRGBRaster,
363  const unsigned int redBandIdx, const unsigned int greenBandIdx,
364  const unsigned int blueBandIdx, const double rgbRangeMin,
365  const double rgbRangeMax, te::rst::Raster& outputIHSRaster );
366 
367  /*!
368  \brief IHS to RGB conversion.
369  \param inputIHSRaster The input raster.
370  \param intensityBandIdx The intensity band index.
371  \param hueBandIdx The hue band index.
372  \param saturationBandIdx The saturation band index.
373  \param rgbRangeMin The minimum RGB value.
374  \param rgbRangeMax The maximum RGB value.
375  \param outputRGBRaster An output pré-initiated raster (with the same dimensions of inputIHSRaster) where the RGB data will be written.
376  \return true if OK, false on errors.
377  \note IHS data with the following channels ranges: I:[0,1] H:[0,2pi] (radians) S:[0,1].
378  \ingroup rp_func
379  */
380  TERPEXPORT bool ConvertIHS2RGB( const te::rst::Raster& inputIHSRaster,
381  const unsigned int intensityBandIdx, const unsigned int hueBandIdx,
382  const unsigned int saturationBandIdx, const double rgbRangeMin,
383  const double rgbRangeMax, te::rst::Raster& outputRGBRaster );
384 
385  /*!
386  \brief Get the mean of band pixel values.
387  \param band The input raster band.
388  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
389  \param meanValue The calculated mean value.
390  \return true if OK, false on errors.
391  \note Optimized for rasters where the used bands have the same blocking scheme.
392  \ingroup rp_func
393  */
394  TERPEXPORT bool GetMeanValue(
395  const te::rst::Band& band,
396  const unsigned int maxThreads,
397  double& meanValue );
398 
399  /*!
400  \brief Get the standard deviation of band pixel values.
401  \param band The input raster band.
402  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
403  \param meanValuePtr A pointer to a pre-calculated band mean value or zero if it does not exist.
404  \param stdDevValue The calculated standard deviation value.
405  \return true if OK, false on errors.
406  \note Optimized for rasters where the used bands have the same blocking scheme.
407  \ingroup rp_func
408  */
410  const te::rst::Band& band,
411  const unsigned int maxThreads,
412  double const * const meanValuePtr,
413  double& stdDevValue );
414 
415  /*!
416  \brief Get the covariance of band pixel values.
417  \param band1 The input band 1.
418  \param band2 The input band 2.
419  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
420  \param mean1ValuePtr A pointer to a pre-calculated band1 mean value or zero if it does not exist.
421  \param mean2ValuePtr A pointer to a pre-calculated band2 mean value or zero if it does not exist.
422  \param covarianceValue The calculated covariance value.
423  \return true if OK, false on errors.
424  \note Optimized for rasters where the used bands have the same blocking scheme.
425  \ingroup rp_func
426  */
428  const te::rst::Band& band1,
429  const te::rst::Band& band2,
430  const unsigned int maxThreads,
431  double const * const mean1ValuePtr,
432  double const * const mean2ValuePtr,
433  double& covarianceValue );
434 
435  /*!
436  \brief Generate all principal components from the given input raster.
437  \param inputRaster Input raster.
438  \param inputRasterBands Input raster bands.
439  \param pcaMatrix The matrix generated over the principal components process.
440  \param pcaRaster The pré-initiated output PCA raster (with the same dimensions of inputRaster) and double as the data type.
441  \param pcaRasterBands Output raster bands.
442  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
443  \return true if OK, false on errors.
444  \note Optimized for rasters where the used bands have the same blocking scheme.
445  \ingroup rp_func
446  */
448  const te::rst::Raster& inputRaster,
449  const std::vector< unsigned int >& inputRasterBands,
450  boost::numeric::ublas::matrix< double >& pcaMatrix,
451  te::rst::Raster& pcaRaster,
452  const std::vector< unsigned int >& pcaRasterBands,
453  const unsigned int maxThreads );
454 
455  /*!
456  \brief Regenerate the original raster from its principal components.
457  \param pcaRaster The principal components raster (with the same dimensions of outputRaster).
458  \param pcaMatrix The matrix generated by the direct principal components process.
459  \param outputRaster The regenerated output raster (with the same dimentions.
460  \param outputRasterBands Output raster bands.
461  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
462  \return true if OK, false on errors.
463  \note Optimized for rasters where the used bands have the same blocking scheme.
464  \ingroup rp_func
465  */
467  const te::rst::Raster& pcaRaster,
468  const boost::numeric::ublas::matrix< double >& pcaMatrix,
469  te::rst::Raster& outputRaster,
470  const std::vector< unsigned int >& outputRasterBands,
471  const unsigned int maxThreads );
472 
473  /*!
474  \brief Remap pixel values using a remap function matrix.
475  \param inputRaster Input raster.
476  \param inputRasterBands Input raster bands.
477  \param remapMatrix The remap function matrix.
478  \param outputRaster The pré-initiated output raster (with the same dimentions of inputRaster).
479  \param outputRasterBands Output raster bands.
480  \param maxThreads The maximum number of threads to use (0-auto, 1-single thread used).
481  \return true if OK, false on errors.
482  \note Optimized for rasters where the used bands have the same blocking scheme.
483  \ingroup rp_func
484  */
485  TERPEXPORT bool RemapValues(
486  const te::rst::Raster& inputRaster,
487  const std::vector< unsigned int >& inputRasterBands,
488  const boost::numeric::ublas::matrix< double >& remapMatrix,
489  te::rst::Raster& outputRaster,
490  const std::vector< unsigned int >& outputRasterBands,
491  const unsigned int maxThreads );
492 
493  /*!
494  \brief Decompose a multi-band raster into a set of one-band rasters.
495  \param inputRaster Input raster.
496  \param inputRasterBands Input raster bands.
497  \param outputRastersInfos Output rasters connections infos. (one info for each decomposed band).
498  \param outputDataSourceType Output raster datasource type.
499  \param outputRastersPtrs Pointers to the generated outputs rasters.
500  \return true if OK, false on errors.
501  \ingroup rp_func
502  */
504  const te::rst::Raster& inputRaster,
505  const std::vector< unsigned int >& inputRasterBands,
506  const std::vector< std::map<std::string, std::string> > & outputRastersInfos,
507  const std::string& outputDataSourceType,
508  std::vector< boost::shared_ptr< te::rst::Raster > > & outputRastersPtrs );
509 
510  /*!
511  \brief Compose a set of bands into one multi-band raster.
512  \param feeder Input rasters feeder.
513  \param inputRasterBands Input raster bands (one band for each input raster).
514  \param interpMethod The interpolator method to use.
515  \param outputRasterInfo Output raster connection info.
516  \param outputDataSourceType Output raster datasource type.
517  \param outputRasterPtr A pointer to the generated output raster.
518  \return true if OK, false on errors.
519  \note The first raster Grid will be taken as reference for the composed raster.
520  \ingroup rp_func
521  */
522  TERPEXPORT bool ComposeBands(
524  const std::vector< unsigned int >& inputRasterBands,
525  const te::rst::Interpolator::Method& interpMethod,
526  const std::map<std::string, std::string>& outputRasterInfo,
527  const std::string& outputDataSourceType,
528  std::auto_ptr< te::rst::Raster >& outputRasterPtr );
529 
530  /*!
531  \brief Create a datailed extent from the given grid.
532  \param grid Input grid.
533  \param detailedExtent The created detailed extent.
534  \return true if ok, false on errors.
535  \ingroup rp_func
536  */
537  TERPEXPORT bool GetDetailedExtent( const te::rst::Grid& grid,
538  te::gm::LinearRing& detailedExtent );
539 
540  /*!
541  \brief Create a indexed (lines,columns) datailed extent from the given grid.
542  \param grid Input grid.
543  \param indexedDetailedExtent The created detailed extent.
544  \return true if ok, false on errors.
545  \ingroup rp_func
546  */
548  te::gm::LinearRing& indexedDetailedExtent );
549 
550  /*!
551  \brief Create a Wavele Atrous Filter.
552  \param filterType The filter type.
553  \return the created filter.
554  \ingroup rp_func
555  */
556  TERPEXPORT boost::numeric::ublas::matrix< double >
558 
559  /*!
560  \brief Generate all wavelet planes from the given input raster.
561  \param inputRaster Input raster.
562  \param inputRasterBands Input raster bands.
563  \param waveletRaster The pré-initiated output wavelet raster (with the same dimensions of inputRaster) and double as the data type.
564  \param levelsNumber The number of decomposed wavelet levels to generate for each input raster band;
565  \param filter The square filter to use.
566  \return true if OK, false on errors.
567  \note The band order of the generated wavelet levels: { [ band0-smoothed0, band0-wavelet0, ... , band0-smoothedN, band0-waveletN ], ... }
568  \note The number of bands of waveletRaster must be ( inputRasterBands.size() * 2 * levelsNumber ) at least.
569  \ingroup rp_func
570  */
572  const te::rst::Raster& inputRaster,
573  const std::vector< unsigned int >& inputRasterBands,
574  te::rst::Raster& waveletRaster,
575  const unsigned int levelsNumber,
576  const boost::numeric::ublas::matrix< double >& filter );
577 
578  /*!
579  \brief Regenerate the original raster from its wavelets planes.
580  \param waveletRaster The input wavelet raster (with the same dimensions of outputRaster).
581  \param levelsNumber The number of decomposed wavelet levels present inside the wavelet raster.
582  \param outputRaster The regenerated output raster.
583  \param outputRasterBands Output raster bands.
584  \return true if OK, false on errors.
585  \note The band order of the expected wavelet levels: { [ band0-smoothed0, band0-wavelet0, ... , band0-smoothedN, band0-waveletN ], ... }
586  \note The number of bands of waveletRaster must be ( outputRasterBands.size() * 2 * levelsNumber ) at least.
587  \note Only the wavelet bands and the last smoothed band are used.
588  \ingroup rp_func
589  */
591  const te::rst::Raster& waveletRaster,
592  const unsigned int levelsNumber,
593  te::rst::Raster& outputRaster,
594  const std::vector< unsigned int >& outputRasterBands );
595 
596  /*!
597  \brief Resample a subset of the raster, given a box.
598  \param inputRaster Input raster.
599  \param inputRasterBands Input raster bands to process.
600  \param interpMethod The method of interpolation. \sa te::rst::Interpolator
601  \param firstRow The starting row to make a subset of the image.
602  \param firstColumn The starting column to make a subset of the image.
603  \param height The height of the subset.
604  \param width The width of the subset.
605  \param newheight The resampled height of the new raster.
606  \param newwidth The resampled width of the new raster.
607  \param rinfo The parameters needed to build the output raster (see RasterFactory documentation).
608  \param dataSourceType Data source type (raster type. I.E. GDAL).
609  \param resampledRasterPtr The resampled raster pointer.
610  \return true if ok, false on errors.
611  */
613  const te::rst::Raster& inputRaster,
614  const std::vector< unsigned int >& inputRasterBands,
615  const te::rst::Interpolator::Method interpMethod,
616  const unsigned int firstRow,
617  const unsigned int firstColumn,
618  const unsigned int height,
619  const unsigned int width,
620  const unsigned int newheight,
621  const unsigned int newwidth,
622  const std::map<std::string, std::string>& rinfo,
623  const std::string& dataSourceType,
624  std::auto_ptr< te::rst::Raster >& resampledRasterPtr );
625 
626  /*!
627  \brief Returns the tie points converx hull area.
628  \param tiePoints Input tie-points (container of te::gm::GTParameters::TiePoint).
629  \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.
630  \return Returns the tie points converx hull area.
631  */
632  template< typename ContainerT >
633  double GetTPConvexHullArea( const ContainerT& tiePoints,
634  const bool useTPSecondCoordPair )
635  {
636  if( tiePoints.size() < 3 )
637  {
638  return 0;
639  }
640  else
641  {
643 
644  typename ContainerT::const_iterator it =
645  tiePoints.begin();
646  const typename ContainerT::const_iterator itE =
647  tiePoints.end();
648 
649  while( it != itE )
650  {
651  if( useTPSecondCoordPair )
652  points.add( new te::gm::Point( it->second.x, it->second.y ) );
653  else
654  points.add( new te::gm::Point( it->first.x, it->first.y ) );
655 
656  ++it;
657  }
658 
659  std::auto_ptr< te::gm::Geometry > convexHullPolPtr( points.convexHull() );
660 
661  if( dynamic_cast< te::gm::Surface* >( convexHullPolPtr.get() ) )
662  {
663  return ( (te::gm::Surface*)( convexHullPolPtr.get() ) )->getArea();
664  }
665  else
666  {
667  return 0.0;
668  }
669  }
670  }
671 
672  } // end namespace rp
673 } // end namespace te
674 
675 #endif // __TERRALIB_RP_INTERNAL_FUNCTIONS_H
676 
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:633
Spline filter type.
Definition: Functions.h:77
Triangle filter type.
Definition: Functions.h:78
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:180
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:118
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.
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:183
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:219
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:678
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:74
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
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.
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:76
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:51
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:671
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.
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