27 #include "../common/STLUtils.h" 28 #include "../common/StringUtils.h" 29 #include "../core/translator/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> 55 const std::size_t nbands = rhs.
m_bands.size();
57 for(std::size_t i = 0; i < nbands; ++i)
88 std::map<std::string, std::string>::const_iterator it = rinfo.find(
"MEM_SRC_RASTER_DRIVER_TYPE");
89 std::map<std::string, std::string>::const_iterator itend = rinfo.end();
91 std::unique_ptr<te::rst::Raster> iraster;
104 bool isTiled =
false;
106 it = rinfo.find(
"MEM_TILED_RASTER");
113 int blkw = iraster->getNumberOfColumns();
114 int blkh = iraster->getNumberOfRows();
120 it = rinfo.find(
"MEM_TILE_WIDTH");
124 blkw = boost::lexical_cast<
int>(it->second);
126 it = rinfo.find(
"MEM_TILE_HEIGHT");
129 throw Exception(
TE_TR(
"You must provide the MEM_TILE_HEIGHT parameter"));
131 blkh = boost::lexical_cast<
int>(it->second);
133 nblksx = (iraster->getNumberOfColumns() + blkw - 1) / blkw;
134 nblksy = (iraster->getNumberOfRows() + blkh - 1) / blkh;
138 it = rinfo.find(
"MEM_TILE_HEIGHT");
142 throw Exception(
TE_TR(
"You must provide the MEM_TILE_WIDTH parameter"));
146 if((iraster->getBand(0) ==
nullptr) || (iraster->getBand(0)->getProperty() ==
nullptr))
147 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!"));
149 blkw = iraster->getBand(0)->getProperty()->m_blkw;
150 blkh = iraster->getBand(0)->getProperty()->m_blkh;
151 nblksx = iraster->getBand(0)->getProperty()->m_nblocksx;
152 nblksy = iraster->getBand(0)->getProperty()->m_nblocksy;
161 const std::size_t nbands = iraster->getNumberOfBands();
163 for(std::size_t
b = 0;
b < nbands; ++
b)
169 bprop->m_blkh = blkh;
170 bprop->m_blkw = blkw;
171 bprop->m_nblocksx = nblksx;
172 bprop->m_nblocksy = nblksy;
194 return std::map<std::string, std::string>();
206 return m_bands[i]->getProperty()->getType();
254 const std::vector<te::rst::BandProperty*>
bands,
255 const std::map<std::string, std::string>& rinfo,
256 void* h,
void (*deleter)(
void*))
261 std::map<std::string, std::string>::const_iterator it;
262 std::map<std::string, std::string>::const_iterator itend = rinfo.end();
267 if(g !=
nullptr && !bands.empty())
277 bool isRaster =
true;
279 it = rinfo.find(
"MEM_IS_DATA_BUFFER");
289 if (iraster ==
nullptr)
296 throw Exception(
TE_TR(
"You must provide a valid input raster in the 'h' parameter"));
300 const std::size_t nbands = bands.size();
302 bool isTiled =
false;
304 if (bands[0]->m_nblocksx > 1 || bands[0]->m_nblocksy > 1)
307 for(std::size_t
b = 0;
b < nbands; ++
b)
323 for(std::size_t
b = 0;
b < bands.size(); ++
b)
334 void* externalBuffer = (
unsigned char*) h + (
b * blksize);
343 if (bands[0]->m_nblocksx > 1 || bands[0]->m_nblocksy > 1)
346 for(std::size_t
b = 0;
b < bands.size(); ++
b)
348 if (bands[
b]->m_blkw == 0 || bands[
b]->m_blkh == 0)
355 throw Exception(
TE_TR(
"You must provide the parameters of block height and width"));
364 for(std::size_t
b = 0;
b < bands.size(); ++
b)
368 bands[
b]->m_nblocksx = 1;
369 bands[
b]->m_nblocksy = 1;
376 else if(h !=
nullptr)
378 bool isRaster =
true;
380 it = rinfo.find(
"MEM_IS_DATA_BUFFER");
390 if (iraster ==
nullptr)
391 throw Exception(
TE_TR(
"You must provide a valid input raster in the 'h' parameter"));
399 bool isTiled =
false;
404 for(std::size_t
b = 0;
b < nbands; ++
b)
424 it = rinfo.find(
"MEM_BUFFER_NROWS");
427 throw Exception(
TE_TR(
"You must provide the MEM_BUFFER_NROWS parameter"));
429 unsigned int nrows = boost::lexical_cast<
unsigned>(it->second);
432 it = rinfo.find(
"MEM_BUFFER_NCOLS");
435 throw Exception(
TE_TR(
"You must provide the MEM_BUFFER_NCOLS parameter"));
437 unsigned int ncols = boost::lexical_cast<
unsigned>(it->second);
440 it = rinfo.find(
"MEM_BUFFER_DATATYPE");
443 throw Exception(
TE_TR(
"You must provide the MEM_BUFFER_DATATYPE parameter"));
445 unsigned int dt = boost::lexical_cast<
unsigned>(it->second);
448 it = rinfo.find(
"MEM_BUFFER_NBANDS");
451 throw Exception(
TE_TR(
"You must provide the MEM_BUFFER_NBANDS parameter"));
453 unsigned int nbands = boost::lexical_cast<
unsigned>(it->second);
456 it = rinfo.find(
"MEM_BUFFER_SRID");
461 srid = boost::lexical_cast<
unsigned>(it->second);
472 it = rinfo.find(
"MEM_BUFFER_MIN_X");
476 minx = boost::lexical_cast<
double>(it->second);
479 it = rinfo.find(
"MEM_BUFFER_MIN_Y");
482 throw Exception(
TE_TR(
"You must provide the MEM_BUFFER_MIN_Y parameter"));
484 miny = boost::lexical_cast<
double>(it->second);
487 it = rinfo.find(
"MEM_BUFFER_MAX_X");
490 throw Exception(
TE_TR(
"You must provide the MEM_BUFFER_MAX_X parameter"));
492 maxx = boost::lexical_cast<
double>(it->second);
495 it = rinfo.find(
"MEM_BUFFER_MAX_Y");
498 throw Exception(
TE_TR(
"You must provide the MEM_BUFFER_MAX_Y parameter"));
500 maxy = boost::lexical_cast<
double>(it->second);
503 it = rinfo.find(
"MEM_BUFFER_RES_X");
506 throw Exception(
TE_TR(
"You must provide the MEM_BUFFER_RES_X parameter"));
508 resx = boost::lexical_cast<
double>(it->second);
511 it = rinfo.find(
"MEM_BUFFER_RES_Y");
514 throw Exception(
TE_TR(
"You must provide the MEM_BUFFER_RES_Y parameter"));
516 resy = boost::lexical_cast<
double>(it->second);
527 for(std::size_t
b = 0;
b < nbands; ++
b)
538 void* externalBuffer = (
unsigned char*) h + (
b * blksize);
545 else if(!rinfo.empty())
547 it = rinfo.find(
"MEM_RASTER_NROWS");
554 unsigned int nrows = boost::lexical_cast<
unsigned>(it->second);
557 it = rinfo.find(
"MEM_RASTER_NCOLS");
560 throw Exception(
TE_TR(
"You must provide the MEM_RASTER_NCOLS parameter"));
562 unsigned int ncols = boost::lexical_cast<
unsigned>(it->second);
565 it = rinfo.find(
"MEM_RASTER_DATATYPE");
568 throw Exception(
TE_TR(
"You must provide the MEM_RASTER_DATATYPE parameter"));
570 int dt = boost::lexical_cast<
int>(it->second);
573 it = rinfo.find(
"MEM_RASTER_NBANDS");
576 throw Exception(
TE_TR(
"You must provide the MEM_RASTER_NBANDS parameter"));
578 unsigned int nbands = boost::lexical_cast<
unsigned>(it->second);
583 it = rinfo.find(
"MEM_RASTER_SRID");
588 srid = boost::lexical_cast<
int>(it->second);
599 it = rinfo.find(
"MEM_RASTER_MIN_X");
603 minx = boost::lexical_cast<
double>(it->second);
606 it = rinfo.find(
"MEM_RASTER_MIN_Y");
609 throw Exception(
TE_TR(
"You must provide the MEM_RASTER_MIN_Y parameter"));
611 miny = boost::lexical_cast<
double>(it->second);
614 it = rinfo.find(
"MEM_RASTER_MAX_X");
617 throw Exception(
TE_TR(
"You must provide the MEM_RASTER_MAX_X parameter"));
619 maxx = boost::lexical_cast<
double>(it->second);
622 it = rinfo.find(
"MEM_RASTER_MAX_Y");
625 throw Exception(
TE_TR(
"You must provide the MEM_RASTER_MAX_Y parameter"));
627 maxy = boost::lexical_cast<
double>(it->second);
630 it = rinfo.find(
"MEM_RASTER_RES_X");
633 throw Exception(
TE_TR(
"You must provide the MEM_RASTER_RES_X parameter"));
635 resx = boost::lexical_cast<
double>(it->second);
638 it = rinfo.find(
"MEM_RASTER_RES_Y");
641 throw Exception(
TE_TR(
"You must provide the MEM_RASTER_RES_Y parameter"));
643 resy = boost::lexical_cast<
double>(it->second);
656 bool isTiled =
false;
658 it = rinfo.find(
"MEM_TILED_RASTER");
672 it = rinfo.find(
"MEM_TILE_WIDTH");
675 throw Exception(
TE_TR(
"You must provide the MEM_TILE_WIDTH parameter"));
677 blkw = boost::lexical_cast<
int>(it->second);
679 it = rinfo.find(
"MEM_TILE_HEIGHT");
682 throw Exception(
TE_TR(
"You must provide the MEM_TILE_HEIGHT parameter"));
684 blkh = boost::lexical_cast<
int>(it->second);
686 nblksx = (ncols + blkw - 1) / blkw;
687 nblksy = (nrows + blkh - 1) / blkh;
690 for(std::size_t
b = 0;
b < nbands; ++
b)
unsigned int getNumberOfRows() const
Returns the grid number of rows.
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.
Base exception class for plugin module.
A tiled band implementation for the In-Memory Raster.
int m_nblocksx
The number of blocks in x.
void setRaster(Raster *r)
int m_nblocksy
The number of blocks in y.
void setRaster(Raster *r)
An exception class for the TerraLib In-Memory Data Access driver.
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.
std::map< std::string, std::string > getInfo() const
It returns additional information about the raster.
std::string m_name
The raster name.
Grid * m_grid
The spatial support for raster data.
AccessPolicy
Supported data access policies (can be used as bitfield).
A raster class for memory.
An Envelope defines a 2D rectangular region.
An abstract class for raster data strucutures.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
BandProperty * getProperty()
Returns the band property.
int m_blkw
Block width (pixels).
void open(const std::map< std::string, std::string > &rinfo, te::common::AccessPolicy p=te::common::RAccess)
Opens a raster.
static te::dt::TimeDuration dt(20, 30, 50, 11)
unsigned int getNumberOfColumns() const
Returns the grid number of columns.
te::dt::AbstractData * clone() const
It returns a clone of this object.
void(* m_deleter)(void *)
A pointer to a deleter function, if the buffer needs to be deleted by this object.
A base class for values that can be retrieved from the data access module.
A raster band description.
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
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...
te::common::AccessPolicy m_policy
The access policy, can be te::common::{NoAccess, RAccess, RWAccess, WAccess}.
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.
void * m_externalBuffer
An external buffer.