27 #include "../datatype/Enums.h"
28 #include "../geometry/Coord2D.h"
35 #include <boost/cstdint.hpp>
46 sizeof(
unsigned char),
47 sizeof(boost::int16_t),
48 sizeof(boost::uint16_t),
49 sizeof(boost::int32_t),
50 sizeof(boost::uint32_t),
51 sizeof(boost::int64_t),
52 sizeof(boost::uint64_t),
65 sizeof(boost::int16_t) * 2,
66 sizeof(boost::int32_t) * 2,
72 sizeof(
unsigned char),
73 sizeof(
unsigned char),
86 std::vector<te::rst::BandProperty*> bprops;
88 std::map<std::string, std::string>::const_iterator it = rinfo.find(
"NBANDS");
91 throw Exception((
"Number of bands must be set!"));
93 nBands = atoi(it->second.c_str());
95 it = rinfo.find(
"BANDSTYPE");
98 throw Exception((
"Data type of bands must be set!"));
100 tBands = atoi(it->second.c_str());
102 for (std::size_t b = 0; b < nBands; b++)
110 unsigned nCols, nRows;
111 double resX = 1.0, resY = 1.0, ulX =0.0, ulY=0.0;
115 std::map<std::string, std::string>::const_iterator it = rinfo.find(
"NCOLS");
117 if(it == rinfo.end())
118 throw Exception((
"Number of columns must be set!"));
120 nCols = atoi(it->second.c_str());
122 it = rinfo.find(
"NROWS");
124 if(it == rinfo.end())
125 throw Exception((
"Number of rows must be set!"));
127 nRows = atoi(it->second.c_str());
129 it = rinfo.find(
"RESX");
130 if(it != rinfo.end())
131 resX = atof(it->second.c_str());
133 it = rinfo.find(
"RESY");
134 if(it != rinfo.end())
135 resY = atof(it->second.c_str());
137 it = rinfo.find(
"SRID");
138 if(it != rinfo.end())
139 srid = atoi(it->second.c_str());
141 it = rinfo.find(
"ULX");
142 if(it != rinfo.end())
143 ulX = atof(it->second.c_str());
145 it = rinfo.find(
"ULY");
146 if(it != rinfo.end())
147 ulY = atof(it->second.c_str());
151 return (
new te::rst::Grid(nCols, nRows, resX, resY, ulc, srid));
162 unsigned int row = 0;
163 unsigned int col = 0;
164 std::complex< double > value;
166 for(std::size_t b = 0; b < nbands; b++)
177 for(row = 0 ; row < nRows ; ++row)
178 for(col = 0 ; col < nCols ; ++col)
195 unsigned char* buffer =
new unsigned char[bin.
getBlockSize()];
207 for(
int y = 0; y < nblocksy; ++y)
209 for(
int x = 0; x < nblocksx; ++x)
211 bin.
read(x, y, buffer);
212 bout.
write(x, y, buffer);
219 std::complex<double> value;
224 for(
int y = 0; y < nblocksy; ++y)
226 for(
int x = 0; x < nblocksx; ++x)
228 unsigned int w = blkw * (x + 1);
230 w = w > ncols ? ncols : w;
232 unsigned int h = blkh * (y + 1);
234 h = h > nrows ? nrows : h;
236 for(
int r = blkh * y; r < (int)h; ++r)
238 for(
int c = blkw * x; c < (int)w; ++c)
273 std::vector<std::complex<double> > v;
275 for (
unsigned r = drow; r < drow + height; r++)
277 for (
unsigned c = dcolumn; c < dcolumn + width; c++)
283 int x =
Round(outputGrid.
x);
284 int y =
Round(outputGrid.
y);
298 return (
int)(val+.5);
300 return (
int)(val-.5);
304 const std::string& uri,
305 const std::string &rType)
307 std::map<std::string, std::string> rasterInfo;
308 rasterInfo[
"URI"] = uri;
310 std::vector<te::rst::BandProperty*> bandsProperties;
312 unsigned int bandIndex = 0;
323 if(outRasterPtr.get() == 0)
326 Copy(rin, *outRasterPtr);
362 max = (double)std::numeric_limits<unsigned short int>::max();
366 min = (double)std::numeric_limits<short int>::min();
367 max = (double)std::numeric_limits<short int>::max();
372 max = (double)std::numeric_limits<unsigned int>::max();
376 min = (double)std::numeric_limits<int>::min();
377 max = (double)std::numeric_limits<int>::max();
381 min = -(double)std::numeric_limits< float >::max();
382 max = (double)std::numeric_limits< float >::max();
386 min = -std::numeric_limits< double >::max();
387 max = std::numeric_limits< double >::max();
391 min = (double)std::numeric_limits<short int>::min();
392 max = (double)std::numeric_limits<short int>::max();
396 min = (double)std::numeric_limits<int>::min();
397 max = (double)std::numeric_limits<int>::max();
401 min = -(double)std::numeric_limits< float >::max();
402 max = (double)std::numeric_limits< float >::max();
406 min = -std::numeric_limits< double >::max();
407 max = std::numeric_limits< double >::max();
411 throw te::rst::Exception(
"Invalid data type");
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.
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.
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.
A raster band description.
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.
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.
TERASTEREXPORT void Copy(const Raster &rin, Raster &rout)
Copies the pixel values from one raster to another.
static int sg_pixelSize[]
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).
An utility struct for representing 2D coordinates.
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.
TERASTEREXPORT int Round(double val)
Round a double value to a integer value.
#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.
virtual void write(int x, int y, void *buffer)=0
It writes a data block from the specified buffer.
A raster band description.
Grid * getGrid()
It returns the raster grid.
TERASTEREXPORT int GetPixelSize(int datatype)
Returns the byte size of a given datatype.
virtual void setValue(unsigned int c, unsigned int r, const double value)=0
Sets the cell attribute value.
TERASTEREXPORT Grid * GetGrid(const std::map< std::string, std::string > &rinfo)
Returns a grid based on a given raster info.
static Raster * make()
It creates and returns an empty raster with default raster driver.
void gridToGeo(const double &col, const double &row, double &x, double &y) const
Get the spatial location of a grid point.
int getType() const
It returns the data type of the elements in the band.
This is the abstract factory for Rasters.
int m_blkh
Block height (pixels).
A rectified grid is the spatial support for raster data.
virtual int getBlockSize() const
It returns the number of bytes ocuppied by a data block.
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.