<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://grasswiki.osgeo.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=%E2%9A%A0%EF%B8%8FGcmillar</id>
	<title>GRASS-Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://grasswiki.osgeo.org/w/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=%E2%9A%A0%EF%B8%8FGcmillar"/>
	<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/wiki/Special:Contributions/%E2%9A%A0%EF%B8%8FGcmillar"/>
	<updated>2026-05-26T04:38:34Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.0</generator>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24333</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24333"/>
		<updated>2017-06-26T19:58:17Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Software */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view (use image on the right if clarification is needed for below steps):&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS (accessible from the toolbar or the Python tab in the Layer Manager). Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), only the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples includes:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it is better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate, in a simple way, what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor (be sure to overwrite any already existing code) and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then, rearrange the layers so that the ortho is below all the other layers.&lt;br /&gt;
Confirm the dialog and the animation should be then loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in a way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is currently set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this, which can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are a GRASS RGB triplet. In other words, red, green, and blue colors are expressed as numbers from 0 to 255 separated by a colon (using HTML syntax, an equivalent would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Information for scripting, parallelization, and supercomputing'''&lt;br /&gt;
&lt;br /&gt;
In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is a very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include: &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use the &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; vector map instead of just &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* Add the &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt; vector map in the same way as the &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt;. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Download the standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download the North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24332</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24332"/>
		<updated>2017-06-26T19:56:58Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Scripting of rendering in GRASS GIS */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view (use image on the right if clarification is needed for below steps):&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS (accessible from the toolbar or the Python tab in the Layer Manager). Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), only the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples includes:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it is better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate, in a simple way, what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor (be sure to overwrite any already existing code) and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then, rearrange the layers so that the ortho is below all the other layers.&lt;br /&gt;
Confirm the dialog and the animation should be then loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in a way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is currently set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this, which can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are a GRASS RGB triplet. In other words, red, green, and blue colors are expressed as numbers from 0 to 255 separated by a colon (using HTML syntax, an equivalent would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Information for scripting, parallelization, and supercomputing'''&lt;br /&gt;
&lt;br /&gt;
In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is a very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include: &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use the &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; vector map instead of just &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;.&lt;br /&gt;
* Add the &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt; vector map in the same way as the &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt;. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24331</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24331"/>
		<updated>2017-06-26T19:53:48Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Scripting of rendering in GRASS GIS */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view (use image on the right if clarification is needed for below steps):&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS (accessible from the toolbar or the Python tab in the Layer Manager). Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), only the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples includes:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it is better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate, in a simple way, what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor (be sure to overwrite any already existing code) and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then, rearrange the layers so that the ortho is below all the other layers.&lt;br /&gt;
Confirm the dialog and the animation should be then loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in a way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is currently set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this, which can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are a GRASS RGB triplet. In other words, red, green, and blue colors are expressed as numbers from 0 to 255 separated by a colon (using HTML syntax, an equivalent would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
'''Information for scripting, parallelization, and supercomputing'''&lt;br /&gt;
&lt;br /&gt;
In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24330</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24330"/>
		<updated>2017-06-26T19:53:33Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Scripting of rendering in GRASS GIS */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view (use image on the right if clarification is needed for below steps):&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS (accessible from the toolbar or the Python tab in the Layer Manager). Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), only the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples includes:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it is better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate, in a simple way, what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor (be sure to overwrite any already existing code) and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then, rearrange the layers so that the ortho is below all the other layers.&lt;br /&gt;
Confirm the dialog and the animation should be then loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in a way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is currently set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this, which can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are a GRASS RGB triplet. In other words, red, green, and blue colors are expressed as numbers from 0 to 255 separated by a colon (using HTML syntax, an equivalent would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
'''Information for scripting, parallelization, and supercomputing'''&lt;br /&gt;
&lt;br /&gt;
In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24329</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24329"/>
		<updated>2017-06-26T19:53:17Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Scripting of rendering in GRASS GIS */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view (use image on the right if clarification is needed for below steps):&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS (accessible from the toolbar or the Python tab in the Layer Manager). Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), only the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples includes:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it is better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate, in a simple way, what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor (be sure to overwrite any already existing code) and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then, rearrange the layers so that the ortho is below all the other layers.&lt;br /&gt;
Confirm the dialog and the animation should be then loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in a way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is currently set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this, which can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are a GRASS RGB triplet. In other words, red, green, and blue colors are expressed as numbers from 0 to 255 separated by a colon (using HTML syntax, an equivalent would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
'''Information for scripting, parallelization, and supercomputing:'''&lt;br /&gt;
&lt;br /&gt;
In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24328</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24328"/>
		<updated>2017-06-26T19:52:55Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Scripting of rendering in GRASS GIS */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view (use image on the right if clarification is needed for below steps):&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS (accessible from the toolbar or the Python tab in the Layer Manager). Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), only the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples includes:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it is better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate, in a simple way, what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor (be sure to overwrite any already existing code) and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then, rearrange the layers so that the ortho is below all the other layers.&lt;br /&gt;
Confirm the dialog and the animation should be then loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in a way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is currently set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this, which can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are a GRASS RGB triplet. In other words, red, green, and blue colors are expressed as numbers from 0 to 255 separated by a colon (using HTML syntax, an equivalent would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
'''Information for scripting, parallelization, and supercomputing:'''&lt;br /&gt;
In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24327</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24327"/>
		<updated>2017-06-26T19:51:47Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Scripting of rendering in GRASS GIS */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view (use image on the right if clarification is needed for below steps):&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS (accessible from the toolbar or the Python tab in the Layer Manager). Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), only the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples includes:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it is better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate, in a simple way, what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor (be sure to overwrite any already existing code) and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then, rearrange the layers so that the ortho is below all the other layers.&lt;br /&gt;
Confirm the dialog and the animation should be then loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in a way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is currently set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this, which can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are a GRASS RGB triplet. In other words, red, green, and blue colors are expressed as numbers from 0 to 255 separated by a colon (using HTML syntax, an equivalent would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
==== Information for scripting, parallelization, and supercomputing: ==== &lt;br /&gt;
In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24326</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24326"/>
		<updated>2017-06-26T19:49:17Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Scripting of rendering in GRASS GIS */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view (use image on the right if clarification is needed for below steps):&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS (accessible from the toolbar or the Python tab in the Layer Manager). Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), only the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples includes:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it is better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate, in a simple way, what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor (be sure to overwrite any already existing code) and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then, rearrange the layers so that the ortho is below all the other layers.&lt;br /&gt;
