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),
49 ( rst->
getGDALDataset()->GetRasterBand(1)->GetColorInterpretation() ==
61 m_x = std::numeric_limits<int>::max();
63 m_y = std::numeric_limits<int>::max();
70 m_raster(rhs.m_raster),
71 m_rasterBand(rhs.m_rasterBand),
72 m_getBuff(rhs.m_getBuff),
73 m_gdaltype(rhs.m_gdaltype)
77 m_x = std::numeric_limits<int>::max();
79 m_y = std::numeric_limits<int>::max();
88 m_rasterBand->WriteBlock(m_x, m_y, m_buffer);
90 m_rasterBand->FlushCache();
93 unsigned char* buff = (
unsigned char*)m_buffer;
113 unsigned char* buffer =
new unsigned char[rhs.
getBlockSize()];
115 for (
int x = 0; x < m_property->m_nblocksx; ++x)
116 for (
int y = 0; y < m_property->m_nblocksy; ++y)
118 rhs.
read(x, y, buffer);
131 m_i = placeBuffer(c, r);
133 m_getBuff(m_i, m_buffer, &value);
138 m_i = placeBuffer(c, r);
140 m_setBuff(m_i, m_buffer, &value);
142 m_update_buffer =
true;
147 m_i = placeBuffer(c, r);
149 m_getBuffI(m_i, m_buffer, &value);
154 m_i = placeBuffer(c, r);
156 m_setBuffI(m_i, m_buffer, &value);
158 m_update_buffer =
true;
163 m_rasterBand->ReadBlock(x, y, buffer);
168 if( m_rasterBand->GetColorInterpretation() == GCI_PaletteIndex )
170 const int bufferSize = m_property->m_blkh * m_property->m_blkw;
172 const GDALColorTable& cTable = *( m_rasterBand->GetColorTable() );
174 GDALColorEntry
const * cEntryPtr = 0;
179 for(
int bufferIdx = 0 ; bufferIdx < bufferSize ; ++bufferIdx )
181 m_getBuff( bufferIdx, buffer, &value );
183 cEntryPtr = cTable.GetColorEntry( (
int)value );
186 value = (double)cEntryPtr->c1;
188 m_setBuff( bufferIdx, buffer, &value );
192 for(
int bufferIdx = 0 ; bufferIdx < bufferSize ; ++bufferIdx )
194 m_getBuff( bufferIdx, buffer, &value );
196 cEntryPtr = cTable.GetColorEntry( (
int)value );
199 value = (double)cEntryPtr->c2;
201 m_setBuff( bufferIdx, buffer, &value );
205 for(
int bufferIdx = 0 ; bufferIdx < bufferSize ; ++bufferIdx )
207 m_getBuff( bufferIdx, buffer, &value );
209 cEntryPtr = cTable.GetColorEntry( (
int)value );
212 value = (double)cEntryPtr->c3;
214 m_setBuff( bufferIdx, buffer, &value );
218 for(
int bufferIdx = 0 ; bufferIdx < bufferSize ; ++bufferIdx )
220 m_getBuff( bufferIdx, buffer, &value );
222 cEntryPtr = cTable.GetColorEntry( (
int)value );
225 value = (double)cEntryPtr->c4;
227 m_setBuff( bufferIdx, buffer, &value );
231 throw Exception(
TE_TR(
"Invalid band index"));
239 if( ( x != m_x ) || ( y != m_y ) )
243 m_rasterBand->WriteBlock(m_x, m_y, m_buffer);
245 m_rasterBand->FlushCache();
247 m_update_buffer =
false;
250 read( x, y, m_buffer );
260 m_rasterBand->WriteBlock(x, y, buffer);
265 assert(c >= 0 && c < m_raster->getNumberOfColumns());
266 assert(r >= 0 && r < m_raster->getNumberOfRows());
268 m_currX = c / m_property->m_blkw;
270 m_currY = r / m_property->m_blkh;
272 m_currC = c % m_property->m_blkw;
274 m_currR = r % m_property->m_blkh;
276 if (m_currX != m_x || m_currY != m_y)
280 m_rasterBand->WriteBlock(m_x, m_y, m_buffer);
282 m_rasterBand->FlushCache();
284 m_update_buffer =
false;
287 read(m_currX, m_currY, m_buffer);
295 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.
GDALDataset * getGDALDataset() const
Returns the raster GDAL handler.
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...
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.
Band(Raster *rst, std::size_t idx)
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.