27 #include "../common/Translator.h"
28 #include "../raster/RasterProperty.h"
29 #include "../raster/Utils.h"
40 #include <gdal_priv.h>
43 : te::rst::
Band(0, idx),
45 m_rasterBand(gdalRasterBandPtr)
55 m_x = std::numeric_limits<int>::max();
57 m_y = std::numeric_limits<int>::max();
64 m_raster(rhs.m_raster),
65 m_rasterBand(rhs.m_rasterBand),
66 m_getBuff(rhs.m_getBuff),
67 m_gdaltype(rhs.m_gdaltype)
71 m_x = std::numeric_limits<int>::max();
73 m_y = std::numeric_limits<int>::max();
82 m_rasterBand->WriteBlock(m_x, m_y, m_buffer);
84 m_rasterBand->FlushCache();
87 unsigned char* buff = (
unsigned char*)m_buffer;
107 unsigned char* buffer =
new unsigned char[rhs.
getBlockSize()];
109 for (
int x = 0; x < m_property->m_nblocksx; ++x)
110 for (
int y = 0; y < m_property->m_nblocksy; ++y)
112 rhs.
read(x, y, buffer);
125 m_i = placeBuffer(c, r);
127 m_getBuff(m_i, m_buffer, &value);
132 m_i = placeBuffer(c, r);
134 m_setBuff(m_i, m_buffer, &value);
136 m_update_buffer =
true;
141 m_i = placeBuffer(c, r);
143 m_getBuffI(m_i, m_buffer, &value);
148 m_i = placeBuffer(c, r);
150 m_setBuffI(m_i, m_buffer, &value);
152 m_update_buffer =
true;
157 m_rasterBand->ReadBlock(x, y, buffer);
162 if( m_rasterBand->GetColorInterpretation() == GCI_PaletteIndex )
164 const int bufferSize = m_property->m_blkh * m_property->m_blkw;
166 const GDALColorTable& cTable = *( m_rasterBand->GetColorTable() );
168 GDALColorEntry
const * cEntryPtr = 0;
173 for(
int bufferIdx = 0 ; bufferIdx < bufferSize ; ++bufferIdx )
175 m_getBuff( bufferIdx, buffer, &value );
177 cEntryPtr = cTable.GetColorEntry( (
int)value );
180 value = (double)cEntryPtr->c1;
182 m_setBuff( bufferIdx, buffer, &value );
186 for(
int bufferIdx = 0 ; bufferIdx < bufferSize ; ++bufferIdx )
188 m_getBuff( bufferIdx, buffer, &value );
190 cEntryPtr = cTable.GetColorEntry( (
int)value );
193 value = (double)cEntryPtr->c2;
195 m_setBuff( bufferIdx, buffer, &value );
199 for(
int bufferIdx = 0 ; bufferIdx < bufferSize ; ++bufferIdx )
201 m_getBuff( bufferIdx, buffer, &value );
203 cEntryPtr = cTable.GetColorEntry( (
int)value );
206 value = (double)cEntryPtr->c3;
208 m_setBuff( bufferIdx, buffer, &value );
212 for(
int bufferIdx = 0 ; bufferIdx < bufferSize ; ++bufferIdx )
214 m_getBuff( bufferIdx, buffer, &value );
216 cEntryPtr = cTable.GetColorEntry( (
int)value );
219 value = (double)cEntryPtr->c4;
221 m_setBuff( bufferIdx, buffer, &value );
225 throw Exception(
TE_TR(
"Invalid band index"));
233 if( ( x != m_x ) || ( y != m_y ) )
237 m_rasterBand->WriteBlock(m_x, m_y, m_buffer);
239 m_rasterBand->FlushCache();
241 m_update_buffer =
false;
244 read( x, y, m_buffer );
254 m_rasterBand->WriteBlock(x, y, buffer);
259 assert(c >= 0 && c < m_raster->getNumberOfColumns());
260 assert(r >= 0 && r < m_raster->getNumberOfRows());
262 m_currX = c / m_property->m_blkw;
264 m_currY = r / m_property->m_blkh;
266 m_currC = c % m_property->m_blkw;
268 m_currR = r % m_property->m_blkh;
270 if (m_currX != m_x || m_currY != m_y)
274 m_rasterBand->WriteBlock(m_x, m_y, m_buffer);
276 m_rasterBand->FlushCache();
278 m_update_buffer =
false;
281 read(m_currX, m_currY, m_buffer);
289 return (m_currC + m_currR * m_property->m_blkw);
void write(int x, int y, void *buffer)
It writes a data block from the specified buffer.
This is a class that represents a GDAL Raster.
void read(int x, int y, void *buffer) const
It reads a data block to the specified buffer.
int m_x
Actual x buffer position.
te::rst::GetBufferValueFPtr m_getBuffI
A pointer to a function that helps to extract the imaginary part value from a specific buffer data ty...
void getIValue(unsigned int c, unsigned int r, double &value) const
Returns the imaginary attribute value in a complex band of a cell.
Utilitary functions to access GDAL and match some of its concepts to TerraLib concepts.
void * m_buffer
An internal buffer.
This class represents Raster data.
virtual Band & operator=(const Band &rhs)
Assignment operator.
It gives access to values in one band (dimension) of a raster.
Band & operator=(const Band &rhs)
te::rst::BandProperty * GetBandProperty(GDALRasterBand *gband, const unsigned int bandIndex)
Gets the properties of a single band from a GDAL dataset.
#define TE_TR(message)
It marks a string in order to get translated.
te::rst::GetBufferValueFPtr m_getBuff
A pointer to a function that helps to extract a double or complex value from a specific buffer data t...
This class represents raster band description.
te::rst::SetBufferValueFPtr m_setBuffI
A pointer to a function that helps to insert the imaginary part value into a specific buffer data typ...
Band(Raster *rstPtr, std::size_t idx, GDALRasterBand *gdalRasterBandPtr)
Constructor.
An exception class for the GDAL module.
void setValue(unsigned int c, unsigned int r, const double value)
Sets the cell attribute value.
An abstract class for raster data strucutures.
GDALRasterBand * m_rasterBand
GDAL Raster band.
int m_y
Actual y buffer position.
te::rst::SetBufferValueFPtr m_setBuff
A pointer to a function that helps to insert a double or complex value into a specific buffer data ty...
void getValue(unsigned int c, unsigned int r, double &value) const
Returns the cell attribute value.
~Band()
Virtual destructor.
void setIValue(unsigned int c, unsigned int r, const double value)
Sets the imaginary attribute value in a complex band of a cell.
std::size_t m_idx
The band index.
GDALDataType m_gdaltype
The GDAL Data type.
int getType() const
It returns the data type of the elements in the band.
bool m_update_buffer
Flag to update buffer.
virtual int getBlockSize() const
It returns the number of bytes ocuppied by a data block.
te::rst::Raster * getRaster() const
Returns the associated raster.
TERASTEREXPORT void SetBlockFunctions(GetBufferValueFPtr *gb, GetBufferValueFPtr *gbi, SetBufferValueFPtr *sb, SetBufferValueFPtr *sbi, int type)
Sets the pointers to functions that helps to extract a double or complex value from a specific buffer...
int placeBuffer(unsigned c, unsigned r) const
Places the buffer in position adequate to obtain row/column values.
BandProperty * m_property
The band information.