27 #include "../common/STLUtils.h" 
   28 #include "../common/StringUtils.h" 
   29 #include "../common/Translator.h" 
   30 #include "../geometry/Envelope.h" 
   31 #include "../raster/Grid.h" 
   32 #include "../raster/RasterFactory.h" 
   33 #include "../raster/Utils.h" 
   44 #include <boost/lexical_cast.hpp> 
   58   const std::size_t nbands = rhs.
m_bands.size();
 
   60   for(std::size_t i = 0; i < nbands; ++i)
 
   91   std::map<std::string, std::string>::const_iterator it = rinfo.find(
"MEM_SRC_RASTER_DRIVER_TYPE");
 
   92   std::map<std::string, std::string>::const_iterator itend = rinfo.end();
 
   94   std::auto_ptr<te::rst::Raster> iraster(0);
 
  107   bool isTiled = 
false;
 
  109   it = rinfo.find(
"MEM_TILED_RASTER");
 
  116   int blkw = iraster->getNumberOfColumns();
 
  117   int blkh = iraster->getNumberOfRows();
 
  123     it = rinfo.find(
"MEM_TILE_WIDTH");
 
  127       blkw = boost::lexical_cast<
int>(it->second);
 
  129       it = rinfo.find(
"MEM_TILE_HEIGHT");
 
  132         throw Exception(
TE_TR(
"You must provide the MEM_TILE_HEIGHT parameter"));
 
  134       blkh = boost::lexical_cast<
int>(it->second);
 
  136       nblksx = (iraster->getNumberOfColumns() + blkw - 1) / blkw;
 
  137       nblksy = (iraster->getNumberOfRows() + blkh - 1) / blkh;
 
  141       it = rinfo.find(
"MEM_TILE_HEIGHT");
 
  145         throw Exception(
TE_TR(
"You must provide the MEM_TILE_WIDTH parameter"));
 
  149         if((iraster->getBand(0) == 0) || (iraster->getBand(0)->getProperty() == 0))
 
  150           throw Exception(
TE_TR(
"It is not possible to determine the in-memory raster tile dimension because the input raster doesn't have enough information!"));
 
  152         blkw = iraster->getBand(0)->getProperty()->m_blkw;
 
  153         blkh = iraster->getBand(0)->getProperty()->m_blkh;
 
  154         nblksx = iraster->getBand(0)->getProperty()->m_nblocksx;
 
  155         nblksy = iraster->getBand(0)->getProperty()->m_nblocksy;
 
  164   const std::size_t nbands = iraster->getNumberOfBands();
 
  166   for(std::size_t b = 0; b < nbands; ++b)
 
  172     bprop->m_blkh = blkh;
 
  173     bprop->m_blkw = blkw;
 
  174     bprop->m_nblocksx = nblksx;
 
  175     bprop->m_nblocksy = nblksy;
 
  184       m_bands.push_back(
new te::mem::Band(
this, bprop.release(), b));
 
  197   return std::map<std::string, std::string>();
 
  202   return m_bands.size();
 
  207   assert(i < getNumberOfBands());
 
  209   return m_bands[i]->getProperty()->getType();
 
  245     m_deleter(m_externalBuffer);
 
  246     m_externalBuffer = 0;
 
  257                              const std::vector<te::rst::BandProperty*> bands,
 
  258                              const std::map<std::string, std::string>& rinfo,
 
  259                              void* h, 
void (*deleter)(
void*))
 
  264   std::map<std::string, std::string>::const_iterator it;
 
  265   std::map<std::string, std::string>::const_iterator itend = rinfo.end();
 
  270   if(g != 0 && !bands.empty())
 
  280       bool isRaster = 
true;
 
  282       it = rinfo.find(
"MEM_IS_DATA_BUFFER");
 
  299           throw Exception(
TE_TR(
"You must provide a valid input raster in the 'h' parameter"));
 
  303         const std::size_t nbands = bands.size();
 
  305         bool isTiled = 
false;
 
  307         if (bands[0]->m_nblocksx > 1 || bands[0]->m_nblocksy > 1)
 
  310         for(std::size_t b = 0; b < nbands; ++b)
 
  326         for(std::size_t b = 0; b < bands.size(); ++b)
 
  330           ibprop->
m_blkh = m_grid->getNumberOfRows();
 
  331           ibprop->
m_blkw = m_grid->getNumberOfColumns();
 
  335           unsigned blksize = m_grid->getNumberOfRows() * m_grid->getNumberOfColumns() * 
te::rst::GetPixelSize(bands[b]->getType());
 
  337           void* externalBuffer = (
unsigned char*) h + (b * blksize);
 
  339           m_bands.push_back(
new te::mem::Band(
this, ibprop, b, externalBuffer));
 
  346       if (bands[0]->m_nblocksx > 1 || bands[0]->m_nblocksy > 1)
 
  349         for(std::size_t b = 0; b < bands.size(); ++b)
 
  351           if (bands[b]->m_blkw == 0 || bands[b]->m_blkh == 0)
 
  358             throw Exception(
TE_TR(
"You must provide the parameters of block height and width"));
 
  367         for(std::size_t b = 0; b < bands.size(); ++b)
 
  369           bands[b]->m_blkh = m_grid->getNumberOfRows();
 
  370           bands[b]->m_blkw = m_grid->getNumberOfColumns();
 
  371           bands[b]->m_nblocksx = 1;
 
  372           bands[b]->m_nblocksy = 1;
 
  381     bool isRaster = 