Confirm the dialog and the animation should be then loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in a way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is currently set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this, which can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are a GRASS RGB triplet. In other words, red, green, and blue colors are expressed as numbers from 0 to 255 separated by a colon (using HTML syntax, an equivalent would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24325</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24325"/>
		<updated>2017-06-26T19:46:39Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Scripting of rendering in GRASS GIS */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view (use image on the right if clarification is needed for below steps):&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS (accessible from the toolbar or the Python tab in the Layer Manager). Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), only the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples includes:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it is better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate, in a simple way, what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor (be sure to overwrite any already existing code) and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then, rearrange the layers so that the ortho is below all the other layers.&lt;br /&gt;
Confirm the dialog and the animation should be then loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in a way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is currently set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this, which can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example is shown below:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24324</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24324"/>
		<updated>2017-06-26T19:34:27Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Animation in GRASS GIS */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view (use image on the right if clarification is needed for below steps):&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS (accessible from the toolbar or the Python tab in the Layer Manager). Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), only the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples includes:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it is better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate, in a simple way, what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor (be sure to overwrite any already existing code) and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then, rearrange the layers so that the ortho is below all the other layers.&lt;br /&gt;
Confirm the dialog and the animation should be then loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24323</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24323"/>
		<updated>2017-06-26T19:33:22Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Animation in GRASS GIS */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view (use image on the right if clarification is needed for below steps):&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS (accessible from the toolbar or the Python tab in the Layer Manager). Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), only the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples includes:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it is better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate, in a simple way, what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor (be sure to overwrite any already existing code) and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then, rearrange the layers so that the ortho is below all the other layers.&lt;br /&gt;
Confirm the dialog and the animation should be then loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24322</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24322"/>
		<updated>2017-06-26T18:51:55Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Batch processing using Python */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view (use image on the right if clarification is needed for below steps):&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS (accessible from the toolbar or the Python tab in the Layer Manager). Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), only the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples includes:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it is better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate, in a simple way, what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor (be sure to overwrite any already existing code) and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24321</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24321"/>
		<updated>2017-06-26T18:49:10Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Batch processing using Python */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view (use image on the right if clarification is needed for below steps):&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS (accessible from the toolbar or the Python tab in the Layer Manager). Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), only the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples includes:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it is better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate, in a simple way, what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24320</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24320"/>
		<updated>2017-06-26T18:42:00Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Batch processing using Python */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view (use image on the right if clarification is needed for below steps):&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS (accessible from the toolbar or the Python tab in the Layer Manager). Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), only the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples includes:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it is better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate, in a simple way, what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24319</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24319"/>
		<updated>2017-06-26T18:25:03Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Introduction to scripting in GRASS GIS with Python */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view (use image on the right if clarification is needed for below steps):&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS (accessible from the toolbar or the Python tab in the Layer Manager). Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), only the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples includes:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it is better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate in a simple way what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24318</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24318"/>
		<updated>2017-06-26T18:19:15Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Introduction to scripting in GRASS GIS with Python */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view (use image on the right if clarification is needed for below steps):&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS (accessible from the toolbar or the Python tab in the Layer Manager). Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), only the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples includes:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate in a simple way what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24317</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24317"/>
		<updated>2017-06-26T18:17:07Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Introduction to scripting in GRASS GIS with Python */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view (use image on the right if clarification is needed for below steps):&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS (accessible from the toolbar or the Python tab in the Layer Manager). Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), only the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate in a simple way what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24316</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24316"/>
		<updated>2017-06-26T18:12:25Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Introduction to scripting in GRASS GIS with Python */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view (use image on the right if clarification is needed for below steps):&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS (accessible from the toolbar or the Python tab in the Layer Manager). Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), just the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate in a simple way what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24315</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24315"/>
		<updated>2017-06-26T18:11:27Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Introduction to scripting in GRASS GIS with Python */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view (use image on the right if clarification is needed for below steps):&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS (accessible from the toolbar or the Python tab in the Layer Manager). Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': most often used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), just the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate in a simple way what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24314</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24314"/>
		<updated>2017-06-26T18:08:53Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* 3D view */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view (use image on the right if clarification is needed for below steps):&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS accessible from the toolbar or the Python tab in the Layer Manager. Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': most often used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), just the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate in a simple way what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24313</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24313"/>
		<updated>2017-06-26T18:06:38Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* 3D view */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view:&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS accessible from the toolbar or the Python tab in the Layer Manager. Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': most often used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), just the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate in a simple way what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24312</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24312"/>
		<updated>2017-06-26T18:05:30Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* 3D view */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view.&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS accessible from the toolbar or the Python tab in the Layer Manager. Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': most often used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), just the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate in a simple way what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24311</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24311"/>
		<updated>2017-06-26T18:04:26Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* 3D view */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view (change 2D view to 3D view in Map Display window).&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS accessible from the toolbar or the Python tab in the Layer Manager. Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': most often used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), just the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate in a simple way what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24310</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24310"/>
		<updated>2017-06-26T16:44:44Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Running modules */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'', or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view.&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS accessible from the toolbar or the Python tab in the Layer Manager. Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': most often used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), just the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate in a simple way what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24309</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24309"/>
		<updated>2017-06-26T16:40:19Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Computational region */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI: On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'' or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view.&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS accessible from the toolbar or the Python tab in the Layer Manager. Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': most often used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), just the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate in a simple way what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24308</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24308"/>
		<updated>2017-06-26T16:29:14Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Computational region */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must properly set the computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check that your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI. On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'' or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view.&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS accessible from the toolbar or the Python tab in the Layer Manager. Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': most often used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), just the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate in a simple way what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24307</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24307"/>
		<updated>2017-06-26T16:26:24Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Command line vs. GUI interface */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copied and pasted into the command line for our workflow, but you can use both the GUI and command line interface depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must set properly computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI. On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'' or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view.&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS accessible from the toolbar or the Python tab in the Layer Manager. Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': most often used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), just the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate in a simple way what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24306</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24306"/>
		<updated>2017-06-26T16:24:04Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Finding and running a module */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command lines specifically built for running GRASS GIS modules. If you type the module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can also use the command line to run whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copy and pasted into the command line for our workflow, but you can use both GUI and command line depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must set properly computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI. On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'' or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view.&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS accessible from the toolbar or the Python tab in the Layer Manager. Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': most often used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), just the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate in a simple way what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24305</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24305"/>
		<updated>2017-06-26T16:18:56Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* GRASS GIS modules overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is a few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command line specifically build for running GRASS GIS modules. If you type module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can use the command line to run also whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copy and pasted into the command line for our workflow, but you can use both GUI and command line depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must set properly computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI. On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'' or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view.&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS accessible from the toolbar or the Python tab in the Layer Manager. Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': most often used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), just the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate in a simple way what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24304</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24304"/>
		<updated>2017-06-26T16:08:52Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* GRASS GIS modules overview */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manners of spatial and temporal data. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command line specifically build for running GRASS GIS modules. If you type module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can use the command line to run also whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copy and pasted into the command line for our workflow, but you can use both GUI and command line depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must set properly computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI. On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'' or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view.&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS accessible from the toolbar or the Python tab in the Layer Manager. Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': most often used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), just the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate in a simple way what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24303</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24303"/>
		<updated>2017-06-26T16:08:07Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Displaying and exploring data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right clicking on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manner of spatial and temporal. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command line specifically build for running GRASS GIS modules. If you type module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can use the command line to run also whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copy and pasted into the command line for our workflow, but you can use both GUI and command line depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must set properly computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI. On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'' or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view.&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS accessible from the toolbar or the Python tab in the Layer Manager. Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': most often used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), just the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate in a simple way what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24302</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24302"/>
		<updated>2017-06-26T16:06:55Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Displaying and exploring data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster and vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right click on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manner of spatial and temporal. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command line specifically build for running GRASS GIS modules. If you type module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can use the command line to run also whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copy and pasted into the command line for our workflow, but you can use both GUI and command line depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must set properly computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI. On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'' or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view.&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS accessible from the toolbar or the Python tab in the Layer Manager. Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': most often used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), just the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate in a simple way what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24301</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24301"/>
		<updated>2017-06-26T15:52:25Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Importing data */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import the provided data into GRASS GIS. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster, vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right click on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manner of spatial and temporal. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command line specifically build for running GRASS GIS modules. If you type module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can use the command line to run also whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copy and pasted into the command line for our workflow, but you can use both GUI and command line depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must set properly computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI. On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'' or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view.&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS accessible from the toolbar or the Python tab in the Layer Manager. Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': most often used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), just the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate in a simple way what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24299</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24299"/>
		<updated>2017-06-26T15:42:20Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: /* Structure of the GRASS GIS Spatial Database */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place your data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import into GRASS GIS the provided data. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster, vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right click on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manner of spatial and temporal. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command line specifically build for running GRASS GIS modules. If you type module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can use the command line to run also whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copy and pasted into the command line for our workflow, but you can use both GUI and command line depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must set properly computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI. On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'' or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view.&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS accessible from the toolbar or the Python tab in the Layer Manager. Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': most often used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), just the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate in a simple way what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
	<entry>
		<id>https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24298</id>
		<title>Analytical data visualizations at ICC 2017</title>
		<link rel="alternate" type="text/html" href="https://grasswiki.osgeo.org/w/index.php?title=Analytical_data_visualizations_at_ICC_2017&amp;diff=24298"/>
		<updated>2017-06-26T15:30:37Z</updated>

		<summary type="html">&lt;p&gt;⚠️Gcmillar: Grammar&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;[[File:icc2017 logo.png|300px|right|none]]&lt;br /&gt;
