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;
434 const unsigned height =
static_cast<unsigned>(std::fabs(cllenv.
y - curenv.
y)) + 1;
436 const unsigned width =
static_cast<unsigned>(std::fabs(cllenv.
x - curenv.
x)) + 1;
438 const unsigned dxoff =
static_cast<unsigned>(std::fabs(cllenv.
x - cllimg.
x));
440 const unsigned dyoff =
static_cast<unsigned>(curenv.
y);
445 getResolutionY(), &ulc, getSRID() );
447 std::vector<te::rst::BandProperty*> bands;
449 for (std::size_t b = 0; b < getNumberOfBands(); b++)
458 std::vector<std::complex<double> > values;
460 for (
unsigned ri = dyoff, ro = 0; ro < height; ri++, ro++)
462 for (
unsigned ci = dxoff, co = 0; co < width; ci++, co++)
464 getValues(ci, ri, values);
481 std::vector<te::rst::BandProperty*> bands;
483 for (std::size_t b = 0; b < getNumberOfBands(); b++)
489 std::vector<std::complex<double> > v;
491 double ripp = applyScale(scale, 1.0);
493 double cipp = applyScale(scale, 1.0);
517 unsigned int dcolumn,
unsigned int height,
unsigned int width,
518 unsigned int newheight,
unsigned int newwidth,
519 const std::map<std::string, std::string>& rinfo)
const
521 assert(drow + height <= getNumberOfRows());
522 assert(dcolumn + width <= getNumberOfColumns());
524 te::gm::Coord2D ulc = getGrid()->gridToGeo( ((
double)dcolumn) - 0.5, ((
double)drow) - 0.5);
525 te::gm::Coord2D lrc = getGrid()->gridToGeo( ((
double)(dcolumn + width)) - 0.5,
526 ((
double)(drow + height)) - 0.5);
536 std::vector<te::rst::BandProperty*> bands;
538 for (std::size_t b = 0; b < getNumberOfBands(); b++)
541 bands[ b ]->m_blkh = 1;
542 bands[ b ]->m_blkw = newwidth;
543 bands[ b ]->m_nblocksx = 1;
544 bands[ b ]->m_nblocksy = newheight;
550 std::vector<std::complex<double> > v;
555 double ripp = ((double)height) / ((double)newheight);
557 double cipp = ((double)width) / ((double)newwidth);
563 for (
unsigned r = 0; r < newheight; r++, ri+=ripp)
566 for (
unsigned c = 0; c < newwidth; c++, ci+=cipp)
583 return new te::rst::Grid((
unsigned) std::ceil(applyScale(-scale, getNumberOfColumns())),
584 (
unsigned) std::ceil(applyScale(-scale, getNumberOfRows())),
585 applyScale(scale, getResolutionX()), applyScale(scale, getResolutionY()),
600 transformedEnvelope.
transform( getSRID(), srid );
602 double transformedResolutionX = transformedEnvelope.
getWidth() /
603 ((double)getNumberOfColumns());
604 double transformedResolutionY = transformedEnvelope.
getHeight() /
605 ((double)getNumberOfRows());
610 getExtent()->getLowerLeftX(),
611 getExtent()->getLowerLeftY(),
612 getExtent()->getUpperRightX(),
613 getExtent()->getUpperRightY(),
614 transformedResolutionX,
615 transformedResolutionY,
622 return this->transform(srid, llx, lly, urx, ury, 0, 0, rinfo, m);
641 assert(b < getNumberOfBands());
649 for (
unsigned int i = 0; i < g.size(); i++)
651 vp.push_back(bvalue % 255);
653 bvalue = bvalue >= 127? bvalue - 126: bvalue > 255? 0: bvalue + 127;
657 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.
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::Interpolator::NearestNeighbor)
Reprojects a raster to another SRS.
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 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.
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.
virtual Raster * trim(const te::gm::Envelope *env, const std::map< std::string, std::string > &rinfo)
Subsetting operation for trimming (cropping) the 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.
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.