Utils.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/raster/Utils.h
22 
23  \brief Utility functions for the raster module.
24 */
25 
26 #ifndef __TERRALIB_RASTER_INTERNAL_UTILS_H
27 #define __TERRALIB_RASTER_INTERNAL_UTILS_H
28 
29 // TerraLib
30 #include "Band.h"
31 #include "BandProperty.h"
32 #include "Config.h"
33 #include "Grid.h"
34 #include "Raster.h"
35 #include "../common/MathUtils.h"
36 
37 // STL
38 #include <memory>
39 #include <map>
40 #include <vector>
41 
42 namespace te
43 {
44  namespace rst
45  {
46  /*! \brief Returns the byte size of a given datatype. */
47  TERASTEREXPORT int GetPixelSize(int datatype);
48 
49  /*!
50  \brief Returns a vector of band properties, based on a given raster info.
51 
52  \param rinfo The map of raster informations.
53 
54  \return A vector of band properties.
55 
56  \note The caller will take the ownership of the returned pointer.
57 
58  \warning The variable rinfo must have the properties NBANDS and BANDSTYPE defined.
59  */
60  TERASTEREXPORT std::vector<BandProperty*> GetBandProperties(const std::map<std::string, std::string>& rinfo);
61 
62  /*!
63  \brief Returns a grid based on a given raster info.
64 
65  \param rinfo The map of raster informations.
66 
67  \return A grid info.
68 
69  \note The caller will take the ownership of the returned pointer.
70 
71  \warning The parameter rinfo must have the properties NCOLS and NROWS defined.
72  \warning Optional properties in parameter rinfo are RESX, RESY, SRID, ULX and ULY.
73  */
74  TERASTEREXPORT Grid* GetGrid(const std::map<std::string, std::string>& rinfo);
75 
76  /*!
77  \brief Copies the pixel values from one raster to another.
78 
79  \param rin The input raster.
80  \param rout The output raster.
81 
82  \warning Both rasters must have the same properties of grid and number/type of bands.
83  */
84  TERASTEREXPORT void Copy(const Raster& rin, Raster& rout);
85 
86  /*!
87  \brief Copies the pixel values from one band to another.
88 
89  \param bin The input band.
90  \param bout The output band.
91 
92  \warning Both bands must have the same properties of type and grid.
93  */
94  TERASTEREXPORT void Copy(const Band& bin, Band& bout);
95 
96  /*!
97  \brief Copy a subset of the raster, given a box.
98 
99  \param method The method of interpolation. \sa te::rst::Interpolator
100  \param drow The starting row to make a subset of the image.
101  \param dcolumn The starting column to make a subset of the image.
102  \param height The height of the subset.
103  \param width The width of the subset.
104  \param rin Pointer to valid output raster.
105  \param rout Pointer to valid output raster.
106  */
107  TERASTEREXPORT void Copy(unsigned int drow, unsigned int dcolumn, unsigned int height, unsigned int width, const Raster& rin, Raster& rout);
108 
109  /*!
110  \brief Round a double value to a integer value.
111 
112  \param val The double value.
113 
114  \return A integer value.
115  */
116 
117  TERASTEREXPORT inline int Round(double val) { return te::common::Round< double, int >( val ); }
118 
119  /*!
120  \brief Create a new raster from existing one.
121 
122  \param rin The input raster.
123  \param uri The output raster URI.
124  \param rType The name of the specific driver to create the raster.
125 
126  \return A valid pointer to the created raster or a null (invalid) pointer if an error ocurred.
127  */
128  TERASTEREXPORT te::rst::RasterPtr CreateCopy(const te::rst::Raster& rin, const std::string& uri,
129  const std::string& rType = std::string("GDAL"));
130 
131  /*!
132  \brief Return the values range of a given data type.
133 
134  \param dataType The given data type.
135  \param min The mininmum value allowed for the given data type.
136  \param min The maximum value allowed for the given data type.
137  */
138  TERASTEREXPORT void GetDataTypeRanges(const int& dataType, double& min, double& max);
139 
140  /*!
141  \brief Fill a Raster with provided value (all bands).
142 
143  \param rin The input raster.
144  \param value The value to fill all the bands of the Raster.
145  */
146  TERASTEREXPORT void FillRaster(te::rst::Raster* rin, const std::complex<double>& value);
147 
148  /*!
149  \brief Fill a Raster Band with provided value.
150 
151  \param bin The input band.
152  \param value The value to fill all the bands of the Raster.
153  */
154  TERASTEREXPORT void FillBand(te::rst::Band* bin, const std::complex<double>& value);
155 
156  /*!
157  \brief Creates a raster crop using a polygon delimiter.
158 
159  \param rin The input raster.
160  \param pin The input polygon, to be used as a delimiter.
161  \param rinfo The map of raster informations.
162  \param rType The name of the specific driver to create the raster.
163 
164  \return A valid pointer to the created raster or a null (invalid) pointer if an error ocurred.
165  \note The area outside the polygon will be filled with nodata values.
166  */
168  const te::gm::Polygon& pin,
169  const std::map<std::string, std::string>& rinfo,
170  const std::string& rType = std::string("GDAL"));
171 
172  /*!
173  \brief Creates a raster crop using a polygon delimiter.
174 
175  \param rin The input raster.
176  \param geometries A vector of pointers to valid geometries.
177  \param rinfo The map of raster informations.
178  \param rType The name of the specific driver to create the raster.
179 
180  \return A valid pointer to the created raster or a null (invalid) pointer if an error ocurred.
181  \note The area outside the polygon will be filled with nodata values.
182  \note Accepted geometry types: te::gm::Polygon, te::gm::MultiPolygon.
183  */
184  TERASTEREXPORT std::unique_ptr< te::rst::Raster > CropRaster(const te::rst::Raster& rin,
185  const std::vector< te::gm::Geometry const *> geometries,
186  const std::map<std::string, std::string>& rinfo,
187  const std::string& rType );
188 
189  /*!
190  \brief Creates a vector of random positions (points) inside the raster.
191 
192  \param inputRaster The given raster.
193  \param numberOfPoints The number of random positions to be created (default = 1000).
194 
195  \return A vector of random positions (points).
196  \ingroup rp_func
197  */
198  TERASTEREXPORT std::vector<te::gm::Point*> GetRandomPointsInRaster(const te::rst::Raster& inputRaster, unsigned int numberOfPoints = 1000);
199 
200  /*!
201  \brief Function used to convert from a Color Interp Enum to a string
202 
203  \param ci The color interpretation enum
204 
205  \return A string with the color interpreation name.
206  */
208 
209  /*!
210  \brief Function used to convert from a Pallete Interp Enum to a string
211 
212  \param pi The pallete interpretation enum
213 
214  \return A string with the pallete interpreation name.
215  */
217 
218  } // end namespace rst
219 } // end namespace te
220 
221 #endif // __TERRALIB_RASTER_INTERNAL_UTILS_H
#define TERASTEREXPORT
You can use this macro in order to export/import classes and functions from this module.
Definition: Config.h:62
TERASTEREXPORT std::string ConvertColorInterpTypeToString(const te::rst::ColorInterp &ci)
Function used to convert from a Color Interp Enum to a string.
It describes one band (or dimension) of a raster.
ColorInterp
Color model component use.
Definition: Enums.h:54
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.
TERASTEREXPORT void FillBand(te::rst::Band *bin, const std::complex< double > &value)
Fill a Raster Band with provided value.
TERASTEREXPORT void GetDataTypeRanges(const int &dataType, double &min, double &max)
Return the values range of a given data type.
TERASTEREXPORT Grid * GetGrid(const std::map< std::string, std::string > &rinfo)
Returns a grid based on a given raster info.
TERASTEREXPORT std::string ConvertPalleteInterpTypeToString(const te::rst::PaletteInterpretation &pi)
Function used to convert from a Pallete Interp Enum to a string.
TERASTEREXPORT int GetPixelSize(int datatype)
Returns the byte size of a given datatype.
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.
boost::shared_ptr< Raster > RasterPtr
Definition: Raster.h:703
An abstract class for raster data strucutures.
An abstract class for raster data strucutures.
Definition: Raster.h:71
URI C++ Library.
TERASTEREXPORT int Round(double val)
Round a double value to a integer value.
Definition: Utils.h:117
It gives access to values in one band (dimension) of a raster.
A raster band description.
Definition: Band.h:63
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Definition: Polygon.h:50
TERASTEREXPORT void FillRaster(te::rst::Raster *rin, const std::complex< double > &value)
Fill a Raster with provided value (all bands).
A rectified grid is the spatial support for raster data.
Configuration flags for the Raster module of TerraLib.
PaletteInterpretation
Palette interpratation types.
Definition: Enums.h:80
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.
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.
TERASTEREXPORT void Copy(const Raster &rin, Raster &rout)
Copies the pixel values from one raster to another.