[[File:Grassgis logo colorlogo text whitebg.png|250px|right|none]]&lt;br /&gt;
[[File:Blender-plain.png|300px|right|none]]&lt;br /&gt;
&lt;br /&gt;
This is material for two sessions at the [[GRASS GIS at ICC 2017|ICC 2017]] workshop called  ''Analytical data visualizations with GRASS GIS and Blender'' and ''Mapping open data with open source geospatial tools'' held in Washington, DC, July 1-2, 2017. These two sessions introduce GRASS GIS, example of its processing capabilities, and visualization techniques relevant to spatio-temporal data and high performance computing (HPC). Participants interactively visualize open data and design maps with several open source geospatial tools including Tangible Landscape system.&lt;br /&gt;
&lt;br /&gt;
We start the workshop with a [https://ncsu-geoforall-lab.github.io/ICC-workshop-presentation/index.html#/ presentation] about the overview of geospatial tools used in this workshop.&lt;br /&gt;
== Data ==&lt;br /&gt;
&lt;br /&gt;
=== Prepared data ===&lt;br /&gt;
&lt;br /&gt;
* digital elevation and surface model (1m resolution) derived from North Carolina Flood Plain Mapping lidar&lt;br /&gt;
* orthophoto (0.5m resolution) from USGS&lt;br /&gt;
&lt;br /&gt;
=== Download OpenStreetMap data ===&lt;br /&gt;
We will use [http://overpass-turbo.eu/ overpass turbo] (web-based data filtering tool) to create and run [http://wiki.openstreetmap.org/wiki/Overpass_API Overpass API] queries to obtain&lt;br /&gt;
[https://en.wikipedia.org/wiki/OpenStreetMap OpenStreetMap] data.&lt;br /&gt;
&lt;br /&gt;
You can use Wizard to create simple queries on the currently zoomed extent. For example, zoom to a small area and paste this into the Wizard and run the query:&lt;br /&gt;
 highway=* and type:way&lt;br /&gt;
&lt;br /&gt;
The query was built in the editor and ran so you can now see the results in a map.&lt;br /&gt;
&lt;br /&gt;
Now, paste this query in the editor window:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “highway=*”&lt;br /&gt;
  way[&amp;quot;highway&amp;quot;](35.76599,-78.66249,35.77230,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
It finds roads in our study area. When you run the query, the roads appear on the map and we can export them as GeoJSON (Export - Data - as GeoJSON). Name the vector file &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
Now let's also download all building footprints and again export them as GeoJSON. Name the vector file &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
[out:json][timeout:25];&lt;br /&gt;
// gather results&lt;br /&gt;
(&lt;br /&gt;
  // query part for: “building=*”&lt;br /&gt;
  way[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
  relation[&amp;quot;building&amp;quot;](35.76599,-78.66249,35.77260,-78.65261);&lt;br /&gt;
);&lt;br /&gt;
// print results&lt;br /&gt;
out body;&lt;br /&gt;
&amp;gt;;&lt;br /&gt;
out skel qt;&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the next steps we will import this data into GRASS GIS.&lt;br /&gt;
&lt;br /&gt;
== Introduction to GRASS GIS ==&lt;br /&gt;
Here we provide an overview of [https://grass.osgeo.org GRASS GIS]. For this exercise it's not necessary to have a full understanding of how to use GRASS GIS. However, you will need to know how to place your data in the correct GRASS GIS database directory, as well as some basic GRASS functionality.&lt;br /&gt;
&lt;br /&gt;
==== Structure of the GRASS GIS Spatial Database ====&lt;br /&gt;
GRASS uses unique database terminology and structure ([https://grass.osgeo.org/grass72/manuals/grass_database.html GRASS GIS Spatial Database]) that are important to understand for working in GRASS GIS efficiently. You will create a new ''location'' and import the required data into that location. In the following we review important terminology and give step by step directions on how to download and place you data in the correct place.&lt;br /&gt;
&lt;br /&gt;
* A '''GRASS GIS Spatial Database''' (''GRASS database'') consists of directory with specific Locations (projects) where data (data layers/maps) are stored.&lt;br /&gt;
* '''Location''' is a directory with data related to one geographic location or a project. All data within one Location has the same coordinate reference system.&lt;br /&gt;
* '''Mapset''' is a collection of maps within Location, containing data related to a specific task, user or a smaller project.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=1 widths=500 heights=250&amp;gt;Image:Grass database.png|GRASS GIS Spatial Database structure&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Creating a GRASS database for the tutorial ====&lt;br /&gt;
Start GRASS GIS, a start-up screen should appear.&lt;br /&gt;
Unless you already have a directory called &amp;lt;tt&amp;gt;grassdata&amp;lt;/tt&amp;gt; in your &amp;lt;tt&amp;gt;Documents&amp;lt;/tt&amp;gt; directory (on MS Windows)&lt;br /&gt;
or in your home directory (on Linux), create one. You can use the Browse button and the dialog in the GRASS GIS start up screen to do that.&lt;br /&gt;
&lt;br /&gt;
We will create a new ''location'' for our project with CRS (coordinate reference system) NC State Plane Meters with EPSG code 3358.&lt;br /&gt;
Open Location Wizard with button ''New'' in the left part of the welcome screen. Select a name for the new location, select EPSG method and code 3358.&lt;br /&gt;
When the wizard is finished, the new location will be listed on the start-up screen. Select the new location and mapset PERMANENT and press ''Start GRASS session''.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=400 heights=270&amp;gt;&lt;br /&gt;
Image:GRASS_startup_ncspm.png|GRASS GIS 7.2 startup dialog&lt;br /&gt;
Image:ICC_workshop_location_wizard_define_7.2.png| Start Location Wizard and type the new location's name&lt;br /&gt;
Image:Location_wizard_method_7.2.png| Select method for describing CRS&lt;br /&gt;
Image:Location_wizard_EPSG3358_7.2.png| Find and select EPSG 3358&lt;br /&gt;
Image:ICC_workshop_location_wizard_summary_7.2.png| Review summary page and confirm&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Importing data ====&lt;br /&gt;
[[File:Import_raster_7.2.1.png|400px|thumb|right|Import raster data]]&lt;br /&gt;
In this step we import into GRASS GIS the provided data. In menu ''File - Import raster data'' select ''Common formats import'' and in the dialog browse to find &amp;lt;tt&amp;gt;dem.tif&amp;lt;/tt&amp;gt; and click button ''Import''. Repeat for raster files &amp;lt;tt&amp;gt;dsm.tif&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt;. &lt;br /&gt;
&lt;br /&gt;
Similarly, go to ''File - Import vector data - Common formats import'' and import files &amp;lt;tt&amp;gt;roads.geojson&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings.geojson&amp;lt;/tt&amp;gt;. '''Note that in this case we need to change the output name from default &amp;lt;tt&amp;gt;OGRGeoJSON&amp;lt;/tt&amp;gt; to &amp;lt;tt&amp;gt;roads&amp;lt;/tt&amp;gt; and &amp;lt;tt&amp;gt;buildings&amp;lt;/tt&amp;gt;, respectively.''' This vector data has different CRS, so a dialog informing you about the need to reproject the data appears and we confirm it.&lt;br /&gt;
&lt;br /&gt;
All the imported layers should be added to GUI, if not, add them manually.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== Displaying and exploring data ====&lt;br /&gt;
&lt;br /&gt;
The GUI interface allows you to display raster, vector data as well as navigate through zooming in and out. More advanced exploration and visualization is also possible using, e.g., queries and adding legend. The screenshots below depicts how you can add different map layers (left) and display the metadata of your data layers.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=2  widths=500 heights=250&amp;gt;&lt;br /&gt;
Image:Wxgui_add_elev_lid.png|Add raster map layer&lt;br /&gt;
Image:Wxgui_add_legend_elev_lid.png|Add raster legend&lt;br /&gt;
Image:GRASS FUTURES wxGUI display.png|Layer Manager and Map Display overview. Annotations show how to add raster layer, query, add legend.&lt;br /&gt;
Image:wxGUI_metadata_rinfo.png|Show raster map metadata by right click on layer&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== GRASS GIS modules overview ===&lt;br /&gt;
&lt;br /&gt;
One of the advantages of GRASS is the diversity and number of modules that let you analyze all manner of spatial and temporal. GRASS GIS has over [https://grass.osgeo.org/grass70/manuals/full_index.html 500 different modules] in the core distribution and over [https://grass.osgeo.org/grass70/manuals/addons/ 230 addon modules] that can be used to prepare and analyze data layers.&lt;br /&gt;
&lt;br /&gt;
GRASS functionality is available through ''modules'' (tools, functions). Modules respect the following naming conventions: &lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&lt;br /&gt;
  {| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Prefix !! Function !! Example&lt;br /&gt;
|-&lt;br /&gt;
| r.* || raster processing || ''{{cmd|r.mapcalc}}'': map algebra&lt;br /&gt;
|-&lt;br /&gt;
| v.* || vector processing  || ''{{cmd|v.clean}}'': topological cleaning&lt;br /&gt;
|-&lt;br /&gt;
| i.* || imagery processing  || ''{{cmd|i.segment}}'': object recognition&lt;br /&gt;
|-&lt;br /&gt;
| db.* || database management || ''{{cmd|db.select}}'': select values from table&lt;br /&gt;
|-&lt;br /&gt;
| r3.* || 3D raster processing  || ''{{cmd|r3.stats}}'': 3D raster statistics&lt;br /&gt;
|-&lt;br /&gt;
| t.* || temporal data processing  || ''{{cmd|t.rast.aggregate}}'': temporal aggregation&lt;br /&gt;
|-&lt;br /&gt;
| g.* || general data management || ''{{cmd|g.rename}}'': renames map&lt;br /&gt;
|-&lt;br /&gt;
| d.* || display ||''{{cmd|d.rast}}'': display raster map&lt;br /&gt;
|}&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
These are the main groups of modules. There is few more for specific purposes. Note also that some modules have multiple dots in their names. This often suggests further grouping. For example, modules staring with ''v.net.'' deal with vector network analysis.&lt;br /&gt;
&lt;br /&gt;
The name of the module helps to understand its function, for example ''v.in.lidar'' starts with ''v'' so it deals with vector maps, the name follows with ''in'' which indicates that the module is for importing the data into GRASS GIS Spatial Database and finally ''lidar'' indicates that it deals with lidar point clouds.&lt;br /&gt;
&lt;br /&gt;
=== Finding and running a module ===&lt;br /&gt;
&lt;br /&gt;
To find a module for your analysis, type the term into the search box into the ''Modules'' tab in the ''Layer Manager'', then keep pressing Enter until you find your module. &lt;br /&gt;
&lt;br /&gt;
Alternatively, you can just browse through the module tree in the ''Modules'' tab. You can also browse through the main menu. For example, to find information about a raster map, use: ''Raster → Reports and statistics → Basic raster metadata''.&lt;br /&gt;
&lt;br /&gt;
If you already know the name of the module, you can just use it in the command line. The GUI offers a Command console tab with command line specifically build for running GRASS GIS modules. If you type module name there, you will get suggestions for automatic completion of the name. After pressing Enter, you will get GUI dialog for the module.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:wxGUI_module_search.png|Search for a module in module tree (searches in names, descriptions and keywords)&lt;br /&gt;
Image:wxGUI_menu_rinfo.png|Modules can be also found in the main menu&lt;br /&gt;
Image:wxGUI_console_completion.png|Automatic suggestions when typing name of the module: By typing prefix r. we make a list of modules starting with that prefix to show up.&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
You can use the command line to run also whole commands for example when you get a command, i.e. module and list of parameters, in the instructions.&lt;br /&gt;
&lt;br /&gt;
=== Command line vs. GUI interface ===&lt;br /&gt;
[[File:Wxgui_module_parameters_r_neighbors.png|400px|thumb|right| Module dialog]]&lt;br /&gt;
GRASS modules can be executed either through a GUI or command line interface. The GUI offers a user-friendly approach to executing modules where the user can navigate to data layers that they would like to analyze and modify processing options with simple check boxes. The GUI also offers an easily accessible manual on how to execute a model. The command line interface allows users to execute a module using command prompts specific to that module. This is handy when you are running similar analyses with minor modification or are familiar with the module commands for quick efficient processing. In this workshop we provide module prompts that can be copy and pasted into the command line for our workflow, but you can use both GUI and command line depending on personal preference. Look how {{cmd|wxGUI.modules|version=71|desc=GUI and command line interface}} represent the same tool.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The same analysis can be done using the following command:&lt;br /&gt;
&lt;br /&gt;
 r.neighbors -c input=elevation output=elev_smooth size=5&lt;br /&gt;
&lt;br /&gt;
Conversely, you can fill the GUI dialog parameter by parameter when you have the command.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Computational region ===&lt;br /&gt;
&lt;br /&gt;
Before we use a module to compute a new raster map, we must set properly computational region. All raster computations will be performed in the specified extent and with the given resolution.&lt;br /&gt;
&lt;br /&gt;
Computational region is an important raster concept in GRASS GIS. In GRASS a computational region can be set, subsetting larger extent data for quicker testing of analysis or analysis of specific regions based on administrative units. We provide a few points to keep in mind when using the computational region function:&lt;br /&gt;
* defined by region extent and raster resolution&lt;br /&gt;
* applies to all raster operations&lt;br /&gt;
* persists between GRASS sessions, can be different for different mapsets&lt;br /&gt;
* advantages: keeps your results consistent, avoid clipping, for computationally demanding tasks set region to smaller extent, check your result is good and then set the computational region to the entire study area and rerun analysis&lt;br /&gt;
* run &amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt; or in menu ''Settings'' - ''Region'' - ''Display region'' to see current region settings&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Computational_region_two_rasters.png|Computational region concept: A raster with large extent (blue) is displayed as well as another raster with smaller extent (green). The computational region (red) is now set to match the smaller raster, so all the computations are limited to the smaller raster extent even if the input is the larger raster. (Not shown on the image: Also the resolution, not only the extent, matches the resolution of the smaller raster.)&lt;br /&gt;
Image:WxGUI set region.png|Simple ways to set computational region from GUI. On the left, set region to match raster map. On the right, select the highlighted option and then set region by drawing rectangle.&lt;br /&gt;
Image:Wxgui_computational_region_set_from_raster.png|Set computational region (extent and resolution) to match a raster (''Layers'' tab in the ''Layer Manager'')&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numeric values of computational region can be checked using:&lt;br /&gt;
&lt;br /&gt;
 g.region -p&lt;br /&gt;
&lt;br /&gt;
After executing the command you will get something like this:&lt;br /&gt;
&lt;br /&gt;
 north:      220750&lt;br /&gt;
 south:      220000&lt;br /&gt;
 west:       638300&lt;br /&gt;
 east:       639000&lt;br /&gt;
 nsres:      1&lt;br /&gt;
 ewres:      1&lt;br /&gt;
 rows:       750&lt;br /&gt;
 cols:       700&lt;br /&gt;
 cells:      525000&lt;br /&gt;
&lt;br /&gt;
Computational region can be set using a raster map:&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm -p&lt;br /&gt;
&lt;br /&gt;
=== Running modules ===&lt;br /&gt;
&lt;br /&gt;
Find the module for computing viewshed in the menu or the module tree under ''Raster → Terrain analysis → Visibility'' or simply run {{cmd|r.viewshed}} from the ''Console''.&lt;br /&gt;
&lt;br /&gt;
 r.viewshed input=dsm output=viewshed coordinates=640167,223907 observer_elevation=1.72 target_elevation=1 max_distance=400&lt;br /&gt;
&lt;br /&gt;
=== 3D view ===&lt;br /&gt;
[[File:ICC_workshop_3Dview_ortho.png|800px|thumb|right| 3D visualization of DSM with orthophoto draped over]]&lt;br /&gt;
We can explore our study area in 3D view.&lt;br /&gt;
# Add raster &amp;lt;tt&amp;gt;dsm&amp;lt;/tt&amp;gt; and '''uncheck or remove''' any other layers. Any layer in Layer Manager is interpreted as surface in 3D view.&lt;br /&gt;
# Switch to 3D view (in the right corner of Map Display).&lt;br /&gt;
# Adjust the view (perspective, height).&lt;br /&gt;
# In ''Data'' tab, set ''Fine mode resolution'' to 1 and set &amp;lt;tt&amp;gt;ortho&amp;lt;/tt&amp;gt; as the color of the surface (the orthophoto is draped over the DSM).&lt;br /&gt;
# Go back to ''View'' tab and explore the different view directions using the green puck.&lt;br /&gt;
# Go again to ''Data'' tab and change color to &amp;lt;tt&amp;gt;viewshed&amp;lt;/tt&amp;gt; raster computed in the previous steps.&lt;br /&gt;
# Go to ''Appearance'' tab and change the light conditions (lower the light height, change directions).&lt;br /&gt;
# When finished, switch back to 2D view.&lt;br /&gt;
&amp;lt;br clear=all&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to scripting in GRASS GIS with Python ==&lt;br /&gt;
&lt;br /&gt;
The simplest way to execute the Python code which uses GRASS GIS packages is to use Simple Python editor integrated in GRASS GIS accessible from the toolbar or the Python tab in the Layer Manager. Another option is to write the Python code in your favorite plain text editor like Notepad++ (note that Python editors are plain text editors). Then run the script in GRASS GIS using the main menu File -&amp;gt; Launch script.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;center&amp;gt;&amp;lt;gallery perrow=3 widths=380 heights=190&amp;gt;&lt;br /&gt;
Image:Simple python editor v buffer.png|''Simple Python Editor'' integrated in GRASS GIS (since version 7.2) with ''Python'' tab in the background which contains an interactive Python shell.&lt;br /&gt;
Image:GRASS GUI Python shell.png|''Python'' tab with an interactive Python shell&lt;br /&gt;
&amp;lt;/gallery&amp;gt;&amp;lt;/center&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
The GRASS GIS 7 Python Scripting Library provides functions to call GRASS modules within scripts as subprocesses. The most often used functions include:&lt;br /&gt;
* '''{{pyapi|script|script.core|run_command}}''': most often used with modules which output raster/vector data where text output is not expected&lt;br /&gt;
* '''{{pyapi|script|script.core|read_command}}''': used when we are interested in text output&lt;br /&gt;
* '''{{pyapi|script|script.core|parse_command}}''': used with modules producing text output as key=value pair&lt;br /&gt;
* '''{{pyapi|script|script.core|write_command}}''': for modules expecting text input from either standard input or file&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We will use GRASS GUI Simple Python Editor to run the commands. You can open it from Python tab.&lt;br /&gt;
For longer scripts, you can create a text file, save it into your current working directory and run it with &amp;lt;tt&amp;gt;python myscript.py&amp;lt;/tt&amp;gt; from the GUI command console or terminal.&lt;br /&gt;
&lt;br /&gt;
When you open Simple Python Editor, you find a short code snippet.&lt;br /&gt;
It starts with importing GRASS GIS Python Scripting Library:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In the main function we call {{cmd|g.region}} to see the current computational region settings:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', flags='p')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Note that the syntax is similar to bash syntax (&amp;lt;code&amp;gt;g.region -p&amp;lt;/code&amp;gt;), just the flag is specified in a parameter. Now we can run the script by pressing the Run button in the toolbar. In Layer Manager we get the output of g.region.&lt;br /&gt;
&lt;br /&gt;
Before running any GRASS raster modules, you need to set the computational region. In this example, we set the computational extent and resolution to the raster layer &amp;lt;tt&amp;gt;elevation&amp;lt;/tt&amp;gt;.&lt;br /&gt;
Replace the previous g.region command with the following line:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('g.region', raster='dsm')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The run_command() function is the most commonly used one. We will use it to compute viewshed using {{cmd|r.viewshed}}.&lt;br /&gt;
Add the following line after g.region command:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
gscript.run_command('r.viewshed', input='dsm', output='viewshed_python', coordinates=TODO, overwrite=True)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Parameter &amp;lt;code&amp;gt;overwrite&amp;lt;/code&amp;gt; is needed if we rerun the script and rewrite the raster. Now let's look at how big the viewshed is by using&lt;br /&gt;
{{cmd|r.univar}}. Here we use &amp;lt;code&amp;gt;parse_command&amp;lt;/code&amp;gt; to obtain the statistics as a Python dictionary&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
univar = gscript.parse_command('r.univar', map='viewshed_python', flags='g')&lt;br /&gt;
print univar['n']&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The printed result is the number of cells of the viewshed.&lt;br /&gt;
&lt;br /&gt;
GRASS GIS Python Scripting Library also provides several wrapper functions for often called modules. List of convenient wrapper functions with examples:&lt;br /&gt;
* Raster metadata using {{pyapi|script|script.raster|raster_info}}: &amp;lt;code&amp;gt;gscript.raster_info('viewshed_python')&amp;lt;/code&amp;gt;&lt;br /&gt;
* Vector metadata using {{pyapi|script|script.vector|vector_info}}: &amp;lt;code&amp;gt;gscript.vector_info('roads')&amp;lt;/code&amp;gt;&lt;br /&gt;
* List raster data in current location using {{pyapi|script|script.core|list_grouped}}: &amp;lt;code&amp;gt;gscript.list_grouped(type=['raster'])&amp;lt;/code&amp;gt;&lt;br /&gt;
* Get current computational region using {{pyapi|script|script.core|region}}: &amp;lt;code&amp;gt;gscript.region()&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Here are two commands (to be executed in the ''Console'') often used when working with scripts. First is setting the computational region. We can do that in a script, but it better and more general to do it before executing the script (so that the script can be used with different computational region settings):&lt;br /&gt;
&lt;br /&gt;
 g.region raster=dsm&lt;br /&gt;
&lt;br /&gt;
The second command is handy when we want to run the script again and again. In that case, we first need to remove the created raster maps, for example:&lt;br /&gt;
&lt;br /&gt;
 g.remove type=raster pattern=&amp;quot;viewshed*&amp;quot;&lt;br /&gt;
&lt;br /&gt;
The above command actually won't remove the maps, but it will inform you which it will remove if you provide the &amp;lt;tt&amp;gt;-f&amp;lt;/tt&amp;gt; flag.&lt;br /&gt;
&lt;br /&gt;
== Batch processing using Python ==&lt;br /&gt;
In this example, we will calculate the viewsheds along a road to simulate in a simple way what a driver would see.&lt;br /&gt;
&lt;br /&gt;
First we extract only segments of road with name 'Umstead Drive':&lt;br /&gt;
&lt;br /&gt;
 v.extract input=roads where=&amp;quot;name = 'Umstead Drive'&amp;quot; output=umstead_drive_segments&lt;br /&gt;
&lt;br /&gt;
We will join the segments into one polyline using {{cmd|v.build.polylines}}&lt;br /&gt;
&lt;br /&gt;
 v.build.polylines input=umstead_drive_segments output=umstead_drive cats=first&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Now we generate viewpoints in regular intervals along the line:&lt;br /&gt;
&lt;br /&gt;
 v.to.points input=umstead_drive type=line output=viewpoints dmax=50&lt;br /&gt;
&lt;br /&gt;
We compute viewshed from each point using a Python script.&lt;br /&gt;
From these viewsheds we can then easily compute ''Cumulative viewshed'' (how much a place is visible).&lt;br /&gt;
For that we will use module {{cmd|r.series}}, which overlays the viewshed rasters and computes how many times each cell is visible in all the rasters.&lt;br /&gt;
&lt;br /&gt;
Copy the following code&lt;br /&gt;
into Python Simple Editor and press Run button.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
def main():&lt;br /&gt;
    # obtain the coordinates of viewpoints&lt;br /&gt;
    viewpoints = gscript.read_command('v.out.ascii', input='viewpoints',&lt;br /&gt;
                                      separator='comma', layer=2).strip()&lt;br /&gt;
    # loop through the viewpoints and compute viewshed from each of them&lt;br /&gt;
    for point in viewpoints.splitlines():&lt;br /&gt;
        x, y, cat = point.split(',')&lt;br /&gt;
        gscript.run_command('r.viewshed', input='dsm', output='viewshed' + cat,&lt;br /&gt;
                            coordinates=(x, y), max_distance=300, overwrite=True)&lt;br /&gt;
    # obtain all viewshed results and set their color to yellow&lt;br /&gt;
    # export the list of viewshed map names to a file&lt;br /&gt;
    maps_file = 'viewsheds.txt'&lt;br /&gt;
    gscript.run_command('g.list', type='raster', pattern='viewshed*', output=maps_file)&lt;br /&gt;
    gscript.write_command('r.colors', file=maps_file, rules='-',&lt;br /&gt;
                          stdin='0% yellow \n 100% yellow')&lt;br /&gt;
    # cumulative viewshed&lt;br /&gt;
    gscript.run_command('r.series', file='viewsheds.txt', output='cumulative_viewshed', method='count')&lt;br /&gt;
    # set color of cumulative viewshed from grey to yellow&lt;br /&gt;
    gscript.write_command('r.colors', map='cumulative_viewshed', rules='-',&lt;br /&gt;
                          stdin='0% 70:70:70 \n 100% yellow')&lt;br /&gt;
&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
    main()&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We can visualize the cumulative viewshed draped over the DSM using 3D view. If needed review the instructions in [[#3D_view| previous section about 3D view]].&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:cumulative_viewshed.png|800px|thumb|center| Cumulative viewshed computed along a road]]&lt;br /&gt;
&lt;br /&gt;
To proceed with the next part, we will export the viewpoints and cumulative viewshed in order for Blender to use it.&lt;br /&gt;
Copy and paste the individual lines to GRASS GUI command console and execute them '''separately''', omit the lines starting with #.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# turn 2D points into 3D using the DSM information&lt;br /&gt;
v.drape input=viewpoints output=viewpoints_3d elevation=dsm method=bilinear&lt;br /&gt;
# export them, ignore errors coming from too long attribute column names&lt;br /&gt;
v.out.ogr input=viewpoints_3d output=viewpoints_3d.shp format=ESRI_Shapefile&lt;br /&gt;
# export cumulative viewshed as PNG&lt;br /&gt;
r.out.gdal input=cumulative_viewshed output=cumulative_viewshed.png format=PNG&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction to Blender ==&lt;br /&gt;
Materials for the Blender part of this workshop are available here:&lt;br /&gt;
&lt;br /&gt;
https://github.com/ptabriz/ICC_2017_Workshop&lt;br /&gt;
&lt;br /&gt;
== Animation in GRASS GIS ==&lt;br /&gt;
In the following exercise we will visualize the viewsheds along the road (we computed above) as an animation. We will use {{cmd|g.gui.animation|desc=GRASS GIS Animation Tool}}. Start it from menu ''File - Animation Tool'':&lt;br /&gt;
[[File:futures_anim_start_animation_tool.png|thumb|none|Animation tool in the main menu]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Start with ''Add new animation'' and click on ''Add space-time dataset or series of map layers''. In the ''Add space-time dataset layer'' click on a button next to the entry field and type &amp;lt;tt&amp;gt;^viewshed&amp;lt;/tt&amp;gt;.&lt;br /&gt;
This filters the rasters which start with &amp;quot;viewshed&amp;quot;. Confirm the dialog and return to the dialog ''Add new animation''.&lt;br /&gt;
&lt;br /&gt;
Next we want to add orthophoto as base layer. Use ''Add raster map layer'' and select raster ortho.&lt;br /&gt;
&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:animation_tool_add_multiple_rasters.png|thumb|none|700px|Add series of viewsheds rasters to animation tool.]]&lt;br /&gt;
| [[File:Animation_tool_add_base_raster.png|thumb|none|700px|Add ortho as base raster]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Do the same for the road vector &amp;lt;tt&amp;gt;umstead_drive&amp;lt;/tt&amp;gt;, just instead of raster, add vector. Then rearrange the layers so that the ortho is below all other layers.&lt;br /&gt;
Confirm the dialog and the animation should be loaded.&lt;br /&gt;
{|style=&amp;quot;margin: 0 auto;&amp;quot;&lt;br /&gt;
| [[File:Animation_tool_layers.png|thumb|none|500px|Change the order of layers]]&lt;br /&gt;
| [[File:Animation_tool_viewsheds.png|thumb|none|500px|Resulting animation]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Further exploration:&lt;br /&gt;
* If you want to zoom in, go back to Map Display, and set the computational region to the extent you want using toolbar button 'Various zoom options - Set computational region extent interactively'. Then press ''Render map'' in the Animation tool toolbar and it will re-render the animation based on the current computational region extent.&lt;br /&gt;
&lt;br /&gt;
== Scripting of rendering in GRASS GIS ==&lt;br /&gt;
&lt;br /&gt;
Rendering of maps can be done in GRASS GIS using Python API in way which follows what is done in the GUI. Similarly to running the processing modules, GUI dialogs have a ''Copy'' button which will put a command line equivalent of what is current set in the GUI dialog. For example, a raster properties dialog can give the code: &amp;lt;code&amp;gt;d.rast map=viewshed&amp;lt;/code&amp;gt;. This code is written in Python syntax as &amp;lt;code&amp;gt;run_command('d.rast', map='viewshed')&amp;lt;/code&amp;gt;. In addition to the rendering commands, we need to specify where (filename) and how (e.g. file format) to render this can be done using the {{cmd|d.mon}} command as below or environmental variables (in GUI we don't need to say anything because the context is clear). A full example follows.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import grass.script as gscript&lt;br /&gt;
&lt;br /&gt;
viewsheds = gscript.list_strings(type=['raster'], pattern='viewshed*')&lt;br /&gt;
&lt;br /&gt;
for viewshed in viewsheds:&lt;br /&gt;
    # drop mapset name from the image file name&lt;br /&gt;
    filename = '{}.png'.format(viewshed.split('@')[0])&lt;br /&gt;
    # begin rendering&lt;br /&gt;
    gscript.run_command('d.mon', start='cairo', output=filename)&lt;br /&gt;
    # rendering commands&lt;br /&gt;
    gscript.run_command('d.rast', map='ortho')&lt;br /&gt;
    gscript.run_command('d.vect', map='umstead_drive', color='232:232:232', width=3)&lt;br /&gt;
    gscript.run_command('d.rast', map=viewshed)&lt;br /&gt;
    # end rendering&lt;br /&gt;
    gscript.run_command('d.mon', stop='cairo')&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The numbers &amp;lt;code&amp;gt;232:232:232&amp;lt;/code&amp;gt; in the {{cmd|d.vect}} call are GRASS RGB triplet, i.e. red, green, and blue colors expressed as numbers from 0 to 255 separated by colon (an equivalent using HTML syntax would be &amp;lt;code&amp;gt;rgb(232,232,232)&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;#E8E8E8&amp;lt;/code&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
Information for scripting, parallelization, and supercomputing: In scripting, the {{cmd|d.mon}} is actually often not used because only one monitor can be active. This is very convenient simplification for interactive use, but limiting for scripting. When the rendering runs in parallel, it is necessary to use environmental {{cmd|variables}} instead of the {{cmd|d.mon}} module. Variables are set globally (using &amp;lt;code&amp;gt;os.environ&amp;lt;/code&amp;gt; dictionary) or for each function call (using &amp;lt;code&amp;gt;env&amp;lt;/code&amp;gt; parameter). The following three variables are the most important: &amp;lt;tt&amp;gt;GRASS_RENDER_IMMEDIATE&amp;lt;/tt&amp;gt; (usually set to &amp;lt;tt&amp;gt;cairo&amp;lt;/tt&amp;gt;), &amp;lt;tt&amp;gt;GRASS_RENDER_FILE_READ&amp;lt;/tt&amp;gt; (set to &amp;lt;tt&amp;gt;TRUE&amp;lt;/tt&amp;gt;), and &amp;lt;tt&amp;gt;GRASS_RENDER_FILE&amp;lt;/tt&amp;gt; (resulting image filename). Additional variables include &amp;lt;tt&amp;gt;GRASS_FONT&amp;lt;/tt&amp;gt; (name of the font to be used, e.g. sans) and &amp;lt;tt&amp;gt;GRASS_LEGEND_FILE&amp;lt;/tt&amp;gt; (file for vector legend, can be path to a temporary file).&lt;br /&gt;
&lt;br /&gt;
Further exploration: &lt;br /&gt;
* Use roads vector map instead of just umstead_drive.&lt;br /&gt;
* Add buildings vector map in the same way as the roads. This time, you need to set two color options: color (for outline) and fill_color (for inner part). Use the vector map layer properties dialog in GUI to create the desired styling. Use the Copy button to get parameters in the command line syntax and rewrite it to Python. You can also just use the following colors: 188:82:47, 213:115:82 (#BC522F, #D57352) or 170:166:157, 213:205:189 (#AAA69D, #D5CDBD).&lt;br /&gt;
* If you have ImageMagic available, create an animated GIF using something like: &amp;lt;code&amp;gt;convert 'viewshed?.png' 'viewshed??.png' viewshed.gif&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Software ==&lt;br /&gt;
Software should be pre-installed at ICC, but the following instructions can be used to install software on participants' laptops.&lt;br /&gt;
&lt;br /&gt;
We use GRASS GIS 7.2 and Blender 2.78.&lt;br /&gt;
&lt;br /&gt;
'''MS Windows'''&lt;br /&gt;
&lt;br /&gt;
Then download standalone GRASS GIS binaries ([https://grass.osgeo.org/grass72/binary/mswindows/native/x86_64/WinGRASS-7.2.1-1-Setup-x86_64.exe 64-bit version], or [https://grass.osgeo.org/grass72/binary/mswindows/native/x86/WinGRASS-7.2.1-1-Setup-x86.exe 32-bit version]) from [https://grass.osgeo.org/ grass.osgeo.org].&lt;br /&gt;
During the installation you can also download North Carolina sample dataset so please select this option. You can also download the dataset later (see the following section).&lt;br /&gt;
&lt;br /&gt;
'''Mac OS'''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS using [https://brew.sh/ Homebrew] [https://github.com/OSGeo/homebrew-osgeo4mac osgeo4mac]:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
brew tap osgeo/osgeo4mac&lt;br /&gt;
brew install grass7&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
'''OSGeo-Live'''&lt;br /&gt;
&lt;br /&gt;
All needed software is included except for Blender.&lt;br /&gt;
&lt;br /&gt;
''' Ubuntu '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
''' Linux '''&lt;br /&gt;
&lt;br /&gt;
Install GRASS GIS from packages:&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable&lt;br /&gt;
sudo apt-get update&lt;br /&gt;
sudo apt-get install grass&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
For other Linux distributions other then Ubuntu, please try to find GRASS GIS in their package managers.&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[GRASS GIS at ICC 2017]]&lt;br /&gt;
* [[Unleash the power of GRASS GIS at US-IALE 2017]]&lt;br /&gt;
* [[Creating animation from FUTURES output in GRASS GIS]]&lt;br /&gt;
* [[Introduction to GRASS GIS with terrain analysis examples]]&lt;br /&gt;
* [[GRASS Location Wizard]]&lt;br /&gt;
&lt;br /&gt;
[[Category: Tutorial]]&lt;br /&gt;
[[Category: Workshops]]&lt;br /&gt;
[[Category: 2017]]&lt;/div&gt;</summary>
		<author><name>⚠️Gcmillar</name></author>
	</entry>
</feed>