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);
348 for (std::size_t b = 0; b < getNumberOfBands(); b++)
349 this->
operator[](b) -= rhs.operator[](b);
358 for (std::size_t b = 0; b < getNumberOfBands(); b++)
359 this->
operator[](b) *= rhs.operator[](b);
368 for (std::size_t b = 0; b < getNumberOfBands(); b++)
369 this->
operator[](b) /= rhs.operator[](b);
402 const unsigned height =
static_cast<unsigned>(std::fabs(cllenv.
y - curenv.
y)) + 1;
404 const unsigned width =
static_cast<unsigned>(std::fabs(cllenv.
x - curenv.
x)) + 1;
406 const unsigned dxoff =
static_cast<unsigned>(std::fabs(cllenv.
x - cllimg.
x));
408 const unsigned dyoff =
static_cast<unsigned>(curenv.
y);
419 std::vector<te::rst::BandProperty*> bands;
421 for (std::size_t b = 0; b < getNumberOfBands(); b++)
427 std::vector<std::complex<double> > values;
429 for (
unsigned ri = dyoff, ro = 0; ro < height; ri++, ro++)
430 for (
unsigned ci = dxoff, co = 0; co < width; ci++, co++)
432 getValues(ci, ri, values);
447 std::vector<te::rst::BandProperty*> bands;
449 for (std::size_t b = 0; b < getNumberOfBands(); b++)
455 std::vector<std::complex<double> > v;
457 double ripp = applyScale(scale, 1.0);
459 double cipp = applyScale(scale, 1.0);
482 te::rst::Raster*
te::rst::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)
484 assert(drow + height <= getNumberOfRows());
485 assert(dcolumn + width <= getNumberOfColumns());
495 std::vector<te::rst::BandProperty*> bands;
497 for (std::size_t b = 0; b < getNumberOfBands(); b++)
503 std::vector<std::complex<double> > v;
508 double ripp = (double) height / newheight;
510 double cipp = (double) width / newwidth;
516 for (
unsigned r = 0; r < newheight; r++, ri+=ripp)
519 for (
unsigned c = 0; c < newwidth; c++, ci+=cipp)
536 return new te::rst::Grid((
unsigned) std::ceil(applyScale(-scale, getNumberOfColumns())),
537 (
unsigned) std::ceil(applyScale(-scale, getNumberOfRows())),
538 applyScale(scale, getResolutionX()), applyScale(scale, getResolutionY()),
552 return this->transform(srid, 1, 1, -1, -1, 0, 0, rinfo, m);
557 return this->transform(srid, llx, lly, urx, ury, 0, 0, rinfo, m);
567 assert(b < getNumberOfBands());
575 for (
unsigned int i = 0; i < g.size(); i++)
577 vp.push_back(bvalue % 255);
579 bvalue = bvalue >= 127? bvalue - 126: bvalue > 255? 0: bvalue + 127;
583 for (
unsigned int i = 0; i < g.size(); i++)
const std::string & getName() const
Returns the raster name.
It gives access to values in one band (dimension) of a raster.
virtual Raster & operator*=(Raster &rhs)
It returns the raster product (pixel by pixel).
virtual ~Raster()
Virtual destructor.
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.
std::string toString(void) const
It returns the data value in a string notation.
unsigned int getNumberOfRows() const
Returns the raster number of rows.
Polygon is a subclass of CurvePolygon whose rings are defined by linear rings.
Grid * getResampledGrid(int scale)
Return the raster grid for a specific scale.
double getResolutionX() const
Returns the raster horizontal (x-axis) resolution.
unsigned int getRow() const
Returns the current row in iterator.
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.
It describes one band (or dimension) of a raster.
const double & getLowerLeftY() const
It returns a constant refernce to the y coordinate of the lower left corner.
Grid * getGrid()
It returns the raster grid.
std::string m_name
The raster name.
void setNumberOfColumns(unsigned int nCols)
Sets the grid number of columns.
static Raster * make()
It creates and returns an empty raster with default raster driver.
Grid * m_grid
The spatial support for raster data.
virtual std::size_t getNumberOfBands() const =0
Returns the number of bands (dimension of cells attribute values) in the raster.
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 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 rectified grid is the spatial support for raster data.
It interpolates one pixel based on a selected algorithm. Methods currently available are Nearest Neig...
void setGeoreference(const te::gm::Coord2D &ulLocation, int srid, double resX, double resY)
Sets the information needed to georeference the grid.
An utility struct for representing 2D coordinates.
const double & getLowerLeftX() const
It returns a constant reference to the x coordinate of the lower left corner.
AccessPolicy
Supported data access policies (can be used as bitfield).
static PolygonIterator begin(const te::rst::Raster *r, const te::gm::Polygon *p)
Returns an iterator referring to the first value of the band.
An exception class for the Raster module.
te::gm::Envelope * getExtent()
Returns the geographic extension of the raster data.
A raster band description.
A rectified grid is the spatial support for raster data.
virtual Raster & operator+=(Raster &rhs)
It returns the raster sum (pixel by pixel).
int getSRID() const
Returns the raster spatial reference system identifier.
virtual Raster * getRaster() const =0
Returns the associated raster.
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.
double applyScale(int i, const double &v)
Scales a value according to a specific resampling scale.
It contains the algorithm to reproject raster data.
This class implements the strategy to iterate with spatial restriction, the iteration occurs inside a...
virtual Raster & operator-=(Raster &rhs)
It returns the raster subtraction (pixel by pixel).
unsigned int getColumn() const
Returns the current column in iterator.
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.
virtual Raster & operator=(const Raster &rhs)
Assignment operator.
unsigned int getNumberOfColumns() const
Returns the raster number of columns.
A raster band description.
This is the abstract factory for Rasters.
virtual Raster * trim(const te::gm::Envelope *env, const std::map< std::string, std::string > &rinfo)
Subsetting operation for trimming (cropping) the raster.
A Converter is responsible for the conversion of coordinates between different Coordinate Systems (CS...
void getValues(const double &c, const double &r, std::vector< std::complex< double > > &values)
Get the interpolated value for all bands.
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.
const double & getUpperRightX() const
It returns a constant refernce to the x coordinate of the upper right corner.
It interpolates one pixel based on a selected algorithm.
An abstract class for raster data strucutures.
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)
Resample a subset of the raster, given a box.
double getResolutionY() const
Returns the raster vertical (y-axis) resolution.
static PolygonIterator end(const te::rst::Raster *r, const te::gm::Polygon *p)
Returns an iterator referring to after the end of the iterator.
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.
An Envelope defines a 2D rectangular region.
Raster()
Default constructor.
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.
virtual Raster & operator/=(Raster &rhs)
It returns the raster division (pixel by pixel).
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...
An abstract class for raster data strucutures.
void setNumberOfRows(unsigned int nRows)
Sets the grid number of rows.
void setName(const std::string name)
Sets the raster name.
te::common::AccessPolicy getAccessPolicy() const
Returns the raster access policy.