27 #include "../common/STLUtils.h"
28 #include "../geometry/Coord2D.h"
29 #include "../geometry/Envelope.h"
30 #include "../geometry/Polygon.h"
31 #include "../srs/Converter.h"
64 m_policy(rhs.m_policy)
106 return m_grid->getExtent();
111 return m_grid->getExtent();
120 converter->setSourceSRID(getSRID());
121 converter->setTargetSRID(srid);
123 unsigned int li=0, lf=getNumberOfRows()-1;
124 unsigned int ci=0, cf=getNumberOfColumns()-1;
130 li=
static_cast<unsigned int>(aux.
y);
131 ci=
static_cast<unsigned int>(aux.
x);
134 lf=
static_cast<unsigned int>(aux.
y);
135 cf=
static_cast<unsigned int>(aux.
x);
138 aux=m_grid->gridToGeo(ci,lf);
139 converter->convert(aux.
x,aux.
y);
143 aux=m_grid->gridToGeo(cf,li);
144 converter->convert(aux.
x,aux.
y);
149 for (
unsigned int c=ci; c<cf; ++c)
151 aux=m_grid->gridToGeo(c,li);
152 if (converter->convert(aux.
x,aux.
y))
154 if(llx > aux.
x) llx = aux.
x;
155 if(lly > aux.
y) lly = aux.
y;
156 if(urx < aux.
x) urx = aux.
x;
157 if(ury < aux.
y) ury = aux.
y;
162 for (
unsigned int c=ci; c<cf; ++c)
164 aux=m_grid->gridToGeo(c,lf);
165 if (converter->convert(aux.
x,aux.
y))
167 if(llx > aux.
x) llx = aux.
x;
168 if(lly > aux.
y) lly = aux.
y;
169 if(urx < aux.
x) urx = aux.
x;
170 if(ury < aux.
y) ury = aux.
y;
175 for (
unsigned int l=li; l<lf; ++l)
177 aux=m_grid->gridToGeo(ci,l);
178 if (converter->convert(aux.
x,aux.
y))
180 if(llx > aux.
x) llx = aux.
x;
181 if(lly > aux.
y) lly = aux.
y;
182 if(urx < aux.
x) urx = aux.
x;
183 if(ury < aux.
y) ury = aux.
y;
188 for (
unsigned int l=li; l<lf; ++l)
190 aux=m_grid->gridToGeo(cf,l);
191 if (converter->convert(aux.
x,aux.
y))
193 if(llx > aux.
x) llx = aux.
x;
194 if(lly > aux.
y) lly = aux.
y;
195 if(urx < aux.
x) urx = aux.
x;
196 if(ury < aux.
y) ury = aux.
y;
205 return m_grid->getSRID();
210 return m_grid->getNumberOfRows();
215 return m_grid->getNumberOfColumns();
220 return m_grid->getResolutionX();
225 return m_grid->getResolutionY();
230 getBand(b)->getValue(c, r, value);
235 getBand(b)->setValue(c, r, value);
240 getBand(b)->getIValue(c, r, value);
245 getBand(b)->setIValue(c, r, value);
250 getBand(b)->getValue(c, r, value);
255 getBand(b)->setValue(c, r, value);
264 for(std::size_t b = 0; b < getNumberOfBands(); b++)
266 getBand(b)->getValue(c, r, v);
276 std::complex<double> v;
278 for(std::size_t b = 0; b < getNumberOfBands(); b++)
280 getBand(b)->getValue(c, r, v);
288 assert(values.size() == getNumberOfBands());
290 for(std::size_t b = 0; b < getNumberOfBands(); b++)
291 getBand(b)->setValue(c, r, values[b]);
296 assert(values.size() == getNumberOfBands());
298 for(std::size_t b = 0; b < getNumberOfBands(); b++)
299 getBand(b)->setValue(c, r, values[b]);
304 std::ostringstream output;
307 output <<
"Raster Name......: " << m_name << std::endl;
308 output <<
"Number of Columns: " << getNumberOfColumns() << std::endl;
309 output <<
"Number of Rows...: " << getNumberOfRows() << std::endl;
310 output <<
"Number of Bands..: " << getNumberOfBands() << std::endl;
311 output <<
"SRID.............: " << getSRID() << std::endl;
312 output <<
"Resolution in X..: " << getResolutionX() << std::endl;
313 output <<
"Resolution in Y..: " << getResolutionY() << std::endl;
314 output <<
"Extent UR........: " << m_grid->getExtent()->getUpperRightX() <<
", " << m_grid->getExtent()->getUpperRightY() << std::endl;
315 output <<
"Extent LL........: " << m_grid->getExtent()->getLowerLeftX() <<
", " << m_grid->getExtent()->getLowerLeftY() << std::endl;
317 for (std::size_t b = 0; b < getNumberOfBands(); b++)
320 output <<
"Band: " << b <<
" " << getBand(b)->getProperty()->m_description << std::endl;
321 output <<
" Min Values...: " << getBand(b)->getMinValue() << std::endl;
322 output <<
" Max Values...: " << getBand(b)->getMaxValue() << std::endl;
323 output <<
" Mean Values..: " << getBand(b)->getMeanValue() << std::endl;
324 output <<
" Std Values...: " << getBand(b)->getStdValue() << std::endl;
325 output <<
" Gain values..: " << getBand(b)->getScaleValue() << std::endl;
326 output <<
" Offset values: " << getBand(b)->getOffsetValue() << std::endl;
338 for (std::size_t b = 0; b < getNumberOfBands(); b++)
339 this->
operator[](b) += rhs.operator[](b);
346 for (std::size_t b = 0; b < getNumberOfBands(); b++)
347 this->
operator[](b) += cvalue;
356 for (std::size_t b = 0; b < getNumberOfBands(); b++)
357 this->
operator[](b) -= rhs.operator[](b);
364 for (std::size_t b = 0; b < getNumberOfBands(); b++)
365 this->
operator[](b) -= cvalue;
374 for (std::size_t b = 0; b < getNumberOfBands(); b++)
375 this->
operator[](b) *= rhs.operator[](b);
382 for (std::size_t b = 0; b < getNumberOfBands(); b++)
383 this->
operator[](b) *= cvalue;
392 for (std::size_t b = 0; b < getNumberOfBands(); b++)
393 this->
operator[](b) /= rhs.operator[](b);
400 for (std::size_t b = 0; b < getNumberOfBands(); b++)
401 this->
operator[](b) /= cvalue;
429 const unsigned int firstInputRow = (
unsigned int)
431 (
double)( m_grid->getNumberOfRows() - 1 )
436 std::floor( curenv.
getY() )
439 const unsigned int firstInputCol = (
unsigned int)
441 (
double)( m_grid->getNumberOfColumns() - 1 )
446 std::floor( cllenv.
getX() )
449 const unsigned int lastInputRow = (
unsigned int)
451 (
double)( m_grid->getNumberOfRows() - 1 )
456 std::ceil( cllenv.
getY() )
459 const unsigned int lastInputCol = (
unsigned int)
461 (
double)( m_grid->getNumberOfColumns() - 1 )
466 std::ceil( curenv.
getX() )
470 if( ( lastInputRow <= firstInputRow ) || ( lastInputCol <= firstInputCol ) )
475 const unsigned int outputWidth = lastInputCol - firstInputCol + 1;
476 const unsigned int outputHeight = lastInputRow - firstInputRow + 1;
481 ((
double)firstInputRow) - 0.5 ) );
484 getResolutionY(), &ulc, getSRID() );
486 std::vector<te::rst::BandProperty*> bands;
488 for (std::size_t b = 0; b < getNumberOfBands(); b++)
491 bands[ b ]->m_nblocksx = 1;
492 bands[ b ]->m_nblocksy = outputHeight;
493 bands[ b ]->m_blkw = outputWidth;
494 bands[ b ]->m_blkh = 1;
503 std::vector<std::complex<double> > values;
509 for( ri = firstInputRow, ro = 0; ro < outputHeight; ri++, ro++)
511 for( ci = firstInputCol, co = 0; co < outputWidth; ci++, co++)
513 getValues(ci, ri, values);
530 std::vector<te::rst::BandProperty*> bands;
532 for (std::size_t b = 0; b < getNumberOfBands(); b++)
538 std::vector<std::complex<double> > v;
540 double ripp = applyScale(scale, 1.0);
542 double cipp = applyScale(scale, 1.0);
566 unsigned int dcolumn,
unsigned int height,
unsigned int width,
567 unsigned int newheight,
unsigned int newwidth,
568 const std::map<std::string, std::string>& rinfo)
const
570 assert(drow + height <= getNumberOfRows());
571 assert(dcolumn + width <= getNumberOfColumns());
573 te::gm::Coord2D ulc = getGrid()->gridToGeo( ((
double)dcolumn) - 0.5, ((
double)drow) - 0.5);
574 te::gm::Coord2D lrc = getGrid()->gridToGeo( ((
double)(dcolumn + width)) - 0.5,
575 ((
double)(drow + height)) - 0.5);
585 std::vector<te::rst::BandProperty*> bands;
587 for (std::size_t b = 0; b < getNumberOfBands(); b++)
590 bands[ b ]->m_blkh = 1;
591 bands[ b ]->m_blkw = newwidth;
592 bands[ b ]->m_nblocksx = 1;
593 bands[ b ]->m_nblocksy = newheight;
599 std::vector<std::complex<double> > v;
604 double ripp = ((double)(height-1)) / ((
double)(newheight-1));
606 double cipp = ((double)(width-1)) / ((
double)(newwidth-1));
612 for (
unsigned r = 0; r < newheight; r++, ri+=ripp)
615 for (
unsigned c = 0; c < newwidth; c++, ci+=cipp)
632 return new te::rst::Grid((
unsigned) std::ceil(applyScale(-scale, getNumberOfColumns())),
633 (
unsigned) std::ceil(applyScale(-scale, getNumberOfRows())),
634 applyScale(scale, getResolutionX()), applyScale(scale, getResolutionY()),
649 transformedEnvelope.
transform( getSRID(), srid );
651 double transformedResolutionX = transformedEnvelope.
getWidth() /
652 ((double)getNumberOfColumns());
653 double transformedResolutionY = transformedEnvelope.
getHeight() /
654 ((double)getNumberOfRows());
659 getExtent()->getLowerLeftX(),
660 getExtent()->getLowerLeftY(),
661 getExtent()->getUpperRightX(),
662 getExtent()->getUpperRightY(),
663 transformedResolutionX,
664 transformedResolutionY,
671 return this->transform(srid, llx, lly, urx, ury, 0, 0, rinfo, m);
690 assert(b < getNumberOfBands());
698 for (
unsigned int i = 0; i < g.size(); i++)
700 vp.push_back(bvalue % 255);
702 bvalue = bvalue >= 127? bvalue - 126: bvalue > 255? 0: bvalue + 127;
706 for (
unsigned int i = 0; i < g.size(); i++)
virtual void setValue(unsigned int c, unsigned int r, const double value, std::size_t b=0)
Sets the attribute value in a band of a cell.
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.
te::gm::Envelope * getExtent()
Returns the geographic extension of the raster data.
void getValues(const double &c, const double &r, std::vector< std::complex< double > > &values)
Get the interpolated value for all bands.
It describes one band (or dimension) of a raster.
It contains the algorithm to reproject raster data.
double applyScale(int i, const double &v) const
Scales a value according to a specific resampling scale.
A raster band description.
virtual Raster & operator/=(Raster &rhs)
It returns the raster division (pixel by pixel).
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
It interpolates one pixel based on a selected algorithm. Methods currently available are Nearest Neig...
virtual Raster * trim(const te::gm::Envelope *env, const std::map< std::string, std::string > &rinfo) const
Subsetting operation for trimming (cropping) the raster.
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.
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
This class implements the strategy to iterate with spatial restriction, the iteration occurs inside a...
virtual Raster * resample(int method, unsigned int drow, unsigned int dcolumn, unsigned int height, unsigned int width, unsigned int newheight, unsigned int newwidth, const std::map< std::string, std::string > &rinfo) const
Resample a subset of the raster, given a box.
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
double getWidth() const
It returns the envelope width.
virtual void setIValue(unsigned int c, unsigned int r, const double value, std::size_t b=0)
Sets the imaginary attribute value in a complex band of a cell.
unsigned int getRow() const
Returns the current row in iterator.
An utility struct for representing 2D coordinates.
double getY() const
It returns the y-coordinate.
virtual Raster & operator*=(Raster &rhs)
It returns the raster product (pixel by pixel).
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
void setAccessPolicy(te::common::AccessPolicy p)
Sets the raster access policy.
te::common::AccessPolicy getAccessPolicy() const
Returns the raster access policy.
std::string m_name
The raster name.
Grid * m_grid
The spatial support for raster data.
Grid * getResampledGrid(int scale) const
Return the raster grid for a specific scale.
AccessPolicy
Supported data access policies (can be used as bitfield).
An exception class for the Raster module.
Raster()
Default constructor.
bool run(std::vector< te::gm::Geometry * > &polygons)
Returns true if current algorithm implementation runs ok, false otherwise.
static PolygonIterator end(const te::rst::Raster *r, const te::gm::Polygon *p)
Returns an iterator referring to after the end of the iterator.
An abstract class for raster data strucutures.
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 ~Raster()
Virtual destructor.
virtual void rasterize(std::vector< te::gm::Geometry * > g, std::vector< double > vp, std::size_t b=0)
Rasterizes a given vector of geometries.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
virtual Raster & operator-=(Raster &rhs)
It returns the raster subtraction (pixel by pixel).
virtual Raster * getRaster() const =0
Returns the associated raster.
double getResolutionX() const
Returns the raster horizontal (x-axis) resolution.
void setName(const std::string name)
Sets the raster name.
It implements the vectorizer, based on TerraLib 4 algorithm.
It gives access to values in one band (dimension) of a raster.
A raster band description.
Grid * getGrid()
It returns the raster grid.
virtual Raster & operator=(const Raster &rhs)
Assignment operator.
virtual void getValue(unsigned int c, unsigned int r, double &value, std::size_t b=0) const
Returns the attribute value of a band of a cell.
A Converter is responsible for the conversion of coordinates between different Coordinate Systems (CS...
std::string toString(void) const
It returns the data value in a string notation.
int getSRID() const
Returns the raster spatial reference system identifier.
const std::string & getName() const
Returns the raster name.
virtual Raster * transform(int srid, const std::map< std::string, std::string > &rinfo, int m=1) const
Reprojects this raster to a distinct SRS. This method reprojects this raster to a distinct SRS...
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
double getX() const
It returns the x-coordinate.
TERASTEREXPORT te::rst::Raster * Reproject(te::rst::Raster const *const rin, int srid, const std::map< std::string, std::string > &routinfo, int m=te::rst::NearestNeighbor)
Reprojects a raster to another SRS.
static PolygonIterator begin(const te::rst::Raster *r, const te::gm::Polygon *p)
Returns an iterator referring to the first value of the band.
static Raster * make()
It creates and returns an empty raster with default raster driver.
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
A rectified grid is the spatial support for raster data.
double getResolutionY() const
Returns the raster vertical (y-axis) resolution.
virtual void getIValue(unsigned int c, unsigned int r, double &value, std::size_t b=0) const
Returns the imaginary attribute value in a complex band of a cell.
This is the abstract factory for Rasters.
unsigned int getColumn() const
Returns the current column in iterator.
A rectified grid is the spatial support for raster data.
void transform(int oldsrid, int newsrid)
It will transform the coordinates of the Envelope from the old SRS to the new one.
double getHeight() const
It returns the envelope height.
virtual Raster & operator+=(Raster &rhs)
It returns the raster sum (pixel by pixel).
It interpolates one pixel based on a selected algorithm.
virtual void vectorize(std::vector< te::gm::Geometry * > &g, std::size_t b, unsigned int mp=0)
Vectorizes a given raster band, using GDALPolygonize function.