11 #include "../../common/progress/TaskProgress.h" 12 #include "../../raster.h" 13 #include "../../raster/BandProperty.h" 14 #include "../../raster/Grid.h" 15 #include "../../raster/RasterFactory.h" 37 m_min = std::numeric_limits<double>::max();
38 m_max = std::numeric_limits<double>::min();
41 std::unique_ptr<te::rst::Raster>
te::mnt::CalculateGrid::Initialize(
bool spline,
unsigned int &nro_neighb,
double &rx1,
double &ry2,
unsigned int &outputWidth,
unsigned int &outputHeight)
73 std::vector<te::rst::BandProperty*>
bands;
76 bands[0]->m_nblocksx = 1;
77 bands[0]->m_nblocksy = (
int)outputHeight;
78 bands[0]->m_blkw = (
int)outputWidth;
87 std::vector<std::pair<te::gm::Coord2D, te::gm::Point> > dataset1;
98 m_dataset.push_back(std::pair<te::gm::Coord2D, te::gm::Point>(co, pz));
99 dataset1.push_back(std::pair<te::gm::Coord2D, te::gm::Point>(co, pz));
109 nro_neighb = (
unsigned int)datasize;
121 unsigned int nro_neighb;
123 unsigned int outputWidth;
124 unsigned int outputHeight;
126 std::unique_ptr<te::rst::Raster>
rst =
Initialize(
false, nro_neighb, rx1, ry2, outputWidth, outputHeight);
128 std::vector<double> distneighb;
129 std::vector<te::gm::Point> points;
130 for (
unsigned int t = 0; t < nro_neighb; ++t)
133 pz.
setX(std::numeric_limits<double>::max());
134 pz.
setY(std::numeric_limits<double>::max());
135 pz.
setZ(std::numeric_limits<double>::max());
136 points.push_back(pz);
143 for (
unsigned int l = 0; l < outputHeight; l++)
145 for (
unsigned int c = 0; c < outputWidth; c++)
157 for (
size_t i = 0; i < points.size(); i++)
161 points[j] = points[i];
162 distneighb[j] = distneighb[i];
191 std::string inDsetName,
192 std::unique_ptr<te::da::DataSetType> inDsetType,
215 const std::string &atrz_pt,
247 double Wi, Wtotal = 0.;
249 if (distq[0] < 1.0e-5)
250 pg.
setZ(points[0].getZ());
261 Ztotal =
Interpwq(pg, points, distq);
266 for (
unsigned int i = 0; i<points.size(); i++){
267 Wi = 1. / pow(distq[i],
m_power / 2.);
268 Ztotal += (points[i].getZ()*Wi);
274 for (
unsigned int i = 0; i< points.size(); i++){
275 Ztotal += points[i].getZ();
281 Ztotal = points[0].getZ();
298 pg.
setZ(Ztotal / Wtotal);
308 double Wi, Wtotal = 0.0;
309 int q1 = 0, q2 = 0, q3 = 0, q4 = 0;
310 unsigned int npts = 0;
312 for (
unsigned int i = 0; i < points.size(); i++)
315 if ((q1<1) && (points[i].getX() > pg.
getX()) && (points[i].getY() > pg.
getY()))
318 if ((q2 < 1) && (points[i].getX() > pg.
getX()) && (points[i].getY()<pg.
getY()))
321 if ((q3 < 1) && (points[i].getX() < pg.
getX()) && (points[i].getY() < pg.
getY()))
324 if ((q4 < 1) && (points[i].getX() < pg.
getX()) && (points[i].getY() > pg.
getY()))
328 points[npts] = points[i];
332 for (
unsigned int i = 0; i<npts; i++)
334 Wi = 1. / pow(distq[i], (
double)
m_power / 2.);
335 Ztotal += (points[i].getZ()*Wi);
340 return(Ztotal / Wtotal);
348 double Wi, Wtotal = 0;
349 int q1 = 0, q2 = 0, q3 = 0, q4 = 0;
353 for (
unsigned int i = 0; i < points.size(); i++)
355 for (j = (
int)i - 1; j >= 0; j--)
356 if (points[(
unsigned int)j].getZ() == points[i].getZ())
360 if ((i == 0) || (j == -1))
363 if ((q1 < 1) && (points[i].getX() > pg.
getX()) && (points[i].getY() > pg.
getY()))
366 if ((q2 < 1) && (points[i].getX() > pg.
getX()) && (points[i].getY() < pg.
getY()))
369 if ((q3 < 1) && (points[i].getX() < pg.
getX()) && (points[i].getY() < pg.
getY()))
372 if ((q4 < 1) && (points[i].getX() < pg.
getX()) && (points[i].getY() > pg.
getY()))
379 Wi = 1. / pow(distq[i],
m_power / 2.);
380 Ztotal += (points[i].getZ()*Wi);
387 return(Ztotal / Wtotal);
void setInput(te::da::DataSourcePtr inDsrc, std::string inDsetName, std::unique_ptr< te::da::DataSetType > inDsetType, InputType type)
It sets the Datasource that is being used to generate TIN.
std::size_t getNumGeometries() const
It returns the number of geometries in this GeometryCollection.
double m_nodatavalue
no data value
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 m_inDsetName_point
CalculateGrid()
Default constructor.
bool run()
Calculate GRID \ return true or false.
Index into a lookup table.
std::unique_ptr< te::rst::Raster > Initialize(bool spline, unsigned int &nro_neighb, double &rx1, double &ry2, unsigned int &outputWidth, unsigned int &outputHeight)
boost::shared_ptr< DataSource > DataSourcePtr
A raster band description.
void setEnvelope(te::gm::Envelope &env)
This class can be used to inform the progress of a task.
te::da::DataSourcePtr m_inDsrc_sample
std::string m_atrZ_sample
Attribute used to calculate grid.
std::string m_inDsetName_sample
std::string m_atrZ_point
Attribute used to calculate grid.
double getWidth() const
It returns the envelope width.
int m_srid
Attribute with spatial reference information.
An utility struct for representing 2D coordinates.
double getY() const
It returns the y-coordinate.
double m_max
Output DTM limits.
const double & getUpperRightY() const
It returns a constant refernce to the x coordinate of the upper right corner.
bool GenerateGridSplineMitasova()
Method to calculate a grid from a vector of samples using a Spline (Mitasova) fitting algorithm...
Interpolator m_inter
selected interpolation method
void Union(const Envelope &rhs)
It updates the envelop with coordinates of another envelope.
std::unique_ptr< te::da::DataSetType > m_inDsetType_sample
KD_ADAPTATIVE_TREE * m_adaptativeTree
Utility functions for MNT support.
TEMNTEXPORT size_t ReadPoints(std::string &inDsetName, te::da::DataSourcePtr &inDsrc, std::string &atrZ, double tol, te::gm::MultiPoint &mpt, std::string &geostype, te::gm::Envelope &env)
MultiPoint is a GeometryCollection whose elements are restricted to points.
void setParams(const std::string &attriso, const std::string &attrpt, double resx, double resy, Interpolator gt, double rad, int pow)
It sets the parameters that is being used to save TIN.
bool GenerateGridSplineGrass()
Method to calculate a grid from a vector of samples using a Spline (GRASS) fitting algorithm...
const double & getY() const
It returns the Point y-coordinate value.
A point with x and y coordinate values.
An Envelope defines a 2D rectangular region.
double Interpwq(te::gm::Point &pg, std::vector< te::gm::Point > &points, std::vector< double > &distq)
Interpolates the z value of the pg point3d using an weighted average by quadrant. \ Implements the in...
void build(std::vector< std::pair< kdKey, kdDataItem > > &dataSet)
It inserts the data set into the tree.
te::sam::kdtree::AdaptativeIndex< KD_ADAPTATIVE_NODE > KD_ADAPTATIVE_TREE
te::da::DataSourcePtr m_inDsrc_point
void pulse()
Calls setCurrentStep() function using getCurrentStep() + 1.
te::gm::Envelope m_env
Attribute used to restrict the area to generate the raster.
void Interpolation(te::gm::Point &pg, std::vector< te::gm::Point > &points, std::vector< double > &distq)
Interpolates the z value of the pg point3d. \ This method interpolates the z value of the pg point3d ...
const double & getZ() const
It returns the Point z-coordinate value, if it has one or DoubleNotANumber otherwise.
This class is designed to declare objects to be thrown as exceptions by TerraLib. ...
std::unique_ptr< te::da::DataSetType > m_inDsetType_point
double Interpwqz(te::gm::Point &pg, std::vector< te::gm::Point > &points, std::vector< double > &distq)
Interpolates the z value of the pg point3d using an weighted average by quadrant and by z values...
TEMNTEXPORT size_t ReadSamples(std::string &inDsetName, te::da::DataSourcePtr &inDsrc, std::string &atrZ, double tol, double max, Simplify alg, te::gm::MultiPoint &mpt, te::gm::MultiLineString &isolines, std::string &geostype, te::gm::Envelope &env, int srid=0)
Geometry * getGeometryN(std::size_t i) const
It returns the n-th geometry in this GeometryCollection.
std::map< std::string, std::string > m_dsinfo
MultiLineString is a MultiCurve whose elements are LineStrings.
This file contains a class to calculate retangular grid from Samples. Adapted from SPRING...
double getX() const
It returns the x-coordinate.
std::vector< std::pair< te::gm::Coord2D, te::gm::Point > > m_dataset
void setX(const double &x)
It sets the Point x-coordinate value.
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.
void setOutput(std::map< std::string, std::string > &dsinfo)
It sets the Datasource that is being used to save TIN.
void setY(const double &y)
It sets the Point y-coordinate value.
A rectified grid is the spatial support for raster data.
double m_resy
grid resolution in X and Y
void nearestNeighborSearch(const kdKey &key, std::vector< kdDataItem > &report, std::vector< double > &sqrDists, const std::size_t &k) const
It searches the nearest data in nodes: you must pass an array of kdDataItem of size "k" with coordina...
double getHeight() const
It returns the envelope height.
const double & getX() const
It returns the Point x-coordinate value.
void setZ(const double &z)
It sets the Point z-coordinate value.
double m_tolerance
tolerance used to simplify lines