27 #include "../datatype/Enums.h"
28 #include "../geometry/Coord2D.h"
36 #include <boost/cstdint.hpp>
37 #include <boost/random.hpp>
38 #include <boost/random/uniform_int_distribution.hpp>
49 sizeof(
unsigned char),
50 sizeof(boost::int16_t),
51 sizeof(boost::uint16_t),
52 sizeof(boost::int32_t),
53 sizeof(boost::uint32_t),
54 sizeof(boost::int64_t),
55 sizeof(boost::uint64_t),
68 sizeof(boost::int16_t) * 2,
69 sizeof(boost::int32_t) * 2,
75 sizeof(
unsigned char),
76 sizeof(
unsigned char),
89 std::vector<te::rst::BandProperty*> bprops;
91 std::map<std::string, std::string>::const_iterator it = rinfo.find(
"NBANDS");
94 throw Exception((
"Number of bands must be set!"));
96 nBands = atoi(it->second.c_str());
98 it = rinfo.find(
"BANDSTYPE");
100 if(it == rinfo.end())
101 throw Exception((
"Data type of bands must be set!"));
103 tBands = atoi(it->second.c_str());
105 for (std::size_t b = 0; b < nBands; b++)
113 unsigned nCols, nRows;
114 double resX = 1.0, resY = 1.0, ulX =0.0, ulY=0.0;
118 std::map<std::string, std::string>::const_iterator it = rinfo.find(
"NCOLS");
120 if(it == rinfo.end())
121 throw Exception((
"Number of columns must be set!"));
123 nCols = atoi(it->second.c_str());
125 it = rinfo.find(
"NROWS");
127 if(it == rinfo.end())
128 throw Exception((
"Number of rows must be set!"));
130 nRows = atoi(it->second.c_str());
132 it = rinfo.find(
"RESX");
133 if(it != rinfo.end())
134 resX = atof(it->second.c_str());
136 it = rinfo.find(
"RESY");
137 if(it != rinfo.end())
138 resY = atof(it->second.c_str());
140 it = rinfo.find(
"SRID");
141 if(it != rinfo.end())
142 srid = atoi(it->second.c_str());
144 it = rinfo.find(
"ULX");
145 if(it != rinfo.end())
146 ulX = atof(it->second.c_str());
148 it = rinfo.find(
"ULY");
149 if(it != rinfo.end())
150 ulY = atof(it->second.c_str());
154 return (
new te::rst::Grid(nCols, nRows, resX, resY, ulc, srid));
165 unsigned int row = 0;
166 unsigned int col = 0;
167 std::complex< double > value;
169 for(std::size_t b = 0; b < nbands; b++)
180 for(row = 0 ; row < nRows ; ++row)
181 for(col = 0 ; col < nCols ; ++col)
198 unsigned char* buffer =
new unsigned char[bin.
getBlockSize()];
210 for(
int y = 0; y < nblocksy; ++y)
212 for(
int x = 0; x < nblocksx; ++x)
214 bin.
read(x, y, buffer);
215 bout.
write(x, y, buffer);
222 std::complex<double> value;
227 for(
int y = 0; y < nblocksy; ++y)
229 for(
int x = 0; x < nblocksx; ++x)
231 unsigned int w = blkw * (x + 1);
233 w = w > ncols ? ncols : w;
235 unsigned int h = blkh * (y + 1);
237 h = h > nrows ? nrows : h;
239 for(
int r = blkh * y; r < (int)h; ++r)
241 for(
int c = blkw * x; c < (int)w; ++c)
276 std::vector<std::complex<double> > v;
278 for (
unsigned r = drow; r < drow + height; r++)
280 for (
unsigned c = dcolumn; c < dcolumn + width; c++)
286 int x =
Round(outputGrid.
x);
287 int y =
Round(outputGrid.
y);
301 return (
int)(val+.5);
303 return (
int)(val-.5);
307 const std::string& uri,
308 const std::string &rType)
310 std::map<std::string, std::string> rasterInfo;
311 rasterInfo[
"URI"] = uri;
313 std::vector<te::rst::BandProperty*> bandsProperties;
315 unsigned int bandIndex = 0;
326 if(outRasterPtr.get() == 0)
329 Copy(rin, *outRasterPtr);
365 max = (double)std::numeric_limits<unsigned short int>::max();
369 min = (double)std::numeric_limits<short int>::min();
370 max = (double)std::numeric_limits<short int>::max();
375 max = (double)std::numeric_limits<unsigned int>::max();
379 min = (double)std::numeric_limits<int>::min();
380 max = (double)std::numeric_limits<int>::max();
384 min = -(double)std::numeric_limits< float >::max();
385 max = (double)std::numeric_limits< float >::max();
389 min = -std::numeric_limits< double >::max();
390 max = std::numeric_limits< double >::max();
394 min = (double)std::numeric_limits<short int>::min();
395 max = (double)std::numeric_limits<short int>::max();
399 min = (double)std::numeric_limits<int>::min();
400 max = (double)std::numeric_limits<int>::max();
404 min = -(double)std::numeric_limits< float >::max();
405 max = (double)std::numeric_limits< float >::max();
409 min = -std::numeric_limits< double >::max();
410 max = std::numeric_limits< double >::max();
414 throw te::rst::Exception(
"Invalid data type");
433 std::vector<te::rst::BandProperty*> bprops;
455 FillBand(rout->getBand(b), noDataValue);
464 unsigned int gridColumn;
465 unsigned int gridRow;
468 for (
unsigned int b = 0; b < rout->getNumberOfBands(); b++)
469 pixels[b] = (*it)[b];
472 gridCoord = rout->getGrid()->geoToGrid(geoCoord.
x, geoCoord.
y);
473 gridColumn = (
unsigned int) gridCoord.
x;
474 gridRow = (
unsigned int) gridCoord.
y;
475 if (gridColumn >= rout->getNumberOfColumns())
477 if (gridRow >= rout->getNumberOfRows())
479 rout->setValues(gridColumn, gridRow, pixels);
487 std::vector<te::gm::Point*> randomPoints;
491 boost::random::mt19937 generator((boost::random::mt19937::result_type) time(0));
492 boost::random::uniform_int_distribution<> random_rows(0, inputRaster.
getNumberOfRows() - 1);
493 boost::random::uniform_int_distribution<> random_columns(0, inputRaster.
getNumberOfColumns() - 1);
495 for (
unsigned int p = 0; p < numberOfPoints; p++)
497 inputRaster.
getGrid()->
gridToGeo(random_columns(generator), random_rows(generator), randX, randY);
507 return TE_TR(
"Undefined");
509 return TE_TR(
"Gray");
511 return TE_TR(
"Palette");
515 return TE_TR(
"Green");
517 return TE_TR(
"Blue");
519 return TE_TR(
"Alpha");
523 return TE_TR(
"Saturation");
525 return TE_TR(
"Lightness");
527 return TE_TR(
"Cyan");
529 return TE_TR(
"Magenta");
531 return TE_TR(
"Yellow");
547 return TE_TR(
"Undefined");
549 return TE_TR(
"Gray");
553 return TE_TR(
"CMYK");
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.
HSL indexed palette interpretation.
virtual void setValues(unsigned int c, unsigned int r, const std::vector< double > &values)
Sets the imaginary attribute values in all complex bands of a cell.
unsigned int getRow() const
Returns the current row in iterator.
Palette indexes color interpretation.
Hue channel color interpretation.
Alpha channel color interpretation.
TERASTEREXPORT void FillBand(te::rst::Band *bin, const std::complex< double > &value)
Fill a Raster Band with provided value.
TERASTEREXPORT void GetDataTypeRanges(const int &dataType, double &min, double &max)
Return the values range of a given data type.
Index into a lookup table.
unsigned int getColumn() const
Returns the current column in iterator.
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.
Lightness color interpretation.
ColorInterp
Color model component use.
A raster band description.
RGB indexed palette interpretation.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
int m_nblocksx
The number of blocks in x.
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
Gray indexed palette interpretation.
void Copy(const std::vector< T * > &src, std::vector< T * > &dst)
This function can be applied to a vector of pointers. It will copy element by element through its cop...
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.
int m_nblocksy
The number of blocks in y.
virtual void getValues(unsigned int c, unsigned int r, std::vector< double > &values) const
Returns the imaginary attribute values in all complex bands of a cell.
This class implements the strategy to iterate with spatial restriction, the iteration occurs inside a...
TERASTEREXPORT void Copy(const Raster &rin, Raster &rout)
Copies the pixel values from one raster to another.
static int sg_pixelSize[]
Red channel color interpretation.
virtual void read(int x, int y, void *buffer) const =0
It reads a data block to the specified buffer.
TERASTEREXPORT void FillRaster(te::rst::Raster *rin, const std::complex< double > &value)
Fill a Raster with provided value (all bands).
unsigned int getRow() const
Returns the current row in iterator.
An utility struct for representing 2D coordinates.
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits::max().
#define TE_TR(message)
It marks a string in order to get translated.
Cyan color interpretation.
TERASTEREXPORT std::string ConvertColorInterpTypeToString(const te::rst::ColorInterp &ci)
Function used to convert from a Color Interp Enum to a string.
This class implements an iterator to "navigate" over a single band (const).
void geoToGrid(const double &x, const double &y, double &col, double &row) const
Get the grid point associated to a spatial location.
static ConstBandIterator begin(const Band *b)
Returns an iterator referring to the first value of the band.
te::common::AccessPolicy getAccessPolicy() const
Returns the raster access policy.
boost::shared_ptr< Raster > RasterPtr
An exception class for the Raster module.
static PolygonIterator end(const te::rst::Raster *r, const te::gm::Polygon *p)
Returns an iterator referring to after the end of the iterator.
A point with x and y coordinate values.
TERASTEREXPORT int Round(double val)
Round a double value to a integer value.
YCbCr Cr Band color interpretation.
An Envelope defines a 2D rectangular region.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
An abstract class for raster data strucutures.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
BandProperty * getProperty()
Returns the band property.
It implements an iterator to "navigate" over a single band (const or not const).
int m_blkw
Block width (pixels).
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
Utility functions for the raster module.
virtual Raster * getRaster() const =0
Returns the associated raster.
double getResolutionX() const
Returns the raster horizontal (x-axis) resolution.
virtual void write(int x, int y, void *buffer)=0
It writes a data block from the specified buffer.
No color interpretation is associated with the band.
A raster band description.
Undefined palette interpretation.
Grid * getGrid()
It returns the raster grid.
TERASTEREXPORT int GetPixelSize(int datatype)
Returns the byte size of a given datatype.
TEDATAACCESSEXPORT double Round(const double &value, const size_t &precision)
It gets the round value.
Key (black) color interpretation.
Yellow color interpretation.
virtual void setValue(unsigned int c, unsigned int r, const double value)=0
Sets the cell attribute value.
int getSRID() const
Returns the raster spatial reference system identifier.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
TERASTEREXPORT Grid * GetGrid(const std::map< std::string, std::string > &rinfo)
Returns a grid based on a given raster info.
static PolygonIterator begin(const te::rst::Raster *r, const te::gm::Polygon *p)
Returns an iterator referring to the first value of the band.
static Raster * make()
It creates and returns an empty raster with default raster driver.
TERASTEREXPORT std::string ConvertPalleteInterpTypeToString(const te::rst::PaletteInterpretation &pi)
Function used to convert from a Pallete Interp Enum to a string.
void gridToGeo(const double &col, const double &row, double &x, double &y) const
Get the spatial location of a grid point.
double getResolutionY() const
Returns the raster vertical (y-axis) resolution.
TERASTEREXPORT std::vector< te::gm::Point * > GetRandomPointsInRaster(const te::rst::Raster &inputRaster, unsigned int numberOfPoints=1000)
Creates a vector of random positions (points) inside the raster.
YCbCr Y Band color interpretation.
int getType() const
It returns the data type of the elements in the band.
CMYK indexed palette interpretation.
This is the abstract factory for Rasters.
Saturation color interpretation.
int m_blkh
Block height (pixels).
Blue channel color interpretation.
PaletteInterpretation
Palette interpratation types.
unsigned int getColumn() const
Returns the current column in iterator.
A rectified grid is the spatial support for raster data.
Green channel color interpretation.
virtual int getBlockSize() const
It returns the number of bytes ocuppied by a data block.
const Envelope * getMBR() const
It returns the minimum bounding rectangle for the geometry in an internal representation.
Magenta color interpretation.
YCbCr Cb Band color interpretation.
TERASTEREXPORT std::vector< BandProperty * > GetBandProperties(const std::map< std::string, std::string > &rinfo)
Returns a vector of band properties, based on a given raster info.
static ConstBandIterator end(const Band *b)
Returns an iterator referring to after the end of the iterator.