38 Q_INVOKABLE
ScriptGrid(QObject *parent =
nullptr);
48 QString
name()
const {
return mVariableName;}
51 int width()
const {
return mGrid?mGrid->sizeX():-1; }
52 int height()
const {
return mGrid?mGrid->sizeY():-1; }
53 int count()
const {
return mGrid?mGrid->count():-1; }
54 int cellsize()
const {
return mGrid?mGrid->cellsize():-1; }
55 bool isValid()
const {
return mGrid?!mGrid->isEmpty():
false; }
63 bool create(
int awidth,
int aheight,
int acellsize);
65 void setName(QString arg) { mVariableName = arg; }
75 void paint(
double min_val,
double max_val);
80 void save(QString fileName);
84 bool load(QString fileName);
88 void apply(QString expression);
91 void combine(QString expression, QJSValue grid_object);
96 QJSValue
resample(QJSValue grid_object);
102 double sum(QString expression);
105 void sumTrees(QString expression, QString filter);
108 double value(
int x,
int y)
const {
return (
isValid() && mGrid->isIndexValid(x,y)) ? mGrid->valueAtIndex(x,y) : -1.;}
113 double valueAt(
double x,
double y)
const {
return (
isValid() && mGrid->coordValid(x,y)) ? mGrid->valueAt(x,y) : -1; }
119 double metricX(
int indexx)
const {
return isValid() ? mGrid->cellCenterPoint(QPoint(indexx, 0)).x() : 0.; }
121 double metricY(
int indexy)
const {
return isValid() ? mGrid->cellCenterPoint(QPoint(0, indexy)).y() : 0.; }
123 int indexX(
double meterx)
const {
return isValid() ? mGrid->indexAt(QPointF(meterx, 0)).x() : -1; }
125 int indexY(
double metery)
const {
return isValid() ? mGrid->indexAt(QPointF(0., metery)).y() : -1; }
133 QString mVariableName;
Grid class (template).
Definition: grid.h:44
Definition: scriptgrid.h:29
QJSValue resample(QJSValue grid_object)
resamples the grid to the extent/cellsize given by the grid 'grid_object' Resampling is "brute-force"...
Definition: scriptgrid.cpp:235
Q_INVOKABLE ScriptGrid(QString fileName)
Definition: scriptgrid.h:39
void clear()
fill the grid with 0-values
Definition: scriptgrid.cpp:104
QJSValue copy()
create a copy of the current grid and return a new script object
Definition: scriptgrid.cpp:90
bool load(QString fileName)
load from a file (ESRI ASC raster grid), relative to project root.
Definition: scriptgrid.cpp:134
void setOwnership(bool should_delete)
Definition: scriptgrid.h:44
double sum(QString expression)
apply the expression "expression" on all pixels of the grid and return the sum of the values
Definition: scriptgrid.cpp:286
int width() const
Definition: scriptgrid.h:51
QString name
Definition: scriptgrid.h:31
void paint(double min_val, double max_val)
draw the map
Definition: scriptgrid.cpp:110
double metricX(int indexx) const
convert a cellindex in x-direction to a metric value (x) representing the center of the cell
Definition: scriptgrid.h:119
ScriptGrid(Grid< double > *grid)
Definition: scriptgrid.h:41
void save(QString fileName)
save to a file as ESRI ASC raster grid (relative to project file)
Definition: scriptgrid.cpp:124
int height
Definition: scriptgrid.h:33
void setValueAt(double x, double y, double value) const
write values to the grid at metric coordinates x and y.
Definition: scriptgrid.h:115
QString info()
Definition: scriptgrid.cpp:117
int height() const
Definition: scriptgrid.h:52
static void addToScriptEngine(QJSEngine *engine)
Definition: scriptgrid.cpp:63
int width
Definition: scriptgrid.h:32
void apply(QString expression)
apply a function on the values of the grid, thus modifiying the grid (see the copy() function).
Definition: scriptgrid.cpp:165
bool isValid
Definition: scriptgrid.h:36
QString name() const
Definition: scriptgrid.h:48
int indexY(double metery) const
convert a metric value (y-axis) to an index for the y-axis (see also isIndexValid(),...
Definition: scriptgrid.h:125
void combine(QString expression, QJSValue grid_object)
combine multiple grids, and calculate the result of 'expression'
Definition: scriptgrid.cpp:188
static QJSValue createGrid(Grid< double > *grid, QString name=QString())
Definition: scriptgrid.cpp:54
int cellsize
Definition: scriptgrid.h:35
Grid< double > * grid()
Definition: scriptgrid.h:49
~ScriptGrid()
Definition: scriptgrid.cpp:45
void setValue(int x, int y, double value) const
write values to the grid
Definition: scriptgrid.h:110
double metricY(int indexy) const
convert a cellindex in y-direction to a metric value (y) representing the center of the cell
Definition: scriptgrid.h:121
bool create(int awidth, int aheight, int acellsize)
creates a grid with cellsize / width / height the offset of the grid (lower left corner) is given by ...
Definition: scriptgrid.cpp:72
void setOrigin(double x, double y)
set the origin of the grid (iLand coordiantes).
Definition: scriptgrid.cpp:81
void setName(QString arg)
Definition: scriptgrid.h:65
void sumTrees(QString expression, QString filter)
loop over all trees and create a sum of 'expression' for each cell. Filter trees with 'filter'
Definition: scriptgrid.cpp:310
bool isCoordValid(double x, double y) const
check if a given pair of metric coordinates (x/y) is valid for the grid
Definition: scriptgrid.h:129
bool isIndexValid(int x, int y) const
check if a given pair of indices (x/y) is valid for the grid
Definition: scriptgrid.h:127
double valueAt(double x, double y) const
access value of the grid in metric coordinates
Definition: scriptgrid.h:113
int cellsize() const
Definition: scriptgrid.h:54
int indexX(double meterx) const
convert a metric value (x-axis) to an index for the x-axis (see also isIndexValid(),...
Definition: scriptgrid.h:123
void aggregate(int factor)
Definition: scriptgrid.cpp:271
void setGrid(Grid< double > *grid)
Definition: scriptgrid.h:43
Q_INVOKABLE ScriptGrid(QObject *parent=nullptr)
Definition: scriptgrid.cpp:37
bool isValid() const
Definition: scriptgrid.h:55
int count
Definition: scriptgrid.h:34
int count() const
Definition: scriptgrid.h:53
double value(int x, int y) const
access values of the grid
Definition: scriptgrid.h:108