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 
36 // STL
37 #include <map>
38 #include <vector>
39 
40 namespace te
41 {
42  namespace rst
43  {
44  /*! \brief Returns the byte size of a given datatype. */
45  TERASTEREXPORT int GetPixelSize(int datatype);
46 
47  /*!
48  \brief Returns a vector of band properties, based on a given raster info.
49 
50  \param rinfo The map of raster informations.
51 
52  \return A vector of band properties.
53 
54  \note The caller will take the ownership of the returned pointer.
55 
56  \warning The variable rinfo must have the properties NBANDS and BANDSTYPE defined.
57  */
58  TERASTEREXPORT std::vector<BandProperty*> GetBandProperties(const std::map<std::string, std::string>& rinfo);
59 
60  /*!
61  \brief Returns a grid based on a given raster info.
62 
63  \param rinfo The map of raster informations.
64 
65  \return A grid info.
66 
67  \note The caller will take the ownership of the returned pointer.
68 
69  \warning The parameter rinfo must have the properties NCOLS and NROWS defined.
70  \warning Optional properties in parameter rinfo are RESX, RESY, SRID, ULX and ULY.
71  */
72  TERASTEREXPORT Grid* GetGrid(const std::map<std::string, std::string>& rinfo);
73 
74  /*!
75  \brief Copies the pixel values from one raster to another.
76 
77  \param rin The input raster.
78  \param rout The output raster.
79 
80  \warning Both rasters must have the same properties of grid and number/type of bands.
81  */
82  TERASTEREXPORT void Copy(const Raster& rin, Raster& rout);
83 
84  /*!
85  \brief Copies the pixel values from one band to another.
86 
87  \param bin The input band.
88  \param bout The output band.
89 
90  \warning Both bands must have the same properties of type and grid.
91  */
92  TERASTEREXPORT void Copy(const Band& bin, Band& bout);
93 
94  /*!
95  \brief Copy a subset of the raster, given a box.
96 
97  \param method The method of interpolation. \sa te::rst::Interpolator
98  \param drow The starting row to make a subset of the image.
99  \param dcolumn The starting column to make a subset of the image.
100  \param height The height of the subset.
101  \param width The width of the subset.
102  \param rin Pointer to valid output raster.
103  \param rout Pointer to valid output raster.
104  */
105  TERASTEREXPORT void Copy(unsigned int drow, unsigned int dcolumn, unsigned int height, unsigned int width, const Raster& rin, Raster& rout);
106 
107  /*!
108  \brief Round a double value to a integer value.
109 
110  \param val The double value.
111 
112  \return A integer value.
113  */
114 
115  TERASTEREXPORT int Round(double val);
116 
117  /*!
118  \brief Create a new raster from existing one.
119 
120  \param rin The input raster.
121  \param uri The output raster URI.
122  \param rType The name of the specific driver to create the raster.
123 
124  \return A valid pointer to the created raster or a null (invalid) pointer if an error ocurred.
125  */
126  TERASTEREXPORT te::rst::RasterPtr CreateCopy(const te::rst::Raster& rin, const std::string& uri,
127  const std::string& rType = std::string("GDAL"));
128 
129  /*!
130  \brief Return the values range of a given data type.
131 
132  \param dataType The given data type.
133  \param min The mininmum value allowed for the given data type.
134  \param min The maximum value allowed for the given data type.
135  */
136  TERASTEREXPORT void GetDataTypeRanges(const int& dataType, double& min, double& max);
137 
138  /*!
139  \brief Fill a Raster with provided value (all bands).
140 
141  \param rin The input raster.
142  \param value The value to fill all the bands of the Raster.
143  */
144  TERASTEREXPORT void FillRaster(te::rst::Raster* rin, const std::complex<double>& value);
145 
146  /*!
147  \brief Fill a Raster Band with provided value.
148 
149  \param bin The input band.
150  \param value The value to fill all the bands of the Raster.
151  */
152  TERASTEREXPORT void FillBand(te::rst::Band* bin, const std::complex<double>& value);
153 
154  /*!
155  \brief Creates a raster crop using a polygon delimiter.
156 
157  \param rin The input raster.
158  \param pin The input polygon, to be used as a delimiter.
159  \param rinfo The map of raster informations.
160  \param rType The name of the specific driver to create the raster.
161 
162  \return A valid pointer to the created raster or a null (invalid) pointer if an error ocurred.
163  */
165  const te::gm::Polygon& pin,
166  const std::map<std::string, std::string>& rinfo,
167  const std::string& rType = std::string("GDAL"));
168 
169  /*!
170  \brief Creates a vector of random positions (points) inside the raster.
171 
172  \param inputRaster The given raster.
173  \param numberOfPoints The number of random positions to be created (default = 1000).
174 
175  \return A vector of random positions (points).
176  \ingroup rp_func
177  */
178  TERASTEREXPORT std::vector<te::gm::Point*> GetRandomPointsInRaster(const te::rst::Raster& inputRaster, unsigned int numberOfPoints = 1000);
179 
180  /*!
181  \brief Function used to convert from a Color Interp Enum to a string
182 
183  \param ci The color interpretation enum
184 
185  \return A string with the color interpreation name.
186  */
188 
189  /*!
190  \brief Function used to convert from a Pallete Interp Enum to a string
191 
192  \param pi The pallete interpretation enum
193 
194  \return A string with the pallete interpreation name.
195  */
197 
198  } // end namespace rst
199 } // end namespace te
200 
201 #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:685
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.
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.