true;
 
  383     it = rinfo.find(
"MEM_IS_DATA_BUFFER");
 
  394         throw Exception(
TE_TR(
"You must provide a valid input raster in the 'h' parameter"));
 
  402       bool isTiled = 
false;
 
  407       for(std::size_t b = 0; b < nbands; ++b)
 
  417           m_bands.push_back(
new te::mem::Band(
this, bprop.release(), b));
 
  427       it = rinfo.find(
"MEM_BUFFER_NROWS");
 
  430         throw Exception(
TE_TR(
"You must provide the MEM_BUFFER_NROWS parameter"));
 
  432       unsigned int nrows = boost::lexical_cast<
unsigned>(it->second);
 
  435       it = rinfo.find(
"MEM_BUFFER_NCOLS");
 
  438         throw Exception(
TE_TR(
"You must provide the MEM_BUFFER_NCOLS parameter"));
 
  440       unsigned int ncols = boost::lexical_cast<
unsigned>(it->second);
 
  443       it = rinfo.find(
"MEM_BUFFER_DATATYPE");
 
  446         throw Exception(
TE_TR(
"You must provide the MEM_BUFFER_DATATYPE parameter"));
 
  448       unsigned int dt = boost::lexical_cast<
unsigned>(it->second);
 
  451       it = rinfo.find(
"MEM_BUFFER_NBANDS");
 
  454         throw Exception(
TE_TR(
"You must provide the MEM_BUFFER_NBANDS parameter"));
 
  456       unsigned int nbands = boost::lexical_cast<
unsigned>(it->second);
 
  459       it = rinfo.find(
"MEM_BUFFER_SRID");
 
  464         srid = boost::lexical_cast<
unsigned>(it->second);
 
  475       it = rinfo.find(
"MEM_BUFFER_MIN_X");
 
  479         minx = boost::lexical_cast<
double>(it->second);
 
  482         it = rinfo.find(
"MEM_BUFFER_MIN_Y");
 
  485           throw Exception(
TE_TR(
"You must provide the MEM_BUFFER_MIN_Y parameter"));
 
  487         miny = boost::lexical_cast<
double>(it->second);
 
  490         it = rinfo.find(
"MEM_BUFFER_MAX_X");
 
  493           throw Exception(
TE_TR(
"You must provide the MEM_BUFFER_MAX_X parameter"));
 
  495         maxx = boost::lexical_cast<
double>(it->second);
 
  498         it = rinfo.find(
"MEM_BUFFER_MAX_Y");
 
  501           throw Exception(
TE_TR(
"You must provide the MEM_BUFFER_MAX_Y parameter"));
 
  503         maxy = boost::lexical_cast<
double>(it->second);
 
  506         it = rinfo.find(
"MEM_BUFFER_RES_X");
 
  509           throw Exception(
TE_TR(
"You must provide the MEM_BUFFER_RES_X parameter"));
 
  511         resx = boost::lexical_cast<
double>(it->second);
 
  514         it = rinfo.find(
"MEM_BUFFER_RES_Y");
 
  517           throw Exception(
TE_TR(
"You must provide the MEM_BUFFER_RES_Y parameter"));
 
  519         resy = boost::lexical_cast<
double>(it->second);
 
  524       m_grid = 
new te::rst::Grid(ncols, nrows, resx, resy, mbr, srid);
 
  530       for(std::size_t b = 0; b < nbands; ++b)
 
  541         void* externalBuffer = (
unsigned char*) h + (b * blksize);
 
  543         m_bands.push_back(
new te::mem::Band(
this, ibprop, b, externalBuffer));
 
  548   else if(!rinfo.empty())
 
  550     it = rinfo.find(
"MEM_RASTER_NROWS");
 
  557       unsigned int nrows = boost::lexical_cast<
unsigned>(it->second);
 
  560       it = rinfo.find(
"MEM_RASTER_NCOLS");
 
  563         throw Exception(
TE_TR(
"You must provide the MEM_RASTER_NCOLS parameter"));
 
  565       unsigned int ncols = boost::lexical_cast<
unsigned>(it->second);
 
  568       it = rinfo.find(
"MEM_RASTER_DATATYPE");
 
  571         throw Exception(
TE_TR(
"You must provide the MEM_RASTER_DATATYPE parameter"));
 
  573       int dt  = boost::lexical_cast<
int>(it->second);
 
  576       it = rinfo.find(
"MEM_RASTER_NBANDS");
 
  579         throw Exception(
TE_TR(
"You must provide the MEM_RASTER_NBANDS parameter"));
 
  581       unsigned int nbands = boost::lexical_cast<
unsigned>(it->second);
 
  586       it = rinfo.find(
"MEM_RASTER_SRID");
 
  591         srid = boost::lexical_cast<
