iLand
mapgrid.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#ifndef MAPGRID_H
21#define MAPGRID_H
22#include <QtCore/QHash>
23#include <QRectF>
24#include "grid.h"
25#include "gisgrid.h"
26class ResourceUnit; // forward
27class Tree; // forward
28class SaplingTreeOld; // forward
29class ResourceUnitSpecies; // forward
30
32{
33public:
34 MapGrid();
36 MapGrid(const GisGrid &source_grid) { loadFromGrid(source_grid); }
37 MapGrid(const QString &fileName, const bool create_index=true) { loadFromFile(fileName, create_index); }
38 bool loadFromFile(const QString &fileName, const bool create_index=true);
39 bool loadFromGrid(const GisGrid &source_grid, const bool create_index=true);
40 void createEmptyGrid();
41 void createIndex();
42
43 // access
44 const QString &name() const { return mName; }
45 bool isValid() const { return !mGrid.isEmpty(); }
46 const Grid<int> &grid() const { return mGrid; }
48 int count() const { return mRectIndex.size(); }
49 // access
51 bool isValid(const int id) const { return mRectIndex.contains(id); }
52 QRectF boundingBox(const int id) const { return isValid(id)?mRectIndex[id].first: QRectF(); }
53 double area(const int id) const {return isValid(id)?mRectIndex[id].second : 0.;}
55 QList<ResourceUnit*> resourceUnits(const int id) const;
58 QList<QPair<ResourceUnit*, double> > resourceUnitAreas(const int id) const { return mRUIndex.values(id); }
60 QList<Tree*> trees(const int id) const;
62 int loadTrees(const int id, QVector<QPair<Tree *, double> > &rList, const QString filter=QString(), int n_estimate=0) const;
64 static void freeLocksForStand(const int id);
66 QList<int> gridIndices(const int id) const;
68 const QMultiHash<int, int> neighborList() const { return mNeighborList; }
69 void updateNeighborList();
70 QList<int> neighborsOf(const int index) const;
72 inline bool hasValue(const int id, const QPoint &lif_grid_coords) const { return mGrid.constValueAtIndex(lif_grid_coords.x()/cPxPerHeight, lif_grid_coords.y()/cPxPerHeight) == id; }
74 inline int standIDFromLIFCoord(const QPoint &lif_grid_coords) const { return mGrid.constValueAtIndex(lif_grid_coords.x()/cPxPerHeight, lif_grid_coords.y()/cPxPerHeight); }
75
76private:
77 QString mName;
78 Grid<int> mGrid;
79 QHash<int, QPair<QRectF,double> > mRectIndex;
80 QMultiHash<int, QPair<ResourceUnit*, double> > mRUIndex;
81 QMultiHash<int, int> mNeighborList;
82};
83
84#endif // MAPGRID_H
GisGrid encapsulates a simple grid of values based on GIS data.
Definition: gisgrid.h:68
Grid class (template).
Definition: grid.h:44
Definition: mapgrid.h:32
QList< ResourceUnit * > resourceUnits(const int id) const
returns the list of resource units with at least one pixel within the area designated by 'id'
Definition: mapgrid.cpp:246
MapGrid()
Definition: mapgrid.cpp:110
QList< int > neighborsOf(const int index) const
retrieve a list of saplings on a given stand polygon.
Definition: mapgrid.cpp:352
QList< int > gridIndices(const int id) const
return a list of grid-indices of a given stand-id
Definition: mapgrid.cpp:320
void createIndex()
(re-)creates the internal index (mRUIndex, mRectIndex, ...)
Definition: mapgrid.cpp:170
QList< QPair< ResourceUnit *, double > > resourceUnitAreas(const int id) const
returns a list with resource units and area factors per 'id'.
Definition: mapgrid.h:58
bool isValid() const
Definition: mapgrid.h:45
MapGrid(const QString &fileName, const bool create_index=true)
Definition: mapgrid.h:37
static void freeLocksForStand(const int id)
free locks for a given stand
Definition: mapgrid.cpp:311
QList< Tree * > trees(const int id) const
return a list of all living trees on the area 'id'
Definition: mapgrid.cpp:256
const Grid< int > & grid() const
Definition: mapgrid.h:46
QRectF boundingBox(const int id) const
returns the bounding box of a polygon
Definition: mapgrid.h:52
bool loadFromFile(const QString &fileName, const bool create_index=true)
load ESRI style text file
Definition: mapgrid.cpp:234
void updateNeighborList()
scan the map and fill the mNeighborList
Definition: mapgrid.cpp:362
int loadTrees(const int id, QVector< QPair< Tree *, double > > &rList, const QString filter=QString(), int n_estimate=0) const
load trees and store in list 'rList'. If 'filter'<>"", then the filter criterion is applied
Definition: mapgrid.cpp:271
MapGrid(const GisGrid &source_grid)
create a MapGrid. the optional parameter "create_index" indicates if a spatial index (e....
Definition: mapgrid.h:36
int standIDFromLIFCoord(const QPoint &lif_grid_coords) const
return the stand-ID at the coordinates from the LIF-Grid (i.e., 2m grid).
Definition: mapgrid.h:74
bool hasValue(const int id, const QPoint &lif_grid_coords) const
return true, if the point 'lif_grid_coords' (x/y integer key within the LIF-Grid)
Definition: mapgrid.h:72
const QMultiHash< int, int > neighborList() const
extract a list of neighborhood relationships between all the polygons of the grid
Definition: mapgrid.h:68
bool isValid(const int id) const
returns true, if 'id' is a valid id in the grid, false otherwise.
Definition: mapgrid.h:51
const QString & name() const
Definition: mapgrid.h:44
int count() const
number of stands stored in the index
Definition: mapgrid.h:48
double area(const int id) const
return the area (m2) covered by the polygon
Definition: mapgrid.h:53
void createEmptyGrid()
create an empty grid with the size of the height grid of iLand (all values are 0, no index is created...
Definition: mapgrid.cpp:149
bool loadFromGrid(const GisGrid &source_grid, const bool create_index=true)
load from an already present GisGrid
Definition: mapgrid.cpp:114
ResourceUnit is the spatial unit that encapsulates a forest stand and links to several environmental ...
Definition: resourceunit.h:49
The class contains data available at ResourceUnit x Species scale.
Definition: resourceunitspecies.h:34
SaplingTreeOld holds information of a sapling (which represents N trees). Emphasis is on efficient st...
Definition: sapling.h:29
A tree is the basic simulation entity of iLand and represents a single tree.
Definition: tree.h:44
const int cPxPerHeight
Definition: globalsettings.h:9