g.gui.gmodeler.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <!-- meta page description: wxGUI Graphical Modeler -->
  2. <!-- meta page index: topic_gui|GUI -->
  3. <h2>DESCRIPTION</h2>
  4. <p>
  5. The <b>Graphical Modeler</b> is
  6. a <em><a href="wxGUI.html">wxGUI</a></em> component which allows the user to
  7. create, edit, and manage complex models using easy-to-use
  8. interface. When performing analytical operations in GRASS, the
  9. operations are not isolated, but part of a chain of operations. Using
  10. Graphical Modeler, that chain of processes (ie. GRASS modules)
  11. can be wrapped into one process (ie. model). So it's easier to execute
  12. the model later with slightly different inputs or parameters.
  13. <br>
  14. Models represent a programming technique used in GRASS GIS to
  15. concatenate models together to accomplish a task. It is advantageous
  16. when user see boxes and ovals that are connected by lines and
  17. represent some tasks rather than seeing lines of coded text. Graphical
  18. Modeler can be used as custom tool that automates a process. Created
  19. model can simplify or shorten a task can be run many times and it can
  20. also be shared with others. Important note is that models cannot
  21. perform specified tasks that one cannot perform manually with GRASS
  22. GIS. It is recommended to first do process manually, note the steps
  23. (eg. using Copy button in module dialogs) and later duplicate them in
  24. model.
  25. <p>
  26. The Graphical Modeler allows you to:
  27. <ul>
  28. <li>define data items (raster, vector, 3D raster maps)</li>
  29. <li>define actions (GRASS commands)</li>
  30. <li>define relations between data and action items</li>
  31. <li>define loops (eg. map series) and conditions (if-else statements)</li>
  32. <li>define model variables</li>
  33. <li>parameterize GRASS commands</li>
  34. <li>define intermediate data</li>
  35. <li>validate and run model</li>
  36. <li>store model properties to the file (<i>GRASS Model File|*.gxm</i>)</li>
  37. <li>export model to Python script</li>
  38. <li>export model to image file</li>
  39. </ul>
  40. <h3>Main dialog</h3>
  41. Graphical Modeler can be launched from the Layer Manager menu
  42. <tt>File -> Graphical modeler</tt> or from the main
  43. toolbar <img src="icons/modeler-main.png" alt="icon">. It's also
  44. available as stand-alone module <em>g.gui.gmodeler</em>.
  45. <p>
  46. The main Graphical Modeler menu contains options which enable the user
  47. to fully control the model. Directly under the main menu one can find
  48. toolbar with buttons (see figure below). There are options like
  49. (<font size="2" color="red">1</font>) Create new model,
  50. (<font size="2" color="red">2</font>) Load model from file,
  51. (<font size="2" color="red">3</font>) Save current model to file,
  52. (<font size="2" color="red">4</font>) Export model to image,
  53. (<font size="2" color="red">5</font>) Export model to Python script,
  54. (<font size="2" color="red">6</font>) Add command (GRASS modul) to
  55. model, (<font size="2" color="red">7</font>) Add data to model,
  56. (<font size="2" color="red">8</font>) Manually define relation between
  57. data and commands, (<font size="2" color="red">9</font>) Add
  58. loop/series to model, (<font size="2" color="red">10</font>) Add
  59. comment to model, (<font size="2" color="red">11</font>) Redraw model
  60. canvas, (<font size="2" color="red">12</font>) Validate model,
  61. (<font size="2" color="red">13</font>) Run model, (<font size="2"
  62. color="red">14</font>) Manage model variables, (<font size="2"
  63. color="red">15</font>) Model settings, (<font size="2"
  64. color="red">16</font>) Show manual and last of them is button
  65. (<font size="2" color="red">17</font>) Quit Graphical Modeler.
  66. <p>
  67. <center>
  68. <br>
  69. <img src="g_gui_gmodeler_toolbar.png">
  70. <br>
  71. <i>Figure: Components of Graphical Modeler menu toolbar.</i>
  72. </center>
  73. <p>
  74. There is also lower menu bar in Graphical modeler dialog where one can
  75. manage model items, see commands, add or manage model variables,
  76. define default values and descriptions. Python editor dialog window
  77. allows seeing performation written in Python code. Rightmost tab of
  78. bottom menu is automatically triggered when model is activated and
  79. shows all the steps of running GRASS modeler modules. In case of some
  80. errors in calculation process, it is written at that place.
  81. <center>
  82. <br>
  83. <img src="g_gui_gmodeler_lower_toolbar.png">
  84. <br>
  85. <i>Figure: Lower Graphical Modeler menu toolbar.</i>
  86. </center>
  87. <h3>Components of models</h3>
  88. The workflow is usually established from four types of diagrams. Input and derived
  89. model data are usually represented with oval diagram.
  90. This type of model elements stores path to
  91. specific data on user's disk. It is possible to insert vector data, raster data,
  92. database tables, etc. Type of data is clear distinguishable in model by color.
  93. Different model elements are shown on the figures below.
  94. <ul>
  95. <li> (<font size="2" color="red">A</font>) raster data: <img src="g_gui_gmodeler_mraster.png" alt="raster" style="margin: 0px 0px -5px 0px">
  96. <li> (<font size="2" color="red">B</font>) relation: <img src="g_gui_gmodeler_mrelation.png" alt="relation" style="margin: 10px 0px 0px 0px">
  97. <li> (<font size="2" color="red">C</font>) GRASS module: <img src="g_gui_gmodeler_mmodule.png" alt="module" style="margin: 0px 0px -5px 0px">
  98. <li> (<font size="2" color="red">D</font>) loop: <img src="g_gui_gmodeler_mloop.png" alt="loop" style="margin: 15px 0px -5px 0px">
  99. <li> (<font size="2" color="red">E</font>) database table: <img src="g_gui_gmodeler_mdb.png" alt="db" style="margin: 10px 0px -5px 0px">
  100. <li> (<font size="2" color="red">F</font>) 3D raster data: <img src="g_gui_gmodeler_mraster3d.png" alt="raster3D" style="margin: 10px 0px -5px 0px">
  101. <li> (<font size="2" color="red">G</font>) vector data: <img src="g_gui_gmodeler_mvector.png" alt="vector" style="margin: 10px 0px -5px 0px">
  102. <li> (<font size="2" color="red">H</font>) disabled GRASS module: <img src="g_gui_gmodeler_mmodulex.png" alt="module" style="margin: 10px 0px -5px 0px">
  103. <li> (<font size="2" color="red">I</font>) comment: <img src="g_gui_gmodeler_mcomment.png" alt="comment" style="margin: 10px 0px -5px 0px">
  104. </ul>
  105. <center>
  106. <img src="g_gui_gmodeler_frame1.png">
  107. <br>
  108. <i>Figure: A model to perform unsupervised classification using MLC
  109. (<a href="i.maxlik.html">i.maxlik</a>) and SMAP
  110. (<a href="i.smap.html">i.smap</a>).</i>
  111. </center>
  112. <p>
  113. Another example:
  114. <center>
  115. <img src="g_gui_gmodeler_frame2.png">
  116. <br>
  117. <i>Figure: A model to perform estimation of average annual soil loss
  118. caused by sheet and rill erosion using The Universal Soil Loss
  119. Equation.</i>
  120. </center>
  121. <p>
  122. Example as part of landslide prediction process:
  123. <center>
  124. <br>
  125. <img src="g_gui_gmodeler_frame3.png">
  126. <br>
  127. <i>Figure: A model to perform creation of parametric maps used by geologists
  128. to predict landlides in area of interest.</i>
  129. </center>
  130. <h2>EXAMPLE</h2>
  131. In this example <tt>zipcodes_wake</tt> vector data
  132. and <tt>elev_state_500m</tt> raster data from the North Carolina
  133. sample dataset (original <a href="http://grass.osgeo.org/sampledata/north_carolina/nc_rast_geotiff.zip">raster</a> and
  134. <a href="http://grass.osgeo.org/sampledata/north_carolina/nc_shape.zip">vector</a>
  135. data) are used to calculate average elevation for every
  136. zone. Important part of the process is Graphical Modeler, namely it's
  137. possibilities of process automation.
  138. <p>
  139. In command console it would be as follows:
  140. <div class="code"><pre>
  141. # input data import
  142. r.import input=elev_state_500m.tif output=elevation
  143. v.import input=zipcodes_wake.shp output=zipcodes_wake
  144. # computation region settings
  145. g.region vector=zipcodes_wake
  146. # raster statistics (average values), upload to vector map table calculation
  147. v.rast.stats -c map=zipcodes_wake raster=elevation column_prefix=rst method=average
  148. # univariate statistics on selected table column for zipcode map calculation
  149. v.db.univar map=zipcodes_wake column=rst_average
  150. # conversation from vector to raster layer (due to result presentation)
  151. v.to.rast input=zipcodes_wake output=zipcodes_avg use=attr attribute_column=rst_average
  152. # display settings
  153. r.colors -e map=zipcodes_avg color=bgyr
  154. d.mon start=wx0 bgcolor=white
  155. d.barscale style=arrow_ends color=black bgcolor=white fontsize=10
  156. d.rast map=zipcodes_avg bgcolor=white
  157. d.vect map=zipcodes_wake type=boundary color=black
  158. d.northarrow style=1a at=85.0,15.0 color=black fill_color=black width=0 fontsize=10
  159. d.legend raster=zipcodes_avg lines=50 thin=5 labelnum=5 color=black fontsize=10
  160. </pre></div>
  161. To start performing above steps as automatic process with Graphical Modeler press
  162. <img src="icons/modeler-main.png" alt="icon"> icon or
  163. type <em>g.gui.gmodeler</em>. The simplest way of inserting elements
  164. is by adding complete GRASS command to Command field in GRASS command
  165. dialog (see figure below). With full text search one can faster
  166. module hunting. Then label and command can be added. In case that only
  167. module name is inserted, after <i>Enter</i> button pressing, module
  168. dialog window is displayed and it is possible to set all of usual
  169. module options (parameters and flags).
  170. <center>
  171. <img src="g_gui_gmodeler_dlg_module.png">
  172. <br>
  173. <i>Figure: Dialog for adding GRASS commands to model.</i>
  174. </center>
  175. <p>
  176. All of used modules can be parameterized in model. That causes launching
  177. dialog with input options for model after model is run. In this example
  178. input layers (<tt>zipcodes_wake</tt> vector data and <tt>elev_state_500m</tt>
  179. raster data) are parameterized. Parameterized elements have a little thicker boarder
  180. in model scheme with diagrams.
  181. <center>
  182. <img src="g_gui_gmodeler_parameter.png">
  183. <br>
  184. <i>Figure: A model parameter settings.</i>
  185. </center>
  186. <p>
  187. Final model, list of all model items, Python code window with <i>Save</i> and
  188. <i>Run</i> option are on figures below.
  189. <center>
  190. <img src="g_gui_gmodeler_zc.png">
  191. <br>
  192. <i>Figure: A model to perform average statistics for zipcode zones.</i>
  193. </center>
  194. <br>
  195. <center>
  196. <img src="g_gui_gmodeler_zc_items.png">
  197. <br>
  198. <i>Figure: Items with Python editor window.</i>
  199. </center>
  200. <p>The resultant model for Graphical Modeler is
  201. available <a href="g_gui_gmodeler_zipcodes_avg_elevation.gxm
  202. ">here</a>.
  203. <p>
  204. After model is run with <img src="icons/execute.png" alt="run"> button
  205. and inputs are set, results can be displayed as follows:
  206. <center>
  207. <img src="g_gui_gmodeler_avg_auto.png">
  208. <br>
  209. <i>Figure: Average elevation for zipcodes using North Carolina sample dataset as
  210. automatic calculation performed by Graphical Modeler.</i>
  211. </center>
  212. <p>
  213. Very useful advantage is that for example, this model can later be
  214. used to calculate (let's say) average precipe value for every
  215. administrative region in Slovakia using <tt>precip</tt> raster data
  216. from
  217. <a href="https://grass.osgeo.org/uploads/grass/sampledata/slovakia3d_grass7.tar.gz">
  218. Slovakia precipitation dataset</a> and administration boundaries of Slovakia from
  219. <a href="https://www.geoportal.sk/sk/zbgis_smd/na-stiahnutie/">Slovak Geoportal</a>
  220. (only with a few clicks).
  221. <h2>SEE ALSO</h2>
  222. <em>
  223. <a href="wxGUI.html">wxGUI</a><br>
  224. <a href="wxGUI.components.html">wxGUI components</a>
  225. </em>
  226. <!--
  227. <p>
  228. User-defined models available
  229. from <a href="http://svn.osgeo.org/grass/grass-addons/wxgui_modeler">SVN</a>.
  230. -->
  231. <p>
  232. See also
  233. the <a href="http://grasswiki.osgeo.org/wiki/WxGUI_Graphical_Modeler">wiki</a> page
  234. (especially various <a href="http://grasswiki.osgeo.org/wiki/WxGUI_Graphical_Modeler#Video_tutorials">video
  235. tutorials</a>).
  236. <h2>AUTHORS</h2>
  237. Martin Landa, OSGeoREL, Czech Technical University in Prague, Czech Republic<br>
  238. Various manual improvements by Ludmila Furkevicova, Slovak University of Technology in Bratislava, Slovak Republic
  239. <p>
  240. <i>$Date$</i>