27 #include "../core/translator/Translator.h" 28 #include "../common/PlatformUtils.h" 29 #include "../geometry/Envelope.h" 30 #include "../raster/Utils.h" 31 #include "../raster/BlockUtils.h" 32 #include "../raster/Interpolator.h" 37 #ifndef TLINTERNAL_EXPANSIBLERASTER_MAXDISKFILESSIZE 38 #define TLINTERNAL_EXPANSIBLERASTER_MAXDISKFILESSIZE 2147483648ul 62 if( rhsPtr ==
nullptr )
64 throw te::mem::Exception(
"Invalid constructor call" );
86 const std::vector<te::rst::BandProperty*> bandsProperties )
91 unsigned int maxBlockSizeBytes = 0;
92 std::vector< unsigned int> numbersOfBlocksX;
93 std::vector< unsigned int> numbersOfBlocksY;
94 std::vector< unsigned int> blocksSizesBytes;
97 for(
unsigned int bandIdx = 0 ; bandIdx < bandsProperties.size() ; ++bandIdx )
100 bandsProperties[ bandIdx ]->m_nblocksx = bandsProperties[ 0 ]->m_nblocksx;
101 bandsProperties[ bandIdx ]->m_nblocksy = bandsProperties[ 0 ]->m_nblocksy;
102 bandsProperties[ bandIdx ]->m_blkw = bandsProperties[ 0 ]->m_blkw;
103 bandsProperties[ bandIdx ]->m_blkh = bandsProperties[ 0 ]->m_blkh;
104 bandsProperties[ bandIdx ]->m_nblocksx = (
int)std::ceil(
106 ((
double)bandsProperties[ bandIdx ]->m_blkw) );
107 bandsProperties[ bandIdx ]->m_nblocksy = (
int)std::ceil(
109 ((
double)bandsProperties[ bandIdx ]->m_blkh) );
111 const unsigned int blockSizeBytes = (
unsigned int)(
112 bandsProperties[ bandIdx ]->m_blkw *
113 bandsProperties[ bandIdx ]->m_blkh *
116 if( maxBlockSizeBytes < blockSizeBytes )
117 maxBlockSizeBytes = blockSizeBytes;
119 numbersOfBlocksX.push_back( (
unsigned int)bandsProperties[ bandIdx ]->m_nblocksx );
120 numbersOfBlocksY.push_back( (
unsigned int)bandsProperties[ bandIdx ]->m_nblocksy );
121 blocksSizesBytes.push_back( blockSizeBytes );
128 const double freeVMem = ( ((double)maxMemPercentUsed) / 100.0 ) *
129 std::min( totalPhysMem, ( totalVMem - usedVMem ) );
130 const unsigned int maxNumberOfBlocks = (
unsigned int)
131 std::max( 1.0, std::ceil( freeVMem / ((
double)maxBlockSizeBytes) ) );
135 numbersOfBlocksY, blocksSizesBytes,
139 for(
unsigned int bandsIdx = 0 ; bandsIdx < bandsProperties.size() ;
143 *(bandsProperties[ bandsIdx ]) , bandsIdx ) );
144 delete ( bandsProperties[ bandsIdx ] );
149 const std::vector<te::rst::BandProperty*> bandsProperties,
150 const unsigned int maxNumberOfRAMBlocks )
155 std::vector< unsigned int> numbersOfBlocksX;
156 std::vector< unsigned int> numbersOfBlocksY;
157 std::vector< unsigned int> blocksSizesBytes;
160 for(
unsigned int bandIdx = 0 ; bandIdx < bandsProperties.size() ; ++bandIdx )
163 bandsProperties[ bandIdx ]->m_nblocksx = bandsProperties[ 0 ]->m_nblocksx;
164 bandsProperties[ bandIdx ]->m_nblocksy = bandsProperties[ 0 ]->m_nblocksy;
165 bandsProperties[ bandIdx ]->m_blkw = bandsProperties[ 0 ]->m_blkw;
166 bandsProperties[ bandIdx ]->m_blkh = bandsProperties[ 0 ]->m_blkh;
167 bandsProperties[ bandIdx ]->m_nblocksx = (
int)std::ceil(
169 ((
double)bandsProperties[ bandIdx ]->m_blkw) );
170 bandsProperties[ bandIdx ]->m_nblocksy = (
int)std::ceil(
172 ((
double)bandsProperties[ bandIdx ]->m_blkh) );
174 const unsigned int blockSizeBytes = (
unsigned int)(
175 bandsProperties[ bandIdx ]->m_blkw *
176 bandsProperties[ bandIdx ]->m_blkh *
179 numbersOfBlocksX.push_back( (
unsigned int)bandsProperties[ bandIdx ]->m_nblocksx );
180 numbersOfBlocksY.push_back( (
unsigned int)bandsProperties[ bandIdx ]->m_nblocksy );
181 blocksSizesBytes.push_back( blockSizeBytes );
187 numbersOfBlocksY, blocksSizesBytes,
191 for(
unsigned int bandsIdx = 0 ; bandsIdx < bandsProperties.size() ;
195 *(bandsProperties[ bandsIdx ]) , bandsIdx ) );
196 delete ( bandsProperties[ bandsIdx ] );
212 return std::map<std::string, std::string>();
217 const std::size_t nBands =
m_bands.size();
218 std::size_t bandIdx = 0;
220 std::vector<te::rst::BandProperty*> bandsProperties;
221 for( bandIdx = 0 ; bandIdx < nBands ; ++bandIdx )
224 *(
m_bands[ bandIdx ]->getProperty() ) ) );
236 for ( bandIdx = 0; bandIdx < nBands; ++bandIdx )
243 for( blkXIdx = 0; blkXIdx < nblcksX; ++blkXIdx )
245 for( blkYIdx = 0; blkYIdx < nblkksY; ++blkYIdx )
247 outBand.
write( blkXIdx, blkYIdx, inBand.
read( blkXIdx, blkYIdx ) );
252 return rasterPtr.release();
260 for(
unsigned int level = 1 ; level < levels ; ++level )
267 std::vector<te::rst::BandProperty*> bandsProperties;
272 )->getProperty() ) ) );
274 bandsProperties[ bandIdx ]->m_blkw = std::max( 1,
275 bandsProperties[ bandIdx ]->m_blkw / (
int)( 2 * level ) );
276 bandsProperties[ bandIdx ]->m_blkh = std::max( 1,
277 bandsProperties[ bandIdx ]->m_blkh / (
int)( 2 * level ) );
278 bandsProperties[ bandIdx ]->m_nblocksx = (
int)std::ceil(
279 ((
double)gridPtr->getNumberOfColumns()) /
280 ((
double)bandsProperties[ bandIdx ]->m_blkw) );
281 bandsProperties[ bandIdx ]->m_nblocksy = (
int)std::ceil(
282 ((
double)gridPtr->getNumberOfRows()) /
283 ((
double)bandsProperties[ bandIdx ]->m_blkh) );
286 boost::shared_ptr< ExpansibleRaster > outRasterPtr;
289 outRasterPtr.reset(
new ExpansibleRaster( gridPtr.release(), bandsProperties,
301 ((
double)outRasterPtr->getNumberOfColumns());
303 ((
double)outRasterPtr->getNumberOfRows());
304 const unsigned int outBandsNumber =
static_cast<unsigned int>(
getNumberOfBands());
305 const unsigned int outColsNumber = outRasterPtr->getNumberOfColumns();
306 const unsigned int outRowsNumber = outRasterPtr->getNumberOfRows();
308 unsigned int outBandIdx = 0;
309 unsigned int outCol = 0;
310 unsigned int outRow = 0;
313 std::complex<double> value;
315 for( outBandIdx = 0 ; outBandIdx < outBandsNumber ; ++outBandIdx )
317 te::rst::Band& outBand = (*(outRasterPtr->getBand( outBandIdx )));
319 for( outRow = 0 ; outRow < outRowsNumber ; ++outRow )
321 inRow = scaleFactorY * ((double)outRow);
323 for( outCol = 0 ; outCol < outColsNumber ; ++outCol )
325 inCol = scaleFactorX * ((double)outCol);
326 interp.
getValue( inCol, inRow, value, outBandIdx );
327 outBand.
setValue( outCol, outRow, value );
377 if(
m_bands.empty() )
return false;
381 const unsigned int blockExpansionSize = (
unsigned int)std::ceil(
382 ((
double)number) / ((
double)
m_bands[ 0 ]->getProperty()->m_blkh) );
384 std::vector< ExpansibleBandBlocksManager::BlockIndex3D > addedBlocksCoords;
386 for(
unsigned int bandsIdx = 0 ; bandsIdx <
m_bands.size() ; ++bandsIdx )
388 std::vector< ExpansibleBandBlocksManager::BlockIndex3D > bandAddedBlocksCoords;
390 bandAddedBlocksCoords ) )
393 addedBlocksCoords.insert( addedBlocksCoords.end(), bandAddedBlocksCoords.begin(),
394 bandAddedBlocksCoords.end() );
396 m_bands[ bandsIdx ]->getProperty()->m_nblocksy += blockExpansionSize;
401 const unsigned int newLinesNumber =
402 ((
unsigned int)
m_bands[ 0 ]->getProperty()->m_blkh) *
403 ((
unsigned int)
m_bands[ 0 ]->getProperty()->m_nblocksy );
404 const unsigned int newColsNumber =
405 ((
unsigned int)
m_bands[ 0 ]->getProperty()->m_blkw) *
406 ((
unsigned int)
m_bands[ 0 ]->getProperty()->m_nblocksx );
408 const double addedLinesNumber = (double)( blockExpansionSize *
409 ((
unsigned int)
m_bands[ 0 ]->getProperty()->m_blkh) );
428 if(
m_bands.empty() )
return false;
432 const unsigned int currExtraLines =
433 ( (
unsigned int)(
m_bands[ 0 ]->getProperty()->m_blkh *
434 m_bands[ 0 ]->getProperty()->m_nblocksy ) ) -
441 if( currExtraLines < number )
443 const unsigned int blockExpansionSize = (
unsigned int)std::ceil(
444 ((
double)number) / ((
double)
m_bands[ 0 ]->getProperty()->m_blkh) );
446 std::vector< ExpansibleBandBlocksManager::BlockIndex3D > addedBlocksCoords;
448 for(
unsigned int bandsIdx = 0 ; bandsIdx <
m_bands.size() ; ++bandsIdx )
450 std::vector< ExpansibleBandBlocksManager::BlockIndex3D > bandAddedBlocksCoords;
452 bandAddedBlocksCoords ) )
455 addedBlocksCoords.insert( addedBlocksCoords.end(), bandAddedBlocksCoords.begin(),
456 bandAddedBlocksCoords.end() );
458 m_bands[ bandsIdx ]->getProperty()->m_nblocksy += blockExpansionSize;
463 const unsigned int newLinesNumber =
464 ((
unsigned int)
m_bands[ 0 ]->getProperty()->m_blkh) *
465 ((
unsigned int)
m_bands[ 0 ]->getProperty()->m_nblocksy );
466 const unsigned int newColsNumber =
467 ((
unsigned int)
m_bands[ 0 ]->getProperty()->m_blkw) *
468 ((
unsigned int)
m_bands[ 0 ]->getProperty()->m_nblocksx );
493 if(
m_bands.empty() )
return false;
497 const unsigned int oldColsNumber =
498 ((
unsigned int)
m_bands[ 0 ]->getProperty()->m_blkw) *
499 ((
unsigned int)
m_bands[ 0 ]->getProperty()->m_nblocksx );
501 const unsigned int blockExpansionSize = (
unsigned int)std::ceil(
502 ((
double)number) / ((
double)
m_bands[ 0 ]->getProperty()->m_blkw) );
504 std::vector< ExpansibleBandBlocksManager::BlockIndex3D > addedBlocksCoords;
506 for(
unsigned int bandsIdx = 0 ; bandsIdx <
m_bands.size() ; ++bandsIdx )
508 std::vector< ExpansibleBandBlocksManager::BlockIndex3D > bandAddedBlocksCoords;
510 bandAddedBlocksCoords ) )
513 addedBlocksCoords.insert( addedBlocksCoords.end(), bandAddedBlocksCoords.begin(),
514 bandAddedBlocksCoords.end() );
516 m_bands[ bandsIdx ]->getProperty()->m_nblocksx += blockExpansionSize;
521 const unsigned int newLinesNumber =
522 ((
unsigned int)
m_bands[ 0 ]->getProperty()->m_blkh) *
523 ((
unsigned int)
m_bands[ 0 ]->getProperty()->m_nblocksy );
524 const unsigned int newColsNumber =
525 ((
unsigned int)
m_bands[ 0 ]->getProperty()->m_blkw) *
526 ((
unsigned int)
m_bands[ 0 ]->getProperty()->m_nblocksx );
528 const double addedColsNumber = (double)( newColsNumber - oldColsNumber );
547 if(
m_bands.empty() )
return false;
551 const unsigned int currExtraCols =
552 ( (
unsigned int)(
m_bands[ 0 ]->getProperty()->m_blkw *
553 m_bands[ 0 ]->getProperty()->m_nblocksx ) ) -
560 if( currExtraCols < number )
562 const unsigned int blockExpansionSize = (
unsigned int)std::ceil(
563 ((
double)number) / ((
double)
m_bands[ 0 ]->getProperty()->m_blkw) );
565 std::vector< ExpansibleBandBlocksManager::BlockIndex3D > addedBlocksCoords;
567 for(
unsigned int bandsIdx = 0 ; bandsIdx <
m_bands.size() ; ++bandsIdx )
569 std::vector< ExpansibleBandBlocksManager::BlockIndex3D > bandAddedBlocksCoords;
571 bandAddedBlocksCoords ) )
574 addedBlocksCoords.insert( addedBlocksCoords.end(), bandAddedBlocksCoords.begin(),
575 bandAddedBlocksCoords.end() );
577 m_bands[ bandsIdx ]->getProperty()->m_nblocksx += blockExpansionSize;
582 const unsigned int newLinesNumber =
583 ((
unsigned int)
m_bands[ 0 ]->getProperty()->m_blkh) *
584 ((
unsigned int)
m_bands[ 0 ]->getProperty()->m_nblocksy );
585 const unsigned int newColsNumber =
586 ((
unsigned int)
m_bands[ 0 ]->getProperty()->m_blkw) *
587 ((
unsigned int)
m_bands[ 0 ]->getProperty()->m_nblocksx );
612 if(
m_bands.empty() )
return false;
616 std::vector< ExpansibleBandBlocksManager::BlockIndex3D > addedBlocksCoords;
622 for(
unsigned int bIdx = 0 ; bIdx <
m_bands.size() ; ++bIdx )
629 delete( oldBandPtr );
634 *(
m_bands[ number ]->getProperty() ), bIdx );
646 if(
m_bands.empty() )
return false;
650 std::vector< ExpansibleBandBlocksManager::BlockIndex3D > addedBlocksCoords;
655 unsigned int lastBandIdx = (
unsigned int)
m_bands.size() - 1;
657 for(
unsigned int bIdx = lastBandIdx + 1 ; bIdx <
m_bands.size() ; ++bIdx )
660 *(
m_bands[ lastBandIdx ]->getProperty() ), bIdx );
673 for(
unsigned int bandsIdx = 0 ; bandsIdx <
m_bands.size() ; ++bandsIdx )
685 for(
unsigned int bandsIdx = 0 ; bandsIdx <
m_bands.size() ;
701 unsigned int blockXIdx = 0;
702 unsigned int blockYIdx = 0;
704 void* blockPtr =
nullptr;
706 for( blockXIdx = 0 ; blockXIdx < nBlocksX ; ++blockXIdx )
708 for( blockYIdx = 0 ; blockYIdx < nBlocksY ; ++blockYIdx )
714 for( eIdx = 0 ; eIdx < elementsNumber ; ++eIdx )
715 sb( eIdx, blockPtr, noDataValuePtr );
722 const std::vector< ExpansibleBandBlocksManager::BlockIndex3D >& blocksCoords )
724 for(
unsigned int coodsIdx = 0 ; coodsIdx < blocksCoords.size() ;
742 const int elementsNumber = band.getProperty()->m_blkh *
743 band.getProperty()->m_blkw;
745 double* noDataValuePtr = &( band.getProperty()->m_noDataValue );
747 for(
int eIdx = 0 ; eIdx < elementsNumber ; ++eIdx )
748 sb( eIdx, blockPtr, noDataValuePtr );
A raster (stored in memory and eventually swapped to disk) where it is possible to dynamically add li...
unsigned int getNumberOfRows() const
Returns the grid number of rows.
te::gm::Envelope * getExtent()
Returns the geographic extension of the raster data.
bool addTopLines(const unsigned int number)
New lines will be added at the top of the raster (before the first line).
std::vector< ExpansibleBand * > m_bands
Internal raster bands.
A raster class for memory.
TECOMMONEXPORT unsigned long long int GetTotalVirtualMemory()
Returns the amount of total virtual memory (bytes) that can be claimed by the current process (physic...
bool createMultiResolution(const unsigned int levels, const te::rst::InterpolationMethod interpMethod)
Create a sub-sampled multi-resolution pyramid.
A raster band description.
int getSRID() const
Returns the grid spatial reference system identifier.
Base exception class for plugin module.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
int m_nblocksx
The number of blocks in x.
void dummyFillBlocks(const std::vector< ExpansibleBandBlocksManager::BlockIndex3D > &blocksCoords)
Fill the required blocks with dummy values.
It interpolates one pixel based on a selected algorithm. Methods currently available are Nearest Neig...
int m_nblocksy
The number of blocks in y.
An exception class for the TerraLib In-Memory Data Access driver.
void dummyFillAllBlocks()
Fill all blocks with dummy values.
An utility struct for representing 2D coordinates.
std::vector< boost::shared_ptr< ExpansibleRaster > > m_multiResRasters
Pointer to Multi-resolution versions of this raster instance.
void getValue(const double &c, const double &r, std::complex< double > &v, const std::size_t &b)
Get the interpolated value at specific band.
int m_type
The data type of the elements in the band ( See te::dt namespace basic data types for reference )...
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits<double>::max().
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
#define TE_TR(message)
It marks a string in order to get translated.
std::size_t getNumberOfBands() const
Returns the number of bands (dimension of cells attribute values) in the raster.
InterpolationMethod
Allowed interpolation methods.
void(* SetBufferValueFPtr)(int index, void *buffer, const double *value)
The type of function used to extract data from a buffer.
double getResolutionY() const
Returns the grid vertical (y-axis) resolution.
Grid * m_grid
The spatial support for raster data.
void open(const std::map< std::string, std::string > &rinfo, te::common::AccessPolicy p=te::common::RAccess)
Opens a raster.
AccessPolicy
Supported data access policies (can be used as bitfield).
void(* GetBufferValueFPtr)(int index, void *buffer, double *value)
The type of function used to extract data from a buffer.
An Envelope defines a 2D rectangular region.
void free()
Free all allocated internal resources and go back to the initial state.
An abstract class for raster data strucutures.
bool addRightColumns(const unsigned int number)
New columns will be added at the right of the raster (after the last column).
unsigned int getNumberOfRows() const
Returns the raster number of rows.
std::map< std::string, std::string > getInfo() const
It returns additional information about the raster.
RAM cached and tiled raster band blocks manager.
BandProperty * getProperty()
Returns the band property.
CoordDataType m_dim0Index
Block Z (band) index.
int m_blkw
Block width (pixels).
bool addBottomBands(const unsigned int number)
New bands will be added at the bottom of the raster (after de the last band).
unsigned int getNumberOfColumns() const
Returns the grid number of columns.
double getResolutionX() const
Returns the grid horizontal (x-axis) resolution.
CoordDataType m_dim2Index
Block X index.
virtual void write(int x, int y, void *buffer)=0
It writes a data block from the specified buffer.
te::rst::Raster * getMultiResLevel(const unsigned int level) const
Returns the required level of a multi-resolution pyramid or NULL if that level does not exists...
bool addBottomLines(const unsigned int number)
New lines will be added at the bottom of the raster (after de the last line).
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.
unsigned int getMultiResLevelsCount() const
Returns the current number of multi-resolution pyramid levels.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
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.
TECOMMONEXPORT unsigned long long int GetTotalPhysicalMemory()
Returns the amount of total physical memory (bytes).
virtual void read(int x, int y, void *buffer) const =0
It reads a data block to the specified buffer.
int getSRID() const
Returns the raster spatial reference system identifier.
boost::shared_ptr< ExpansibleBandBlocksManager > m_blocksManagerPtr
Internal blocks manager.
bool removeMultiResolution()
Remove/Destroy a sub-sampled multi-resolution pyramid, if there is one.
A raster (stored in memory and eventually swapped to disk) where it is possible to dynamically add li...
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
te::gm::Envelope * getExtent()
Returns the geographic extension of the grid.
CoordDataType m_dim1Index
Block Y index.
te::dt::AbstractData * clone() const
It returns a clone of this object.
const te::rst::Band * getBand(std::size_t i) const
Returns the raster i-th band.
int m_blkh
Block height (pixels).
TECOMMONEXPORT unsigned long long int GetUsedVirtualMemory()
Returns the amount of used virtual memory (bytes) for the current process (physical + swapped)...
A rectified grid is the spatial support for raster data.
bool addLeftColumns(const unsigned int number)
New columns will be added at the left of the raster (before the first column).
bool addTopBands(const unsigned int number)
New bands will be added at the top of the raster (before the first band).
#define TLINTERNAL_EXPANSIBLERASTER_MAXDISKFILESSIZE
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...