src/terralib/raster/Raster.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2008 National Institute For Space Research (INPE) - Brazil.
2 
3  This file is part of the TerraLib - a Framework for building GIS enabled applications.
4 
5  TerraLib is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published by
7  the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  TerraLib is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with TerraLib. See COPYING. If not, write to
17  TerraLib Team at <terralib-team@terralib.org>.
18  */
19 
20 /*!
21  \file terralib/raster/Raster.cpp
22 
23  \brief An abstract class for raster data strucutures.
24 */
25 
26 // TerraLib
27 #include "Utils.h"
28 #include "../common/progress/TaskProgress.h"
29 #include "../common/STLUtils.h"
30 #include "../geometry/Coord2D.h"
31 #include "../geometry/Envelope.h"
32 #include "../geometry/Polygon.h"
33 #include "../srs/Converter.h"
34 #include "Band.h"
35 #include "BandProperty.h"
36 #include "Exception.h"
37 #include "Grid.h"
38 #include "Interpolator.h"
39 #include "PositionIterator.h"
40 #include "Raster.h"
41 #include "RasterFactory.h"
42 #include "RasterProperty.h"
43 #include "Reprojection.h"
44 
45 // STL
46 #include <cassert>
47 #include <cmath>
48 #include <limits>
49 #include <memory>
50 
52  : m_grid(nullptr),
53  m_policy(te::common::RAccess)
54 {
55 }
56 
58  : m_grid(grid),
59  m_policy(p)
60 {
61 }
62 
64  : m_name(rhs.m_name),
65  m_grid(nullptr),
66  m_policy(rhs.m_policy)
67 {
68  m_grid = rhs.m_grid ? new Grid(*rhs.m_grid) : nullptr;
69 }
70 
72 {
73  delete m_grid;
74 }
75 
76 void te::rst::Raster::setName(const std::string name)
77 {
78  m_name = name;
79 }
80 
81 const std::string& te::rst::Raster::getName() const
82 {
83  return m_name;
84 }
85 
87 {
88  m_policy = p;
89 }
90 
92 {
93  return m_policy;
94 }
95 
97 {
98  return m_grid;
99 }
100 
102 {
103  return m_grid;
104 }
105 
107 {
108  return m_grid->getExtent();
109 }
110 
112 {
113  return m_grid->getExtent();
114 }
115 
117 {
118  if (srid==getSRID())
119  return new te::gm::Envelope(*getExtent());
120 
121  std::unique_ptr<te::srs::Converter> converter(new te::srs::Converter());
122  converter->setSourceSRID(getSRID());
123  converter->setTargetSRID(srid);
124 
125  unsigned int li=0, lf=getNumberOfRows()-1;
126  unsigned int ci=0, cf=getNumberOfColumns()-1;
127 
128  te::gm::Coord2D aux;
129  if (roi)
130  {
131  aux=m_grid->geoToGrid(roi->getLowerLeftX(),roi->getLowerLeftY());
132  li=static_cast<unsigned int>(aux.y);
133  ci=static_cast<unsigned int>(aux.x);
134 
135  aux=m_grid->geoToGrid(roi->getUpperRightX(),roi->getUpperRightY());
136  lf=static_cast<unsigned int>(aux.y);
137  cf=static_cast<unsigned int>(aux.x);
138  }
139 
140  aux=m_grid->gridToGeo(ci,lf);
141  converter->convert(aux.x,aux.y);
142  double llx=aux.x,
143  lly=aux.y;
144 
145  aux=m_grid->gridToGeo(cf,li);
146  converter->convert(aux.x,aux.y);
147  double urx=aux.x,
148  ury=aux.y;
149 
150  // follow the upper horizontal edge
151  for (unsigned int c=ci; c<cf; ++c)
152  {
153  aux=m_grid->gridToGeo(c,li);
154  if (converter->convert(aux.x,aux.y))
155  {
156  if(llx > aux.x) llx = aux.x;
157  if(lly > aux.y) lly = aux.y;
158  if(urx < aux.x) urx = aux.x;
159  if(ury < aux.y) ury = aux.y;
160  }
161  }
162 
163  // follow the lower horizontal edge
164  for (unsigned int c=ci; c<cf; ++c)
165  {
166  aux=m_grid->gridToGeo(c,lf);
167  if (converter->convert(aux.x,aux.y))
168  {
169  if(llx > aux.x) llx = aux.x;
170  if(lly > aux.y) lly = aux.y;
171  if(urx < aux.x) urx = aux.x;
172  if(ury < aux.y) ury = aux.y;
173  }
174  }
175 
176  // follow the left vertical edge
177  for (unsigned int l=li; l<lf; ++l)
178  {
179  aux=m_grid->gridToGeo(ci,l);
180  if (converter->convert(aux.x,aux.y))
181  {
182  if(llx > aux.x) llx = aux.x;
183  if(lly > aux.y) lly = aux.y;
184  if(urx < aux.x) urx = aux.x;
185  if(ury < aux.y) ury = aux.y;
186  }
187  }
188 
189  // follow the right vertical edge
190  for (unsigned int l=li; l<lf; ++l)
191  {
192  aux=m_grid->gridToGeo(cf,l);
193  if (converter->convert(aux.x,aux.y))
194  {
195  if(llx > aux.x) llx = aux.x;
196  if(lly > aux.y) lly = aux.y;
197  if(urx < aux.x) urx = aux.x;
198  if(ury < aux.y) ury = aux.y;
199  }
200  }
201 
202  return new te::gm::Envelope(llx,lly,urx,ury);
203 }
204 
206 {
207  return m_grid->getSRID();
208 }
209 
211 {
212  return m_grid->getNumberOfRows();
213 }
214 
216 {
217  return m_grid->getNumberOfColumns();
218 }
219 
221 {
222  return m_grid->getResolutionX();
223 }
224 
226 {
227  return m_grid->getResolutionY();
228 }
229 
230 void te::rst::Raster::getValue(unsigned int c, unsigned int r, double& value, std::size_t b) const
231 {
232  getBand(b)->getValue(c, r, value);
233 }
234 
235 void te::rst::Raster::setValue(unsigned int c, unsigned int r, const double value, std::size_t b)
236 {
237  getBand(b)->setValue(c, r, value);
238 }
239 
240 void te::rst::Raster::getIValue(unsigned int c, unsigned int r, double& value, std::size_t b) const
241 {
242  getBand(b)->getIValue(c, r, value);
243 }
244 
245 void te::rst::Raster::setIValue(unsigned int c, unsigned int r, const double value, std::size_t b)
246 {
247  getBand(b)->setIValue(c, r, value);
248 }
249 
250 void te::rst::Raster::getValue(unsigned int c, unsigned int r, std::complex<double>& value, std::size_t b) const
251 {
252  getBand(b)->getValue(c, r, value);
253 }
254 
255 void te::rst::Raster::setValue(unsigned int c, unsigned int r, const std::complex<double>& value, std::size_t b)
256 {
257  getBand(b)->setValue(c, r, value);
258 }
259 
260 void te::rst::Raster::getValues(unsigned int c, unsigned int r, std::vector<double>& values) const
261 {
262  values.clear();
263 
264  double v;
265 
266  for(std::size_t b = 0; b < getNumberOfBands(); b++)
267  {
268  getBand(b)->getValue(c, r, v);
269 
270  values.push_back(v);
271  }
272 }
273 
274 void te::rst::Raster::getValues(unsigned int c, unsigned int r, std::vector<std::complex<double> >& values) const
275 {
276  values.clear();
277 
278  std::complex<double> v;
279 
280  for(std::size_t b = 0; b < getNumberOfBands(); b++)
281  {
282  getBand(b)->getValue(c, r, v);
283 
284  values.push_back(v);
285  }
286 }
287 
288 void te::rst::Raster::setValues(unsigned int c, unsigned int r, const std::vector<double>& values)
289 {
290  assert(values.size() == getNumberOfBands());
291 
292  for(std::size_t b = 0; b < getNumberOfBands(); b++)
293  getBand(b)->setValue(c, r, values[b]);
294 }
295 
296 void te::rst::Raster::setValues(unsigned int c, unsigned int r, const std::vector<std::complex<double> >& values)
297 {
298  assert(values.size() == getNumberOfBands());
299 
300  for(std::size_t b = 0; b < getNumberOfBands(); b++)
301  getBand(b)->setValue(c, r, values[b]);
302 }
303 
304 std::string te::rst::Raster::toString(void) const
305 {
306  std::ostringstream output;
307 
308  output << std::endl;
309  output << "Raster Name......: " << m_name << std::endl;
310  output << "Number of Columns: " << getNumberOfColumns() << std::endl;
311  output << "Number of Rows...: " << getNumberOfRows() << std::endl;
312  output << "Number of Bands..: " << getNumberOfBands() << std::endl;
313  output << "SRID.............: " << getSRID() << std::endl;
314  output << "Resolution in X..: " << getResolutionX() << std::endl;
315  output << "Resolution in Y..: " << getResolutionY() << std::endl;
316  output << "Extent UR........: " << m_grid->getExtent()->getUpperRightX() << ", " << m_grid->getExtent()->getUpperRightY() << std::endl;
317  output << "Extent LL........: " << m_grid->getExtent()->getLowerLeftX() << ", " << m_grid->getExtent()->getLowerLeftY() << std::endl;
318 
319  for (std::size_t b = 0; b < getNumberOfBands(); b++)
320  {
321  output << std::endl;
322  output << "Band: " << b << " " << getBand(b)->getProperty()->m_description << std::endl;
323  output << " Min Values...: " << getBand(b)->getMinValue() << std::endl;
324  output << " Max Values...: " << getBand(b)->getMaxValue() << std::endl;
325  output << " Mean Values..: " << getBand(b)->getMeanValue() << std::endl;
326  output << " Std Values...: " << getBand(b)->getStdValue() << std::endl;
327  output << " Gain values..: " << getBand(b)->getScaleValue() << std::endl;
328  output << " Offset values: " << getBand(b)->getOffsetValue() << std::endl;
329  }
330 
331  output << std::endl;
332 
333  return output.str();
334 }
335 
337 {
338  assert(getNumberOfBands() == rhs.getNumberOfBands());
339 
340  for (std::size_t b = 0; b < getNumberOfBands(); b++)
341  this->operator[](b) += rhs.operator[](b);
342 
343  return *this;
344 }
345 
346 te::rst::Raster& te::rst::Raster::operator+=(std::complex<double>& cvalue)
347 {
348  for (std::size_t b = 0; b < getNumberOfBands(); b++)
349  this->operator[](b) += cvalue;
350 
351  return *this;
352 }
353 
355 {
356  assert(getNumberOfBands() == rhs.getNumberOfBands());
357 
358  for (std::size_t b = 0; b < getNumberOfBands(); b++)
359  this->operator[](b) -= rhs.operator[](b);
360 
361  return *this;
362 }
363 
364 te::rst::Raster& te::rst::Raster::operator-=(std::complex<double>& cvalue)
365 {
366  for (std::size_t b = 0; b < getNumberOfBands(); b++)
367  this->operator[](b) -= cvalue;
368 
369  return *this;
370 }
371 
373 {
374  assert(getNumberOfBands() == rhs.getNumberOfBands());
375 
376  for (std::size_t b = 0; b < getNumberOfBands(); b++)
377  this->operator[](b) *= rhs.operator[](b);
378 
379  return *this;
380 }
381 
382 te::rst::Raster& te::rst::Raster::operator*=(std::complex<double>& cvalue)
383 {
384  for (std::size_t b = 0; b < getNumberOfBands(); b++)
385  this->operator[](b) *= cvalue;
386 
387  return *this;
388 }
389 
391 {
392  assert(getNumberOfBands() == rhs.getNumberOfBands());
393 
394  for (std::size_t b = 0; b < getNumberOfBands(); b++)
395  this->operator[](b) /= rhs.operator[](b);
396 
397  return *this;
398 }
399 
400 te::rst::Raster& te::rst::Raster::operator/=(std::complex<double>& cvalue)
401 {
402  for (std::size_t b = 0; b < getNumberOfBands(); b++)
403  this->operator[](b) /= cvalue;
404 
405  return *this;
406 }
407 
409 {
411 
412  if(this != &rhs)
413  {
414  m_name = rhs.m_name;
415 
416  delete m_grid;
417 
418  m_grid = rhs.m_grid ? new Grid(*rhs.m_grid) : nullptr;
419  }
420 
421  return *this;
422 }
423 
424 te::rst::Raster* te::rst::Raster::trim(const te::gm::Envelope* env, const std::map<std::string, std::string>& rinfo) const
425 {
426 // calculate output properties
427 
430 
431  const unsigned int firstInputRow = (unsigned int)
432  std::min(
433  (double)( m_grid->getNumberOfRows() - 1 )
434  ,
435  std::max(
436  0.0
437  ,
438  std::floor( curenv.getY() )
439  )
440  );
441  const unsigned int firstInputCol = (unsigned int)
442  std::min(
443  (double)( m_grid->getNumberOfColumns() - 1 )
444  ,
445  std::max(
446  0.0
447  ,
448  std::floor( cllenv.getX() )
449  )
450  );
451  const unsigned int lastInputRow = (unsigned int)
452  std::min(
453  (double)( m_grid->getNumberOfRows() - 1 )
454  ,
455  std::max(
456  0.0
457  ,
458  std::ceil( cllenv.getY() )
459  )
460  );
461  const unsigned int lastInputCol = (unsigned int)
462  std::min(
463  (double)( m_grid->getNumberOfColumns() - 1 )
464  ,
465  std::max(
466  0.0
467  ,
468  std::ceil( curenv.getX() )
469  )
470  );
471 
472  if( ( lastInputRow <= firstInputRow ) || ( lastInputCol <= firstInputCol ) )
473  {
474  return nullptr;
475  }
476 
477  const unsigned int outputWidth = lastInputCol - firstInputCol + 1;
478  const unsigned int outputHeight = lastInputRow - firstInputRow + 1;
479 
480 // create output parameters and raster
481 
482  te::gm::Coord2D ulc( m_grid->gridToGeo( ((double)firstInputCol) - 0.5,
483  ((double)firstInputRow) - 0.5 ) );
484 
485  te::rst::Grid* grid = new te::rst::Grid( outputWidth, outputHeight, getResolutionX(),
486  getResolutionY(), &ulc, getSRID() );
487 
488  std::vector<te::rst::BandProperty*> bands;
489 
490  for (std::size_t b = 0; b < getNumberOfBands(); b++)
491  {
492  bands.push_back(new te::rst::BandProperty(*(getBand(b)->getProperty())));
493  bands[ b ]->m_nblocksx = 1;
494  bands[ b ]->m_nblocksy = outputHeight;
495  bands[ b ]->m_blkw = outputWidth;
496  bands[ b ]->m_blkh = 1;
497  }
498 
499  te::rst::Raster* rout = te::rst::RasterFactory::make(grid, bands, rinfo);
500 
501 // perform trim
502 
503  if( rout )
504  {
505  std::vector<std::complex<double> > values;
506  unsigned int ci = 0;
507  unsigned int ri = 0;
508  unsigned int co = 0;
509  unsigned int ro = 0;
510 
511  for( ri = firstInputRow, ro = 0; ro < outputHeight; ri++, ro++)
512  {
513  for( ci = firstInputCol, co = 0; co < outputWidth; ci++, co++)
514  {
515  getValues(ci, ri, values);
516 
517  rout->setValues(co, ro, values);
518  }
519  }
520  }
521 
522  return rout;
523 }
524 
526  const std::vector< te::gm::Geometry const *> geometries,
527  const std::map<std::string, std::string>& rinfo,
528  const std::string& rType ) const
529 {
530  return te::rst::CropRaster( *this, geometries, rinfo, rType ).release();
531 }
532 
533 te::rst::Raster* te::rst::Raster::resample(int method, int scale, const std::map<std::string, std::string>& rinfo) const
534 {
535  assert(scale != 0);
536 
537 // create output parameters and raster
538  te::rst::Grid* grid = new te::rst::Grid(*getResampledGrid(scale));
539 
540  std::vector<te::rst::BandProperty*> bands;
541 
542  for (std::size_t b = 0; b < getNumberOfBands(); b++)
543  bands.push_back(new te::rst::BandProperty(*(getBand(b)->getProperty())));
544 
545  te::rst::Raster* rout = te::rst::RasterFactory::make(grid, bands, rinfo);
546 
547 // define variables for interpolation
548  std::vector<std::complex<double> > v;
549 
550  double ripp = applyScale(scale, 1.0);
551 
552  double cipp = applyScale(scale, 1.0);
553 
554  double ri = 0.0;
555 
556  double ci;
557 
558  te::rst::Interpolator* interp = new te::rst::Interpolator(this, method);
559 
560 // fill output raster
561  for (unsigned r = 0; r < rout->getNumberOfRows(); r++, ri+=ripp)
562  {
563  ci = 0.0;
564  for (unsigned c = 0; c < rout->getNumberOfColumns(); c++, ci+=cipp)
565  {
566  interp->getValues(ci, ri, v);
567 
568  rout->setValues(c, r, v);
569  }
570  }
571 
572  return rout;
573 }
574 
575 te::rst::Raster* te::rst::Raster::resample(int method, unsigned int drow,
576  unsigned int dcolumn, unsigned int height, unsigned int width,
577  unsigned int newheight, unsigned int newwidth,
578  const std::map<std::string, std::string>& rinfo) const
579 {
580  assert(drow + height <= getNumberOfRows());
581  assert(dcolumn + width <= getNumberOfColumns());
582 
583  te::gm::Coord2D ulc = getGrid()->gridToGeo( ((double)dcolumn) - 0.5, ((double)drow) - 0.5);
584  te::gm::Coord2D lrc = getGrid()->gridToGeo( ((double)(dcolumn + width)) - 0.5,
585  ((double)(drow + height)) - 0.5);
586 
587  te::gm::Envelope* newEnvelopePtr = new te::gm::Envelope( ulc.x, lrc.y, lrc.x,
588  ulc.y );
589 
590  // create output parameters and raster
591 
592  te::rst::Grid* grid = new te::rst::Grid(newwidth, newheight, newEnvelopePtr,
593  getSRID());
594 
595  std::vector<te::rst::BandProperty*> bands;
596 
597  for (std::size_t b = 0; b < getNumberOfBands(); b++)
598  {
599  bands.push_back(new te::rst::BandProperty(*(getBand(b)->getProperty())));
600  bands[ b ]->m_blkh = 1;
601  bands[ b ]->m_blkw = newwidth;
602  bands[ b ]->m_nblocksx = 1;
603  bands[ b ]->m_nblocksy = newheight;
604  }
605 
606  te::rst::Raster* rout = te::rst::RasterFactory::make(grid, bands, rinfo);
607 
608 // define variables for interpolation
609  std::vector<std::complex<double> > v;
610 
611  te::rst::Interpolator* interp = new te::rst::Interpolator(this, method);
612 
613 // fill output raster
614  double ripp = ((double)(height-1)) / ((double)(newheight-1));
615 
616  double cipp = ((double)(width-1)) / ((double)(newwidth-1));
617 
618  double ri = drow;
619 
620  double ci;
621 
622  for (unsigned r = 0; r < newheight; r++, ri+=ripp)
623  {
624  ci = dcolumn;
625  for (unsigned c = 0; c < newwidth; c++, ci+=cipp)
626  {
627  interp->getValues(ci, ri, v);
628 
629  rout->setValues(c, r, v);
630  }
631  }
632 
633  return rout;
634 }
635 
637 {
638  assert(scale != 0);
639 
640  te::gm::Coord2D* ulc = new te::gm::Coord2D(getExtent()->getLowerLeftX(), getExtent()->getUpperRightY());
641 
642  return new te::rst::Grid((unsigned) std::ceil(applyScale(-scale, getNumberOfColumns())),
643  (unsigned) std::ceil(applyScale(-scale, getNumberOfRows())),
644  applyScale(scale, getResolutionX()), applyScale(scale, getResolutionY()),
645  ulc, getSRID());
646 }
647 
648 double te::rst::Raster::applyScale(int i, const double& v) const
649 {
650  if (i > 0)
651  return (v / i);
652 
653  return (v * -i);
654 }
655 
656 te::rst::Raster* te::rst::Raster::transform(int srid, const std::map<std::string, std::string>& rinfo, int m) const
657 {
658  te::gm::Envelope transformedEnvelope( *getExtent() );
659  transformedEnvelope.transform( getSRID(), srid );
660 
661  double transformedResolutionX = transformedEnvelope.getWidth() /
662  ((double)getNumberOfColumns());
663  double transformedResolutionY = transformedEnvelope.getHeight() /
664  ((double)getNumberOfRows());
665 
666  return te::rst::Reproject(
667  this,
668  srid,
669  getExtent()->getLowerLeftX(),
670  getExtent()->getLowerLeftY(),
671  getExtent()->getUpperRightX(),
672  getExtent()->getUpperRightY(),
673  transformedResolutionX,
674  transformedResolutionY,
675  rinfo,
676  m);
677 }
678 
679 te::rst::Raster* te::rst::Raster::transform(int srid, double llx, double lly, double urx, double ury, const std::map<std::string, std::string>& rinfo, int m) const
680 {
681  return te::rst::Reproject(this, srid, llx, lly, urx, ury, 0, 0, rinfo, m);
682 }
683 
684 te::rst::Raster* te::rst::Raster::transform(int srid, double llx, double lly, double urx, double ury, double resx, double resy, const std::map<std::string, std::string>& rinfo, int m) const
685 {
686  return te::rst::Reproject(this, srid, llx, lly, urx, ury, resx, resy, rinfo, m);
687 }
688 
689 void te::rst::Raster::vectorize(std::vector<te::gm::Geometry*>& g, std::size_t b, unsigned int mp, std::vector< double > * const polygonsValues)
690 {
691  g.clear();
692 
693  te::rst::Vectorizer vectorizer(this, b, mp );
694 
695  vectorizer.run(g, polygonsValues);
696 }
697 
698 void te::rst::Raster::rasterize(std::vector<te::gm::Geometry*> g, std::vector<double> vp, std::size_t b)
699 {
700  assert(b < getNumberOfBands());
701 
702  te::rst::Band* band = getBand(b);
703 
704 // if vp is empty, create a vector of contrastand pixel values for neighboring polygons
705  if (vp.size() == 0)
706  {
707  int bvalue = 254;
708  for (unsigned int i = 0; i < g.size(); i++)
709  {
710  vp.push_back(bvalue % 255);
711 
712  bvalue = bvalue >= 127? bvalue - 126: bvalue > 255? 0: bvalue + 127;
713  }
714  }
715 
717  task.setTotalSteps(static_cast<int>(g.size()));
718  task.setMessage(TE_TR("Rasterizing..."));
719 
720  for (unsigned int i = 0; i < g.size(); i++)
721  {
722  std::vector<te::gm::Geometry*> geoms;
723 
724  te::gm::Multi2Single(g[i], geoms);
725 
726  for (std::size_t j = 0; j < geoms.size(); ++j)
727  {
728  te::gm::Polygon* polygon = static_cast<te::gm::Polygon*> (geoms[j]);
729 
732 
733  while (it != itend)
734  {
735  setValue(it.getColumn(), it.getRow(), vp[i], b);
736 
737  ++it;
738  }
739  }
740 
741 
742 
743  if (!task.isActive())
744  throw te::common::Exception(TE_TR("Rasterize operation canceled!"));
745 
746  task.pulse();
747  }
748 }
virtual void setIValue(unsigned int c, unsigned int r, const double value)=0
Sets the imaginary attribute value in a complex band of a cell.
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.
unsigned int getNumberOfRows() const
Returns the grid number of rows.
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.
unsigned int band
virtual void vectorize(std::vector< te::gm::Geometry * > &g, std::size_t b, unsigned int mp=0, std::vector< double > *const polygonsValues=0)
Vectorizes a given raster band, using GDALPolygonize function.
It gives access to values in one band (dimension) of a raster.
void setMessage(const std::string &message)
Set the task message.
double y
y-coordinate.
Definition: Coord2D.h:114
It describes one band (or dimension) of a raster.
std::complex< double > getOffsetValue() const
It returns the offset values (real and imaginary) to be applied to the band.
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.
Definition: BandProperty.h:61
double x
x-coordinate.
Definition: Coord2D.h:113
virtual Raster & operator/=(Raster &rhs)
It returns the raster division (pixel by pixel).
int getSRID() const
Returns the grid spatial reference system identifier.
Raster property.
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...
Definition: Interpolator.h:55
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...
This class can be used to inform the progress of a task.
Definition: TaskProgress.h:53
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.
An abstract class for raster data strucutures.
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.
Definition: Coord2D.h:40
double getY() const
It returns the y-coordinate.
Definition: Coord2D.h:108
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.
#define TE_TR(message)
It marks a string in order to get translated.
Definition: Translator.h:242
void setAccessPolicy(te::common::AccessPolicy p)
Sets the raster access policy.
TEGEOMEXPORT void Multi2Single(const te::gm::Geometry *g, std::vector< te::gm::Geometry * > &geoms)
It will get a GeometryCollection and distribute in a vector.
bool isActive() const
Verify if the task is active.
void geoToGrid(const double &x, const double &y, double &col, double &row) const
Get the grid point associated to a spatial location.
virtual void getIValue(unsigned int c, unsigned int r, double &value) const =0
Returns the imaginary attribute value in a complex band of a cell.
double getResolutionY() const
Returns the grid vertical (y-axis) resolution.
void setTotalSteps(int value)
Set the task total stepes.
te::common::AccessPolicy getAccessPolicy() const
Returns the raster access policy.
std::string m_name
The raster name.
Utility functions for the raster module.
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).
int b
Definition: TsRtree.cpp:32
This is the abstract factory for Rasters.
Raster()
Default constructor.
static PolygonIterator end(const te::rst::Raster *r, const te::gm::Polygon *p)
Returns an iterator referring to after the end of the iterator.
virtual std::complex< double > getMaxValue(bool readall=false, unsigned int rs=0, unsigned int cs=0, unsigned int rf=0, unsigned int cf=0) const
It computes and returns the maximum occurring value in a window of the band.
virtual std::complex< double > getStdValue(unsigned int rs=0, unsigned int cs=0, unsigned int rf=0, unsigned int cf=0) const
It computes and returns the standard deviation of the occurring values in a window of the band...
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.
virtual ~Raster()
Virtual destructor.
BandProperty * getProperty()
Returns the band property.
URI C++ Library.
Definition: Attributes.h:37
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 Raster & operator-=(Raster &rhs)
It returns the raster subtraction (pixel by pixel).
unsigned int getNumberOfColumns() const
Returns the grid number of columns.
double getResolutionX() const
Returns the raster horizontal (x-axis) resolution.
double getResolutionX() const
Returns the grid horizontal (x-axis) resolution.
list bands
Definition: compose.py:2
void setName(const std::string name)
Sets the raster name.
It implements the vectorizer, based on TerraLib 4 algorithm.
Definition: Vectorizer.h:64
te::gm::Polygon * p
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
A raster band description.
virtual const Band * getBand(std::size_t i) const =0
Returns the raster i-th band.
std::complex< double > getScaleValue() const
It returns the scale values (real and imaginary) to be applied to the band.
Grid * getGrid()
It returns the raster grid.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
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.
static PolygonIterator begin(const te::rst::Raster *r, const te::gm::Polygon *p, const IterationType iterationType)
Returns an iterator referring to the first value of the band.
virtual void setValue(unsigned int c, unsigned int r, const double value)=0
Sets the cell attribute value.
A Converter is responsible for the conversion of coordinates between different Coordinate Systems (CS...
Definition: Converter.h:53
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.
Definition: Polygon.h:50
double getX() const
It returns the x-coordinate.
Definition: Coord2D.h:102
A rectified grid is the spatial support for 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::NearestNeighbor)
Reprojects a raster to another SRS.
virtual std::complex< double > getMinValue(bool readall=false, unsigned int rs=0, unsigned int cs=0, unsigned int rf=0, unsigned int cf=0) const
It computes and returns the minimum occurring value in a window 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.
virtual std::complex< double > getMeanValue(unsigned int rs=0, unsigned int cs=0, unsigned int rf=0, unsigned int cf=0) const
It computes and returns the mean of the occurring values in a window of the band. ...
te::gm::Envelope * getExtent()
Returns the geographic extension of the grid.
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.
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.
virtual Raster * clip(const std::vector< te::gm::Geometry const * > geometries, const std::map< std::string, std::string > &rinfo, const std::string &rType) const
Subsetting operation for clipping the raster.
bool run(std::vector< te::gm::Geometry * > &polygons, std::vector< double > *const polygonsValues=0)
Returns true if current algorithm implementation runs ok, false otherwise.
Definition: Vectorizer.cpp:117
std::string m_description
A description.
Definition: BandProperty.h:134
unsigned int getColumn() const
Returns the current column in iterator.
A rectified grid is the spatial support for raster data.
Definition: raster/Grid.h:68
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.
te::common::AccessPolicy m_policy
The access policy, can be te::common::{NoAccess, RAccess, RWAccess, WAccess}.
virtual Raster & operator+=(Raster &rhs)
It returns the raster sum (pixel by pixel).
It interpolates one pixel based on a selected algorithm.
virtual void getValue(unsigned int c, unsigned int r, double &value) const =0
Returns the cell attribute value.