int>(it->second);
 
  602       it = rinfo.find(
"MEM_RASTER_MIN_X");
 
  606         minx = boost::lexical_cast<
double>(it->second);
 
  609         it = rinfo.find(
"MEM_RASTER_MIN_Y");
 
  612           throw Exception(
TE_TR(
"You must provide the MEM_RASTER_MIN_Y parameter"));
 
  614         miny = boost::lexical_cast<
double>(it->second);
 
  617         it = rinfo.find(
"MEM_RASTER_MAX_X");
 
  620           throw Exception(
TE_TR(
"You must provide the MEM_RASTER_MAX_X parameter"));
 
  622         maxx = boost::lexical_cast<
double>(it->second);
 
  625         it = rinfo.find(
"MEM_RASTER_MAX_Y");
 
  628           throw Exception(
TE_TR(
"You must provide the MEM_RASTER_MAX_Y parameter"));
 
  630         maxy = boost::lexical_cast<
double>(it->second);
 
  633         it = rinfo.find(
"MEM_RASTER_RES_X");
 
  636           throw Exception(
TE_TR(
"You must provide the MEM_RASTER_RES_X parameter"));
 
  638         resx = boost::lexical_cast<
double>(it->second);
 
  641         it = rinfo.find(
"MEM_RASTER_RES_Y");
 
  644           throw Exception(
TE_TR(
"You must provide the MEM_RASTER_RES_Y parameter"));
 
  646         resy = boost::lexical_cast<
double>(it->second);
 
  651       m_grid = 
new te::rst::Grid(ncols, nrows, resx, resy, mbr, srid);
 
  659       bool isTiled = 
false;
 
  661       it = rinfo.find(
"MEM_TILED_RASTER");
 
  675         it = rinfo.find(
"MEM_TILE_WIDTH");
 
  678           throw Exception(
TE_TR(
"You must provide the MEM_TILE_WIDTH parameter"));
 
  680         blkw = boost::lexical_cast<
int>(it->second);
 
  682         it = rinfo.find(
"MEM_TILE_HEIGHT");
 
  685           throw Exception(
TE_TR(
"You must provide the MEM_TILE_HEIGHT parameter"));
 
  687         blkh = boost::lexical_cast<
int>(it->second);
 
  689         nblksx = (ncols + blkw - 1) / blkw;
 
  690         nblksy = (nrows  + blkh - 1) / blkh;
 
  693       for(std::size_t b = 0; b < nbands; ++b)
 
  711     throw Exception(
TE_TR(
"You must provide enough parameters"));
 
A raster class for memory. 
 
const te::rst::Band * getBand(std::size_t i) const 
Returns the raster i-th band. 
 
~Raster()
Virtual destructor. 
 
A raster band description. 
 
A tiled band implementation for the In-Memory Raster. 
 
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 setRaster(Raster *r)
 
int m_nblocksy
The number of blocks in y. 
 
void setRaster(Raster *r)
 
TERASTEREXPORT void Copy(const Raster &rin, Raster &rout)
Copies the pixel values from one raster to another. 
 
std::vector< te::rst::Band * > m_bands
The list of data bands. 
 
std::string Convert2UCase(const std::string &value)
It converts a string to upper case. 
 
#define TE_TR(message)
It marks a string in order to get translated. 
 
An exception class for the TerraLib In-Memory Data Access driver. 
 
std::map< std::string, std::string > getInfo() const 
It returns additional information about the raster. 
 
AccessPolicy
Supported data access policies (can be used as bitfield). 
 
An Envelope defines a 2D rectangular region. 
 
An abstract class for raster data strucutures. 
 
BandProperty * getProperty()
Returns the band property. 
 
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. 
 
void open(const std::map< std::string, std::string > &rinfo, te::common::AccessPolicy p=te::common::RAccess)
Opens a raster. 
 
te::dt::AbstractData * clone() const 
It returns a clone of this object. 
 
A raster class for memory. 
 
A base class for values that can be retrieved from the data access module. 
 
A raster band description. 
 
Grid * getGrid()
It returns the raster grid. 
 
TERASTEREXPORT int GetPixelSize(int datatype)
Returns the byte size of a given datatype. 
 
Band implementation for the In-Memory Raster. 
 
const te::rst::Band & operator[](std::size_t i) const 
Access band in i position. 
 
int m_blkh
Block height (pixels). 
 
void create(te::rst::Grid *g, const std::vector< te::rst::BandProperty * > bands, const std::map< std::string, std::string > &rinfo, void *h, void(*deleter)(void *))
 
std::size_t getNumberOfBands() const 
Returns the number of bands (dimension of cells attribute values) in the raster. 
 
A rectified grid is the spatial support for raster data. 
 
void FreeContents(boost::unordered_map< K, V * > &m)
This function can be applied to a map of pointers. It will delete each pointer in the map...
 
int getBandDataType(std::size_t i) const 
Returns the data type in a particular band (or dimension). 
 
static Raster * open(const std::map< std::string, std::string > &rinfo, te::common::AccessPolicy p=te::common::RAccess)
It opens a raster with the given parameters and default raster driver.