Subversion Repositories public iLand

Rev

Rev 1221 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1191 werner 1
/**
2
The `Map` object encapsulates a "GIS" grid. Grids can be read from ESRI ASCII raster files, and are
3
automatically mapped to a 10x10m grid (the resolution and extent of the height grid).
4
Internally, a "spatial index" is created allowing for fast access to trees that lie on specific pixels.
5
See also the wiki page [landscape setup](http://iland.boku.ac.at/landscape+setup).
6
The loaded map can be used, e.g., to specifically apply management on specific areas.
7
 
8
 
9
A newly created `Map` object (without a call to `load()`) points to the global stand grid
10
defined in the [project file](http://iland.boku.ac.at/project+file).
11
 
12
Use {{#crossLink "Map/load:method"}}{{/crossLink}} to read a raster file from disk.
13
 
14
 
15
Example
16
--------
17
    function loadMap()
18
    {
19
      var path = Globals.defaultDirectory("script"); // get project script folder; see also the "currentDir" property of "Globals". defaultDirectory() adds already a slash
20
      // var stand_map = new Map(); // Qt4
21
      var stand_map = Factory.newMap(); // Qt5
22
      stand_map.load(path + "test.txt");
23
      // now load all trees on pixels with value '2020' in the "test.txt" grid
24
      management.loadFromMap(stand_map, 2020);
25
      // ... now do something ....
26
 
27
      var map = new Map();
28
      // select all trees on stand with id 127 of the 'system' stand grid
29
      management.loadFromMap(map, 127);
30
    }
31
 
32
 @module iLand
33
 @class Map
34
 */
35
 
36
Map = {
37
 
38
    /**
39
    The filename for successfully loaded grid or 'invalid'.
40
 
41
    @property name
42
    @type string
43
    @readOnly
44
    */
45
 
46
    /**
47
    Load a grid (provided in ESRI textformat) from disk. See [landscape setup](http://iland.boku.ac.at/landscape+setup) for information about projections.
48
 
49
    @method load
50
    @param {string} file_name
51
    */
52
    /**
53
    Retrieves the area of the polygon `stand_id` in square meters (m2). Returns -1, if `stand_id` is invalid.
54
 
55
    @method area
56
    @param {integer} stand_id ID of the polygon for which to return the area.
57
    @return {double}
58
    The area (m2) of the polygon.
59
    */
60
    /**
61
    Visualization of the map in the iLand Viewers' main window (if present).
62
    Map values are colorized between `min_value` (blue) and `max_value` (red).
63
 
64
 
65
    @method paint
66
    @param {double} min_value The minimum value for the color ramp in the visualization
67
    @param {double} max_value The minimum value for the color ramp in the visualization
68
    */
69
    /**
70
    Clears the map (set all values to 0)
71
 
72
    @method clear
73
    */
74
 
75
    /**
76
    Clear only the project area (set all cell values to 0), but do not affect pixels
77
    that are "outside of project area" (i.e., have values of -1 and -2).
78
    (see [Landscape setup](http://iland.boku.ac.at/Landscape+setup))
79
 
80
    @method clearProjectArea
81
    */
82
 
83
    /**
84
    "Paint" a shape on the Map with an ID `stand_id`.
85
    The `paint_function` is a valid iLand [Expression](http://iland.boku.ac.at/Expression)
86
    (with the paramters: `x`and `y` as *metric* coordinates). All pixels for which `paint_function`
87
    evaluates to `true` are set to `stand_id`, all other pixels are not modified.
88
 
89
 
90
    @method createStand
91
    @param {integer} stand_id ID of the polygon to be created
92
    @param {string} paint_function the function defining the shape
93
    @param {boolean} wrap_around if `true`, the shape is wrapped around the edges of the simulated area (torus)
94
    @Example
95
        var map = undefined;
96
        // the function create 10 random circles
97
        // with a radius between 10 and 60m on a random location on the landscape,
98
        // and removes some of those trees
99
        function random_circles()
100
        {
101
            if (map == undefined) {
102
               map = Factory.newMap(); // create a new map
103
               map.clear();
104
            }
105
            for (var i=1;i<10;++i) {
106
                var x = Math.random() * 600;
107
                var y = Math.random() * 400;
108
                var r = 10 + Math.random() * 50;
109
                map.clear();
110
                map.createStand(i,'(x-'+x+')^2+(y-'+y+')^2<'+r+'^2',true);
111
                // load all trees that are present on the stand
112
                management.loadFromMap(map, i);
113
                print(management.count + " trees in the area...");
114
                // apply a special filter polygon
115
                management.filter('polygon(dbh, 10,0, 30,1)');
116
                print(management.count + " after filter: trees in the area...");
117
                management.killAll(); // kill the trees
118
            }
119
        }
120
    */
121
 
122
 
123
 
124
 
125
}