27 #include "../datatype/Enums.h" 28 #include "../geometry/Coord2D.h" 29 #include "../common/MathUtils.h" 37 #include <boost/cstdint.hpp> 38 #include <boost/random.hpp> 39 #include <boost/random/uniform_int_distribution.hpp> 50 sizeof(
unsigned char),
51 sizeof(boost::int16_t),
52 sizeof(boost::uint16_t),
53 sizeof(boost::int32_t),
54 sizeof(boost::uint32_t),
55 sizeof(boost::int64_t),
56 sizeof(boost::uint64_t),
69 sizeof(boost::int16_t) * 2,
70 sizeof(boost::int32_t) * 2,
76 sizeof(
unsigned char),
77 sizeof(
unsigned char),
83 return sg_pixelSize[datatype];
90 std::vector<te::rst::BandProperty*> bprops;
92 std::map<std::string, std::string>::const_iterator it = rinfo.find(
"NBANDS");
95 throw Exception((
"Number of bands must be set!"));
97 nBands = atoi(it->second.c_str());
99 it = rinfo.find(
"BANDSTYPE");
101 if(it == rinfo.end())
102 throw Exception((
"Data type of bands must be set!"));
104 tBands = atoi(it->second.c_str());
106 for (std::size_t
b = 0;
b < nBands;
b++)
114 unsigned nCols, nRows;
115 double resX = 1.0, resY = 1.0, ulX =0.0, ulY=0.0;
119 std::map<std::string, std::string>::const_iterator it = rinfo.find(
"NCOLS");
121 if(it == rinfo.end())
122 throw Exception((
"Number of columns must be set!"));
124 nCols = atoi(it->second.c_str());
126 it = rinfo.find(
"NROWS");
128 if(it == rinfo.end())
129 throw Exception((
"Number of rows must be set!"));
131 nRows = atoi(it->second.c_str());
133 it = rinfo.find(
"RESX");
134 if(it != rinfo.end())
135 resX = atof(it->second.c_str());
137 it = rinfo.find(
"RESY");
138 if(it != rinfo.end())
139 resY = atof(it->second.c_str());
141 it = rinfo.find(
"SRID");
142 if(it != rinfo.end())
143 srid = atoi(it->second.c_str());
145 it = rinfo.find(
"ULX");
146 if(it != rinfo.end())
147 ulX = atof(it->second.c_str());
149 it = rinfo.find(
"ULY");
150 if(it != rinfo.end())
151 ulY = atof(it->second.c_str());
155 return (
new te::rst::Grid(nCols, nRows, resX, resY, ulc, srid));
166 unsigned int row = 0;
167 unsigned int col = 0;
168 std::complex< double > value;
170 for(std::size_t
b = 0;
b < nbands;
b++)
181 for(row = 0 ; row < nRows ; ++row)
199 unsigned char* buffer =
new unsigned char[bin.
getBlockSize()];
211 for(
int y = 0; y < nblocksy; ++y)
213 for(
int x = 0; x < nblocksx; ++x)
215 bin.
read(x, y, buffer);
216 bout.
write(x, y, buffer);
223 std::complex<double> value;
228 for(
int y = 0; y < nblocksy; ++y)
230 for(
int x = 0; x < nblocksx; ++x)
232 unsigned int w = blkw * (x + 1);
234 w = w > ncols ? ncols : w;
236 unsigned int h = blkh * (y + 1);
238 h = h > nrows ? nrows : h;
240 for(
int r = blkh * y; r < (
int)h; ++r)
242 for(
int c = blkw * x; c < (
int)w; ++c)
277 std::vector<std::complex<double> > v;
279 for (
unsigned r = drow; r < drow + height; r++)
281 for (
unsigned c = dcolumn; c < dcolumn + width; c++)
287 int x =
Round(outputGrid.
x);
288 int y =
Round(outputGrid.
y);
300 const std::string& uri,
301 const std::string &rType)
303 std::map<std::string, std::string> rasterInfo;
304 rasterInfo[
"URI"] = uri;
306 std::vector<te::rst::BandProperty*> bandsProperties;
308 unsigned int bandIndex = 0;
319 if(outRasterPtr.get() ==
nullptr)
322 Copy(rin, *outRasterPtr);
358 max = (double)std::numeric_limits<unsigned short int>::max();
362 min = (double)std::numeric_limits<short int>::min();
363 max = (double)std::numeric_limits<short int>::max();
368 max = (double)std::numeric_limits<unsigned int>::max();
372 min = (double)std::numeric_limits<int>::min();
373 max = (double)std::numeric_limits<int>::max();
377 min = -(double)std::numeric_limits< float >::max();
378 max = (double)std::numeric_limits< float >::max();
382 min = -std::numeric_limits< double >::max();
383 max = std::numeric_limits< double >::max();
387 min = (double)std::numeric_limits<short int>::min();
388 max = (double)std::numeric_limits<short int>::max();
392 min = (double)std::numeric_limits<int>::min();
393 max = (double)std::numeric_limits<int>::max();
397 min = -(double)std::numeric_limits< float >::max();
398 max = (double)std::numeric_limits< float >::max();
402 min = -std::numeric_limits< double >::max();
403 max = std::numeric_limits< double >::max();
407 throw te::rst::Exception(
"Invalid data type");
426 std::vector< te::gm::Geometry const *> geometries;
427 geometries.push_back( &pin );
433 const std::vector< te::gm::Geometry const *> geometries,
434 const std::map<std::string, std::string>& rinfo,
435 const std::string& rType)
437 std::unique_ptr< te::rst::Raster > outRasterPtr;
445 outEnvelope.
m_llx = outEnvelope.
m_lly = std::numeric_limits< double >::max();
446 outEnvelope.
m_urx = outEnvelope.
m_ury = -1.0 * std::numeric_limits< double >::max();
448 const std::size_t geometriesSize = geometries.size();
449 std::size_t geometriesIdx = 0;
453 for( geometriesIdx = 0 ; geometriesIdx < geometriesSize ; ++geometriesIdx )
455 gPtr = geometries[ geometriesIdx ];
470 gEnvelopePtr = gPtr->
getMBR();
472 outEnvelope.
m_llx = std::min( outEnvelope.
m_llx, gEnvelopePtr->
m_llx );
473 outEnvelope.
m_lly = std::min( outEnvelope.
m_lly, gEnvelopePtr->
m_lly );
474 outEnvelope.
m_urx = std::max( outEnvelope.
m_urx, gEnvelopePtr->
m_urx );
475 outEnvelope.
m_ury = std::max( outEnvelope.
m_ury, gEnvelopePtr->
m_ury );
481 unsigned int firstInputRow = 0;
482 unsigned int firstInputCol = 0;
491 te::common::Round< double, unsigned int >(
503 te::common::Round< double, unsigned int >(
514 const unsigned int lastInputRow =
515 te::common::Round< double, unsigned int >(
526 const unsigned int lastInputCol =
527 te::common::Round< double, unsigned int >(
539 if( ( lastInputRow <= firstInputRow ) || ( lastInputCol <= firstInputCol ) )
544 const unsigned int outputWidth = lastInputCol - firstInputCol + 1;
545 const unsigned int outputHeight = lastInputRow - firstInputRow + 1;
547 if( ( outputHeight == 0 ) || ( outputHeight == 0 ) )
553 ((
double)firstInputRow) - 0.5 ) );
558 std::vector<te::rst::BandProperty*>
bands;
563 bands[
b ]->m_nblocksx = 1;
564 bands[
b ]->m_nblocksy = outputHeight;
565 bands[
b ]->m_blkw = outputWidth;
566 bands[
b ]->m_blkh = 1;
570 if( outRasterPtr.get() == nullptr )
582 const std::size_t geometriesSize = geometries.size();
583 std::size_t geometriesIdx = 0;
584 std::vector< te::gm::Geometry * > singleGgeomsPtrs;
585 std::size_t singleGgeomsPtrsIdx = 0;
586 std::size_t singleGgeomsPtrsSize = 0;
587 std::vector<std::complex<double> > values;
588 unsigned int outRow = 0;
589 unsigned int outCol = 0;
591 for( geometriesIdx = 0 ; geometriesIdx < geometriesSize ; ++geometriesIdx )
593 for(
auto p : singleGgeomsPtrs)
595 singleGgeomsPtrs.
clear();
598 singleGgeomsPtrsSize = singleGgeomsPtrs.size();
600 for( singleGgeomsPtrsIdx = 0 ; singleGgeomsPtrsIdx < singleGgeomsPtrsSize ;
601 ++singleGgeomsPtrsIdx )
603 assert( singleGgeomsPtrs[ singleGgeomsPtrsIdx ]->getGeomTypeId() ==
607 outRasterPtr.get(), (
te::gm::Polygon*)singleGgeomsPtrs[ singleGgeomsPtrsIdx ] );
609 outRasterPtr.get(), (
te::gm::Polygon*)singleGgeomsPtrs[ singleGgeomsPtrsIdx ] );
616 rin.
getValues( outCol + firstInputCol, outRow + firstInputRow, values );
617 outRasterPtr->setValues( outCol, outRow, values );
624 for(
auto p : singleGgeomsPtrs)
626 singleGgeomsPtrs.
clear();
634 std::vector<te::gm::Point*> randomPoints;
638 boost::random::mt19937 generator((boost::random::mt19937::result_type) time(
nullptr));
639 boost::random::uniform_int_distribution<> random_rows(0, inputRaster.
getNumberOfRows() - 1);
640 boost::random::uniform_int_distribution<> random_columns(0, inputRaster.
getNumberOfColumns() - 1);
642 for (
unsigned int p = 0;
p < numberOfPoints;
p++)
644 inputRaster.
getGrid()->
gridToGeo(random_columns(generator), random_rows(generator), randX, randY);
654 return TE_TR(
"Undefined");
656 return TE_TR(
"Gray");
658 return TE_TR(
"Palette");
662 return TE_TR(
"Green");
664 return TE_TR(
"Blue");
666 return TE_TR(
"Alpha");
670 return TE_TR(
"Saturation");
672 return TE_TR(
"Lightness");
674 return TE_TR(
"Cyan");
676 return TE_TR(
"Magenta");
678 return TE_TR(
"Yellow");
694 return TE_TR(
"Undefined");
696 return TE_TR(
"Gray");
700 return TE_TR(
"CMYK");
TERASTEREXPORT te::rst::RasterPtr CropRaster(const te::rst::Raster &rin, const te::gm::Polygon &pin, const std::map< std::string, std::string > &rinfo, const std::string &rType=std::string("GDAL"))
Creates a raster crop using a polygon delimiter.
An exception class for the Raster module.
HSL indexed palette interpretation.
unsigned int getNumberOfRows() const
Returns the grid number of rows.
virtual void setValues(unsigned int c, unsigned int r, const std::vector< double > &values)
Sets the imaginary attribute values in all complex bands of a cell.
unsigned int getRow() const
Returns the current row in iterator.
Palette indexes color interpretation.
Hue channel color interpretation.
Alpha channel color interpretation.
TERASTEREXPORT void FillBand(te::rst::Band *bin, const std::complex< double > &value)
Fill a Raster Band with provided value.
TERASTEREXPORT void GetDataTypeRanges(const int &dataType, double &min, double &max)
Return the values range of a given data type.
Index into a lookup table.
unsigned int getColumn() const
Returns the current column in iterator.
Lightness color interpretation.
#define TE_UNKNOWN_SRS
A numeric value to represent a unknown SRS identification in TerraLib.
ColorInterp
Color model component use.
A raster band description.
RGB indexed palette interpretation.
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.
Gray indexed palette interpretation.
TERASTEREXPORT te::rst::RasterPtr CreateCopy(const te::rst::Raster &rin, const std::string &uri, const std::string &rType=std::string("GDAL"))
Create a new raster from existing one.
GeomType getGeomTypeId() const _NOEXCEPT_OP(true)
It returns the geometry subclass type identifier.
int m_nblocksy
The number of blocks in y.
virtual void getValues(unsigned int c, unsigned int r, std::vector< double > &values) const
Returns the imaginary attribute values in all complex bands of a cell.
This class implements the strategy to iterate with spatial restriction, the iteration occurs inside a...
TERASTEREXPORT void Copy(const Raster &rin, Raster &rout)
Copies the pixel values from one raster to another.
double m_urx
Upper right corner x-coordinate.
Red channel color interpretation.
TERASTEREXPORT void FillRaster(te::rst::Raster *rin, const std::complex< double > &value)
Fill a Raster with provided value (all bands).
unsigned int getRow() const
Returns the current row in iterator.
An utility struct for representing 2D coordinates.
double m_noDataValue
Value to indicate elements where there is no data, default is std::numeric_limits<double>::max().
#define TE_TR(message)
It marks a string in order to get translated.
Cyan color interpretation.
TERASTEREXPORT std::string ConvertColorInterpTypeToString(const te::rst::ColorInterp &ci)
Function used to convert from a Color Interp Enum to a string.
TEGEOMEXPORT void Multi2Single(const te::gm::Geometry *g, std::vector< te::gm::Geometry * > &geoms)
It will get a GeometryCollection and distribute in a vector.
This class implements an iterator to "navigate" over a single band (const).
void geoToGrid(const double &x, const double &y, double &col, double &row) const
Get the grid point associated to a spatial location.
static ConstBandIterator begin(const Band *b)
Returns an iterator referring to the first value of the band.
te::common::AccessPolicy getAccessPolicy() const
Returns the raster access policy.
Utility functions for the raster module.
unsigned int unsigned int nCols
boost::shared_ptr< Raster > RasterPtr
This is the abstract factory for Rasters.
double m_llx
Lower left corner x-coordinate.
A point with x and y coordinate values.
const Envelope * getMBR() const _NOEXCEPT_OP(true)
It returns the minimum bounding rectangle for the geometry in an internal representation.
YCbCr Cr Band color interpretation.
An Envelope defines a 2D rectangular region.
An abstract class for raster data strucutures.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
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.
It implements an iterator to "navigate" over a single band (const or not const).
int m_blkw
Block width (pixels).
unsigned int getNumberOfColumns() const
Returns the grid number of columns.
double getResolutionX() const
Returns the raster horizontal (x-axis) resolution.
virtual void write(int x, int y, void *buffer)=0
It writes a data block from the specified buffer.
void Copy(std::string dataSetName, std::unique_ptr< te::da::DataSource > inDs, te::da::DataSource *outDs)
No color interpretation is associated with the band.
A raster band description.
Undefined palette interpretation.
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.
Geometry is the root class of the geometries hierarchy, it follows OGC and ISO standards.
Key (black) color interpretation.
Yellow color interpretation.
OutputValueT Round(const InputValueT &inVal)
Round a value.
double m_lly
Lower left corner y-coordinate.
virtual void setValue(unsigned int c, unsigned int r, const double value)=0
Sets the cell attribute value.
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.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
TERASTEREXPORT Grid * GetGrid(const std::map< std::string, std::string > &rinfo)
Returns a grid based on a given raster info.
double m_ury
Upper right corner y-coordinate.
static Raster * make()
It creates and returns an empty raster with default raster driver.
TERASTEREXPORT std::string ConvertPalleteInterpTypeToString(const te::rst::PaletteInterpretation &pi)
Function used to convert from a Pallete Interp Enum to a string.
void clear()
It deletes all the rings of the CurvePolygon and clear it.
virtual Raster * getRaster() const =0
Returns the associated raster.
void gridToGeo(const double &col, const double &row, double &x, double &y) const
Get the spatial location of a grid point.
double getResolutionY() const
Returns the raster vertical (y-axis) resolution.
TERASTEREXPORT std::vector< te::gm::Point * > GetRandomPointsInRaster(const te::rst::Raster &inputRaster, unsigned int numberOfPoints=1000)
Creates a vector of random positions (points) inside the raster.
YCbCr Y Band color interpretation.
int getType() const
It returns the data type of the elements in the band.
CMYK indexed palette interpretation.
Saturation color interpretation.
int m_blkh
Block height (pixels).
Blue channel color interpretation.
PaletteInterpretation
Palette interpratation types.
unsigned int getColumn() const
Returns the current column in iterator.
A rectified grid is the spatial support for raster data.
static int sg_pixelSize[]
Green channel color interpretation.
virtual int getBlockSize() const
It returns the number of bytes ocuppied by a data block.
Magenta color interpretation.
YCbCr Cb Band color interpretation.
TERASTEREXPORT std::vector< BandProperty * > GetBandProperties(const std::map< std::string, std::string > &rinfo)
Returns a vector of band properties, based on a given raster info.
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.
static ConstBandIterator end(const Band *b)
Returns an iterator referring to after the end of the iterator.