Rev 1221 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
671 | werner | 1 | /******************************************************************************************** |
2 | ** iLand - an individual based forest landscape and disturbance model |
||
3 | ** http://iland.boku.ac.at |
||
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 | |||
543 | werner | 20 | #ifndef MAPGRID_H |
21 | #define MAPGRID_H |
||
22 | #include <QtCore/QHash> |
||
23 | #include <QRectF> |
||
24 | #include "grid.h" |
||
25 | #include "gisgrid.h" |
||
26 | class ResourceUnit; // forward |
||
544 | werner | 27 | class Tree; // forward |
1111 | werner | 28 | class SaplingTreeOld; // forward |
564 | werner | 29 | class ResourceUnitSpecies; // forward |
30 | |||
543 | werner | 31 | class MapGrid |
32 | { |
||
33 | public: |
||
34 | MapGrid(); |
||
732 | werner | 35 | /// create a MapGrid. the optional parameter "create_index" indicates if a spatial index (e.g. to query all pixels with a given value) should be built. |
543 | werner | 36 | MapGrid(const GisGrid &source_grid) { loadFromGrid(source_grid); } |
732 | werner | 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); ///< load ESRI style text file |
||
39 | bool loadFromGrid(const GisGrid &source_grid, const bool create_index=true); ///< load from an already present GisGrid |
||
848 | werner | 40 | void createEmptyGrid(); ///< create an empty grid with the size of the height grid of iLand (all values are 0, no index is created) |
41 | void createIndex(); ///< (re-)creates the internal index (mRUIndex, mRectIndex, ...) |
||
42 | |||
543 | werner | 43 | // access |
575 | werner | 44 | const QString &name() const { return mName; } |
543 | werner | 45 | bool isValid() const { return !mGrid.isEmpty(); } |
549 | werner | 46 | const Grid<int> &grid() const { return mGrid; } |
543 | werner | 47 | // access |
863 | werner | 48 | /// returns true, if 'id' is a valid id in the grid, false otherwise. |
49 | bool isValid(const int id) const { return mRectIndex.contains(id); } |
||
50 | QRectF boundingBox(const int id) const { return isValid(id)?mRectIndex[id].first: QRectF(); } ///< returns the bounding box of a polygon |
||
51 | double area(const int id) const {return isValid(id)?mRectIndex[id].second : 0.;} ///< return the area (m2) covered by the polygon |
||
565 | werner | 52 | /// returns the list of resource units with at least one pixel within the area designated by 'id' |
53 | QList<ResourceUnit*> resourceUnits(const int id) const; |
||
54 | /// returns a list with resource units and area factors per 'id'. |
||
55 | /// the area is '1' if the resource unit is fully covered by the grid-value. |
||
56 | QList<QPair<ResourceUnit*, double> > resourceUnitAreas(const int id) const { return mRUIndex.values(id); } |
||
578 | werner | 57 | /// return a list of all living trees on the area 'id' |
549 | werner | 58 | QList<Tree*> trees(const int id) const; |
884 | werner | 59 | /// load trees and store in list 'rList'. If 'filter'<>"", then the filter criterion is applied |
885 | werner | 60 | int loadTrees(const int id, QVector<QPair<Tree *, double> > &rList, const QString filter, int n_estimate=0) const; |
932 | werner | 61 | /// free locks for a given stand |
62 | static void freeLocksForStand(const int id); |
||
549 | werner | 63 | /// return a list of grid-indices of a given stand-id |
64 | QList<int> gridIndices(const int id) const; |
||
797 | werner | 65 | /// extract a list of neighborhood relationships between all the polygons of the grid |
66 | const QMultiHash<int, int> neighborList() const { return mNeighborList; } |
||
914 | werner | 67 | void updateNeighborList(); ///< scan the map and fill the mNeighborList |
797 | werner | 68 | QList<int> neighborsOf(const int index) const; |
544 | werner | 69 | /// return true, if the point 'lif_grid_coords' (x/y integer key within the LIF-Grid) |
549 | werner | 70 | 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; } |
1203 | werner | 71 | /// return the stand-ID at the coordinates *from* the LIF-Grid (i.e., 2m grid). |
72 | inline int standIDFromLIFCoord(const QPoint &lif_grid_coords) const { return mGrid.constValueAtIndex(lif_grid_coords.x()/cPxPerHeight, lif_grid_coords.y()/cPxPerHeight); } |
||
903 | werner | 73 | |
543 | werner | 74 | private: |
575 | werner | 75 | QString mName; ///< file name of the grid |
543 | werner | 76 | Grid<int> mGrid; |
544 | werner | 77 | QHash<int, QPair<QRectF,double> > mRectIndex; ///< holds the extent and area for each map-id |
565 | werner | 78 | QMultiHash<int, QPair<ResourceUnit*, double> > mRUIndex; ///< holds a list of resource units + areas per map-id |
797 | werner | 79 | QMultiHash<int, int> mNeighborList; ///< a list of neighboring polygons; for each ID all neighboring IDs are stored. |
543 | werner | 80 | }; |
81 | |||
82 | #endif // MAPGRID_H |