iLand
gisgrid.h
Go to the documentation of this file.
1/********************************************************************************************
2** iLand - an individual based forest landscape and disturbance model
3** http://iland-model.org
4** Copyright (C) 2009- Werner Rammer, Rupert Seidl
5**
6** This program is free software: you can redistribute it and/or modify
7** it under the terms of the GNU General Public License as published by
8** the Free Software Foundation, either version 3 of the License, or
9** (at your option) any later version.
10**
11** This program is distributed in the hope that it will be useful,
12** but WITHOUT ANY WARRANTY; without even the implied warranty of
13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14** GNU General Public License for more details.
15**
16** You should have received a copy of the GNU General Public License
17** along with this program. If not, see <http://www.gnu.org/licenses/>.
18********************************************************************************************/
19
20
21#ifndef GISGRID_H
22#define GISGRID_H
23
24#include <QString>
25#include <QPointF>
26#include <QRectF>
27
28#include "grid.h"
29
31 SCoordTrans() { setupTransformation(0.,0.,0.,0.); }
36 void setupTransformation(double new_offsetx, double new_offsety, double new_offsetz, double angle_degree)
37 {
38 offsetX = new_offsetx;
39 offsetY = new_offsety;
40 offsetZ = new_offsetz;
41 RotationAngle=angle_degree * M_PI / 180.;
46 }
47};
48
55// setup routine -- give a vector with offsets [m] and rotation angle.
56void setupGISTransformation(const double offsetx,
57 const double offsety,
58 const double offsetz,
59 const double angle_degree);
60// transformation routines.
61void worldToModel(const Vector3D &From, Vector3D &To);
62void modelToWorld(const Vector3D &From, Vector3D &To);
63QPointF modelToWorld(QPointF model_coordinates);
64QPointF worldToModel(QPointF world_coordinates);
65
66
68{
69public:
70 GisGrid();
71 ~GisGrid();
72 // maintenance
73 bool loadFromFile(const QString &fileName);
74 // access
75 int dataSize() const { return mDataSize; }
76 int rows() const { return mNRows; }
77 int cols() const { return mNCols; }
78 QPointF origin() const { return mOrigin; }
79 double cellSize() const { return mCellSize; }
80 double minValue() const { return min_value; }
81 double maxValue() const { return max_value; }
82 int noDataValue() const { return mNODATAValue; }
85 double value(const QPointF &p) const {return value(p.x(), p.y());}
86 double value(const double X, const double Y) const;
87 double value(const int indexx, const int indexy) const;
88 double value(const int Index) const;
90 Vector3D coord(const int Index) const;
91 Vector3D coord(const int indexx, const int indexy) const;
92 QRectF rectangle(const int indexx, const int indexy) const;
93 void clip(const QRectF & box);
94
95 // special operations
96 //QRectF GetBoundingBox(int LookFor, SBoundingBox &Result, double x_m, double y_m);
97 QList<double> distinctValues();
98 //void GetDistinctValues(TStringList *ResultList, double x_m, double y_m);
99 //void CountOccurence(int intID, int & Count, int & left, int &upper, int &right, int &lower, SBoundingBox *OuterBox);
100 //S3dVector GetNthOccurence(int ID, int N, int left, int upper, int right, int lower);
101 //void ExportToTable(AnsiString OutFileName);
102
103 // global conversion functions between local and world coordinates
104 // the world-context is created by calling setupGISTransformation() (once).
106 static QPointF modelToWorld(QPointF model_coordinates);
108 static QPointF worldToModel(QPointF world_coordinates);
109
110
111private:
112
113 int mDataSize;
114 double mCellSize; // size of cells [m]
115 double max_value;
116 double min_value;
117 QPointF mOrigin; // lowerleftcorner
118 QPointF xAxis; // transformed axis (moved, rotated)
119 QPointF yAxis;
120 int mNRows;
121 int mNCols; // count of rows and cols
122 double *mData;
123 int mNODATAValue;
124};
125
126
127// Cached GIS - Dataset
128// template class.
129/*
130template <class T> class TGISData
131{
132public:
133 TTypedList<T> *Items;
134
135 TGISGrid *Grid;
136 TGISData() {
137 Items = new TTypedList<T>(true);
138 Grid=0;
139 }
140 ~TGISData() {
141 delete Items;
142 //if (Grid)
143 // delete Grid;
144 }
145 int Add(T* Item) {
146 return Items->Add(Item);
147 }
148 void Clear() { Items->Clear(); }
149// template <class T> * Select(int ID);
150 T* Select(int ID) {
151 for (int i=0;i<Items->Count;i++)
152 if (Items->Items[i]->ID == ID)
153 return Items->Items[i];
154 return 0;
155 }
156 T* SelectAt(double X, double Y) {
157 if (!Grid)
158 return 0;
159 int CellValue = Grid->value(X,Y);
160 return Select(CellValue);
161 }
162 //bool Select(int ID);
163};
164
165*/
166//---------------------------------------------------------------------------
167#endif
GisGrid encapsulates a simple grid of values based on GIS data.
Definition: gisgrid.h:68
double minValue() const
minimum data value
Definition: gisgrid.h:80
Vector3D coord(const int Index) const
get coordinates of the center of the cell with 'Index'
Definition: gisgrid.cpp:297
int noDataValue() const
no data value of the grid
Definition: gisgrid.h:82
int dataSize() const
number of data items (rows*cols)
Definition: gisgrid.h:75
int cols() const
number of columns
Definition: gisgrid.h:77
double cellSize() const
size of a cell (meters)
Definition: gisgrid.h:79
bool loadFromFile(const QString &fileName)
load ESRI style text file
Definition: gisgrid.cpp:77
static QPointF modelToWorld(QPointF model_coordinates)
convert model to world coordinates (metric)
Definition: gisgrid.cpp:186
void clip(const QRectF &box)
clip the grid to 'Box' (set values outside to -1)
Definition: gisgrid.cpp:394
GisGrid()
Definition: gisgrid.cpp:64
QRectF rectangle(const int indexx, const int indexy) const
Definition: gisgrid.cpp:283
QPointF origin() const
coordinates of the lower left corner of the grid
Definition: gisgrid.h:78
QList< double > distinctValues()
returns a list of distinct values
Definition: gisgrid.cpp:175
int rows() const
number of rows
Definition: gisgrid.h:76
static QPointF worldToModel(QPointF world_coordinates)
convert world (i.e. GIS) to model coordinates (metric) (with 0/0 at lower left edge of project area)
Definition: gisgrid.cpp:193
~GisGrid()
Definition: gisgrid.cpp:71
double maxValue() const
maximum data value
Definition: gisgrid.h:81
double value(const QPointF &p) const
get grid value at local coordinates (X/Y); returs NODATAValue if out of range X and Y are local coord...
Definition: gisgrid.h:85
simple 3d vector.
Definition: grid.h:249
void modelToWorld(const Vector3D &From, Vector3D &To)
Definition: gisgrid.cpp:54
void worldToModel(const Vector3D &From, Vector3D &To)
Definition: gisgrid.cpp:45
void setupGISTransformation(const double offsetx, const double offsety, const double offsetz, const double angle_degree)
GIS Transformation The transformation is defined by three offsets (x,y,z) and a rotation information.
Definition: gisgrid.cpp:40
Definition: gisgrid.h:30
double cosRotateReverse
Definition: gisgrid.h:34
double offsetY
Definition: gisgrid.h:35
double sinRotate
Definition: gisgrid.h:33
double offsetX
Definition: gisgrid.h:35
void setupTransformation(double new_offsetx, double new_offsety, double new_offsetz, double angle_degree)
Definition: gisgrid.h:36
double offsetZ
Definition: gisgrid.h:35
double RotationAngle
Definition: gisgrid.h:32
SCoordTrans()
Definition: gisgrid.h:31
double cosRotate
Definition: gisgrid.h:33
double sinRotateReverse
Definition: gisgrid.h:34