Quick wxGUI tutorial: Difference between revisions
(Created page with '<font color="#409840">_\|/_ GRASS 6.4.0 _\|/_</font> ==About== [http://grass.osgeo.org GRASS] (Geographic Resources Analysis Support System) is a raster/vector GIS, image proces…') |
(Define region first when creating new fractal surface map) |
||
(38 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
<font color="#409840">_\|/_ GRASS 6.4 | <!-- <center><font color="#409840">_\|/_ GRASS 6.4 _\|/_</font></center> --> | ||
==About== | ==About== | ||
[http://grass.osgeo.org GRASS] (Geographic Resources Analysis | [http://grass.osgeo.org GRASS] ('''Geographic Resources Analysis Support System''') is a raster/vector GIS, image processing system, and graphics | ||
Support System) is a raster/vector GIS, image processing system, and graphics | |||
production system. GRASS contains over 400 programs and tools to render maps | production system. GRASS contains over 400 programs and tools to render maps | ||
and images on monitor and paper; manipulate raster, vector, and sites data; | and images on monitor and paper; manipulate raster, vector, and sites data; | ||
Line 11: | Line 10: | ||
plotters, digitizers, and databases to develop new data as well as manage | plotters, digitizers, and databases to develop new data as well as manage | ||
existing data. | existing data. | ||
[[Image:grass-startup.png|400px|center]] | |||
== Setup == | |||
This tutorial assumes that you've already [http://grass.osgeo.org/download/ installed GRASS GIS], and have downloaded either the [http://grass.osgeo.org/download/sample-data/ North Carolina sample datasets] from our download web page. You'll want to uncompress them first, ideally into a directory called "grassdata" in your home directory. | |||
Almost all the [http://grass.osgeo.org/documentation/manuals/ help pages], [http://grass.osgeo.org/documentation/tutorials/ tutorials], and [http://grass.osgeo.org/documentation/books/ books] use these two datasets in their examples, so they are worth grabbing. | |||
==Running== | ==Running== | ||
To run GRASS | |||
From the "Welcome to GRASS" window select either the Spearfish or North Carolina (nc_spm_08) | To run GRASS, click on the GRASS link on the desktop or from the system menu. From the "Welcome to GRASS" window select either the Spearfish or North Carolina (nc_spm_08) sample datasets for the location, and "user1" for the mapset, then click on [Start Grass]. | ||
then click on [Start Grass]. | |||
This will launch GRASS with our [[wxGUI|brand new GUI written in wxPython]]. | |||
<!-- | |||
This will launch GRASS with our brand new GUI written in wxPython. At | This will launch GRASS with our brand new GUI written in wxPython. At | ||
the time of writing we have gotten just about all of the kinks out of | the time of writing we have gotten just about all of the kinks out of | ||
Line 22: | Line 30: | ||
Tcl/Tk GUI is still available if you prefer to use that; you can start | Tcl/Tk GUI is still available if you prefer to use that; you can start | ||
it by typing <em>g.gui --ui</em> on the command line. | it by typing <em>g.gui --ui</em> on the command line. | ||
--> | |||
===Displaying maps=== | ===Displaying maps=== | ||
[[Image:grass-layerman.png|400px|center]] | |||
Once inside add a raster map layer such as "elevation" from the PERMANENT | Once inside add a raster map layer such as "elevation" from the PERMANENT | ||
mapset. To do this click on the checkerboard toolbar button with a "+" on | mapset. To do this click on the checkerboard toolbar button with a "+" on | ||
Line 38: | Line 50: | ||
===Plot an elevation profile=== | ===Plot an elevation profile=== | ||
[[Image:grass-profile.png|400px|center]] | |||
Back in the GIS Layer Manager window click on the elevation raster | Back in the GIS Layer Manager window click on the elevation raster | ||
map name to select it. Then in the Map Display window, to the right of the | map name to select it. Then in the Map Display window, to the right of the | ||
Line 50: | Line 65: | ||
===Create a random surface=== | ===Create a random surface=== | ||
Now let's create a new raster map. | |||
We first define the extent and resolution of this map. For simplicity, we select a predefined region with the spatial extent of Wake county, Raleigh (NC, USA) and spatial resolution of 30m: Select <tt>Settings → Region → Set region</tt> from the main menu. In this dialog window, select 'wake_30m' for the parameter <tt>Set current region from named region</tt>; and click [Run] (i.e, it defines the [[Computational region]] for raster computations). | |||
Now select <tt>Raster → Generate surfaces → Fractal surface</tt> from the menu (near the bottom); | |||
give your new map a name; adjust any options you like in the Options | |||
tab (the defaults are fine); and click [Run]. | |||
[[Image:grass-fractal.png|400px|center]] | |||
===Adjust colors=== | |||
Now add your new raster layer to the layer list as you did before with | |||
the elevation raster map, except this time it will be in your "user1" | |||
working mapset. You might un-tick the elevation layer check-box | |||
now so that the two don't draw over the top of each other. Click on the | |||
eyeball to view your new map. | |||
The colors might not be as you'd like so let's change them. In the <tt>Raster</tt> menu select <tt>Manage colors → Color Tables</tt>. | |||
In the "Colors" tab click on the pull-down list for the "Type of color | |||
table" option, and pick one from the list. "srtm" is a nice choice. Once | |||
done click the [Run] button and close the <em>r.colors</em> dialog window. | |||
Because you have altered the map's metadata, this time to re-render it | |||
you will have to fully flush the display cache. So click on the little | |||
refresh button next to the eyeball button to re-render all layers and you | |||
should see your map with its new colors. | |||
===Create a shaded relief map=== | |||
[[Image:grass-shadedrelief.png|400px|center]] | |||
Next we'll create a shaded relief map of the elevation layer we saw | |||
earlier. Start by selecting the elevation @PERMANENT map from before | |||
by clicking on its name. In the <tt>Raster</tt> menu select <tt>Terrain | |||
analysis → Shaded relief</tt> (Terrain analysis is about half way | |||
down), and the module control dialog will appear. With the elevation | |||
map name selected as the input map click [Run]. Now add the new | |||
elevation.shade @user1 map into your layer list and un-tick the other | |||
raster layers, then click the eyeball to re-render. (If you get sick of | |||
clicking the eyeball all the time you can tick the "Render" box in the | |||
bottom right of the Map Display window to have that happen automatically) | |||
===Watersheds and streams=== | |||
Once again select the elevation @PERMANENT map and in the Raster menu | |||
choose <tt>Hydrologic modeling → Watershed analysis</tt>. Set | |||
the elevation layer as your input map, in the 'Input Options' tab | |||
set the sub-basin threshold to 10000 cells, then in the 'Output Options' | |||
tab enter "elev.basins" for the watershed basin option and "elev.streams" | |||
for the stream segments option just below it. Then click [Run]. | |||
[[Image:grass-watersheds.png|400px|center]] | |||
Back in the Layer Manager window add those two new raster maps to the | |||
layer list and make sure that they are the only two which are ticked | |||
for display in the box to the left of the layer name. Right click on | |||
the elev.basins raster map layer name and select "Change opacity level". | |||
Set it to about 50% then re-render the Map Display. | |||
In the GIS Layer Manager window click on the third button in from the | |||
right to add a grid layer. For size of grid put 0:03 for 0 degrees and | |||
3 minutes (format is D:M:S), then in the "Optional" tab tick Draw | |||
geographic grid and press [Run] and re-render. | |||
To add a scalebar go to the Map Display window and press the "Add | |||
Overlay" button to the right of where you selected the Profile tool | |||
earlier and select "Add scalebar and north arrow". Read the instructions | |||
then click [Ok]. A scalebar will appear in the top right. Drag it down | |||
to the bottom left. From the same toolbar menu select "Add legend" and | |||
in the instructions window click the Set Options button to set the | |||
raster map name to create the legend for. After picking one click [Ok] | |||
and [Ok] again. | |||
Now you may be thinking to yourself that these fonts are a bit bare. | |||
That's easily fixed in the GIS Layer Manager menus open <tt>Config → | |||
Preferences</tt> and in the Display tab click the [Set font] button and | |||
then [Apply] in the Preferences window. You will have to do a full | |||
re-render to see the change so click on the re-render button next to the | |||
eyeball. The fonts will now be much prettier. | |||
===Vector modules=== | |||
[[Image:grass-vectattrib.png|400px|right]] | |||
The above tasks have only covered a few raster modules. Don't let this | |||
give you the idea that GRASS is just for raster maps -- the vector engine | |||
and modules are every bit as full-featured as the raster ones. GRASS | |||
maintains a fully topological vector system which allows all sorts of | |||
very powerful analyses. | |||
Continuing with the watershed basins created above, next we'll convert them into vector polygons. In the Raster menu select 'Map type conversions → Raster to vector'. In the {{Cmd|r.to.vect}} dialog that opens make sure that ''basins @user1'' is selected for the input map, give a name for the output map like ''basins_areas'' (vector map names must be SQL compliant), and change feature type to 'area'. In the Attributes tab tick the box to use raster values as category numbers, since these will match the values in our stream segment raster map created earlier. Then click on [Run]. Once the new vector map is displayed, you might right click on it in the Layer Manager list and change its opacity level. Also if you right click on the ''basins_areas'' vector map in the 'Layer List' you can turn off rendering of area centroids by going into 'Properties' and un-ticking it in the 'Selection' tab. | |||
Next we'll add some attributes to those new areas, containing the average elevation in each basin. In the Vector menu select 'Update attributes → Update area attributes from raster' to launch the {{Cmd|v.rast.stats}} module. Use ''basin_areas'' as the vector polygon map, the 'elevation' raster to calculate the statistics from, make the column prefix ''elev'', and click [Run] then close the dialog when it is finished. You can query the values in the 'Map Display' window using the fifth icon from the left and after verifying that the vector-areas map is selected in the 'Layer List', clicking on a vector area in the map canvas. | |||
You can colorize the areas based on the average elevation values using the {{Cmd|v.colors}} module. In the Vector menu select 'Manage colors → Color tables'. Select ''basin_areas'' for the input vector map, the ''elev_mean'' attribute column for the column containing the numeric range, and in the 'Colors' tab have it copy the colors from the 'elevation' raster map. After running that right-click on the ''basin_areas'' map in the Layer List and select 'Properties'. In the 'Colors' tab tick the box for getting colors from the map table column. Once you click [Apply] you should see the colors change in the 'Map Display' window. | |||
Now let's look at the attribute table and SQL builder in more detail. In the 'Layer Manager' click the table icon, it's second from the left on the bottom row. This will open a view of the attached database table. For now we'll just do a simple database query to find watershed basins without a lot of variation in them. Where it says ''SELECT * FROM basin_areas WHERE'' pick ''elev_stdde'' from the pull down list for the standard deviation statistic, then in the text box to its right enter ''< 50'' and click [Apply]. You'll notice the number of loaded records in the information bar along the bottom of the window has shrunk, and that all of the rows with large values for std. dev. are now gone from the displayed table. Right-click on the table data and choose ''Select all''. Again right-click on the table data and this time choose ''Highlight selected features''. You should see e.g. alluvial flood basins and mesas show up in the ''Map Display''. | |||
===3D visualization=== | |||
[[Image:grass-nviz.png|400px|right]] | |||
Start the 3D visualization suite from the <tt>File → NVIZ</tt> | |||
menu item and have fun exploring. You will have to select those raster | |||
and vector maps again from the Raster and Vector tabs. | |||
Select <tt>Visualize→Raster Surfaces</tt> from the menu, and | |||
set the fine resolution to "1", then move the positioning puck and height slider around to get different views. | |||
===Other things to try=== | |||
While not covered here, you may like to experiment with the new Cartographic Composer and object-oriented Graphical Modeling Tool; you'll find icons to launch them on the lower row of icons in the ''Layer Manager'' window. Further details can be found in [[wxGUI]] help pages. | |||
The new GUI is written in Python, and if you're a fan of Python programming there are a number of great tools available to you. In the bottom of the 'Layer Manager' window click on the 'Python shell' tab and type ''help(grass.core)'' to see a listing of the functions available in the core GIS python library. Besides the core GIS functions there is also 'array' (NumPy), 'db' (database), 'raster', and 'vector' libraries available. For advanced use 'Pythons CTypes' is supported allowing the Python programmer access to GRASS's extensive C libraries. | |||
===Shutdown and the command line=== | |||
When finished, exit the GRASS GUI with <tt>File→Exit</tt>. | |||
Before you close the GRASS terminal session as well, try a GRASS | |||
module by typing "<tt>g.manual --help</tt>" which will give you a list | |||
of module options. The GRASS command line is where the true power of | |||
the GIS comes into its own. GRASS is designed to allow all commands | |||
to be tied together in scripts for large bulk processing jobs. Popular | |||
scripting languages are Bourne Shell and Python and some neat tricks | |||
are included for both to make this scripting easier. | |||
"<tt>g.manual -i</tt>" will launch a web browser | |||
with the module help pages. When done close the browser and type "exit" | |||
at the GRASS terminal prompt to leave the GIS environment. | |||
==Creating a new GRASS Location from pre-existing data== | |||
The GRASS location wizard enables you to create a new location in a few simple steps. It provides a number of ways to set the map projection: from a geodata file (Shapefile, GeoTIFF etc), using an EPSG code, setting projection and datum parameters manually, etc. | |||
[[Image:Grass64 location wiz1.png|300px|thumb|center|GRASS Location Wizard: user choices]] | |||
For a graphical guide, read on at [[GRASS Location Wizard]]. | |||
==Further reading== | |||
* Visit the GRASS website at http://grass.osgeo.org | |||
* Visit the GRASS Wiki help site at http://grasswiki.osgeo.org/wiki | |||
* [http://grass.osgeo.org/grass64/manuals/helptext.html How to start with GRASS] | |||
* More tutorials and overviews can be found [[GRASS_Help#Getting_Started|here]]. | |||
* Synopsis of GRASS modules, including menu positions ({{website|gdp/grassmanuals/grass64_module_list.pdf|PDF, 100k}}) ({{website|gdp/grassmanuals/grass64_module_list.html|HTML version}}) (slightly outdated) | |||
* If the 400 GIS modules which come with GRASS aren't enough for you have a look at the many contributed add-ons at [[AddOns|http://grass.osgeo.org/wiki/AddOns]] | |||
< | <center><font color="#409840">_\|/_ '''''Happy mapping!''</font>'''</center> | ||
[[Category: Tutorial]] | |||
{{wxGUI}} |
Latest revision as of 12:41, 8 August 2015
About
GRASS (Geographic Resources Analysis Support System) is a raster/vector GIS, image processing system, and graphics production system. GRASS contains over 400 programs and tools to render maps and images on monitor and paper; manipulate raster, vector, and sites data; process multi-spectral image data; and create, manage, and store spatial data. GRASS uses both an intuitive graphical interface as well as command line syntax for ease of operations. GRASS can interface with commercial printers, plotters, digitizers, and databases to develop new data as well as manage existing data.
Setup
This tutorial assumes that you've already installed GRASS GIS, and have downloaded either the North Carolina sample datasets from our download web page. You'll want to uncompress them first, ideally into a directory called "grassdata" in your home directory. Almost all the help pages, tutorials, and books use these two datasets in their examples, so they are worth grabbing.
Running
To run GRASS, click on the GRASS link on the desktop or from the system menu. From the "Welcome to GRASS" window select either the Spearfish or North Carolina (nc_spm_08) sample datasets for the location, and "user1" for the mapset, then click on [Start Grass].
This will launch GRASS with our brand new GUI written in wxPython.
Displaying maps
Once inside add a raster map layer such as "elevation" from the PERMANENT mapset. To do this click on the checkerboard toolbar button with a "+" on it and then select the map name from the pull-down list which appears, and click [Ok].
In a similar fashion add the "roads" vector layer from the PERMANENT mapset by clicking on the toolbar button with a "+" and a bent poly-line which looks a bit like a "V".
Over in the Map Display window toolbar click on the eyeball button to
render the view.
You should now see the maps displayed.
Plot an elevation profile
Back in the GIS Layer Manager window click on the elevation raster map name to select it. Then in the Map Display window, to the right of the zooming buttons on the Map Display toolbar is an icon with a line graph and checkerboard on it. Click on that and select Profile Surface Map. If it isn't automatically listed again pick an elevation map as the raster layer and press [Ok]. The second button in from the left allows you to set out the profile line, click it then mark out a few points on the Map Display canvas. When done go back to the Profile window and click on the eyeball button to create the plot. Click on the I/O button of the far right to close the profile window.
Create a random surface
Now let's create a new raster map.
We first define the extent and resolution of this map. For simplicity, we select a predefined region with the spatial extent of Wake county, Raleigh (NC, USA) and spatial resolution of 30m: Select Settings → Region → Set region from the main menu. In this dialog window, select 'wake_30m' for the parameter Set current region from named region; and click [Run] (i.e, it defines the Computational region for raster computations).
Now select Raster → Generate surfaces → Fractal surface from the menu (near the bottom); give your new map a name; adjust any options you like in the Options tab (the defaults are fine); and click [Run].
Adjust colors
Now add your new raster layer to the layer list as you did before with the elevation raster map, except this time it will be in your "user1" working mapset. You might un-tick the elevation layer check-box now so that the two don't draw over the top of each other. Click on the eyeball to view your new map.
The colors might not be as you'd like so let's change them. In the Raster menu select Manage colors → Color Tables. In the "Colors" tab click on the pull-down list for the "Type of color table" option, and pick one from the list. "srtm" is a nice choice. Once done click the [Run] button and close the r.colors dialog window.
Because you have altered the map's metadata, this time to re-render it you will have to fully flush the display cache. So click on the little refresh button next to the eyeball button to re-render all layers and you should see your map with its new colors.
Create a shaded relief map
Next we'll create a shaded relief map of the elevation layer we saw earlier. Start by selecting the elevation @PERMANENT map from before by clicking on its name. In the Raster menu select Terrain analysis → Shaded relief (Terrain analysis is about half way down), and the module control dialog will appear. With the elevation map name selected as the input map click [Run]. Now add the new elevation.shade @user1 map into your layer list and un-tick the other raster layers, then click the eyeball to re-render. (If you get sick of clicking the eyeball all the time you can tick the "Render" box in the bottom right of the Map Display window to have that happen automatically)
Watersheds and streams
Once again select the elevation @PERMANENT map and in the Raster menu choose Hydrologic modeling → Watershed analysis. Set the elevation layer as your input map, in the 'Input Options' tab set the sub-basin threshold to 10000 cells, then in the 'Output Options' tab enter "elev.basins" for the watershed basin option and "elev.streams" for the stream segments option just below it. Then click [Run].
Back in the Layer Manager window add those two new raster maps to the layer list and make sure that they are the only two which are ticked for display in the box to the left of the layer name. Right click on the elev.basins raster map layer name and select "Change opacity level". Set it to about 50% then re-render the Map Display.
In the GIS Layer Manager window click on the third button in from the right to add a grid layer. For size of grid put 0:03 for 0 degrees and 3 minutes (format is D:M:S), then in the "Optional" tab tick Draw geographic grid and press [Run] and re-render.
To add a scalebar go to the Map Display window and press the "Add Overlay" button to the right of where you selected the Profile tool earlier and select "Add scalebar and north arrow". Read the instructions then click [Ok]. A scalebar will appear in the top right. Drag it down to the bottom left. From the same toolbar menu select "Add legend" and in the instructions window click the Set Options button to set the raster map name to create the legend for. After picking one click [Ok] and [Ok] again.
Now you may be thinking to yourself that these fonts are a bit bare. That's easily fixed in the GIS Layer Manager menus open Config → Preferences and in the Display tab click the [Set font] button and then [Apply] in the Preferences window. You will have to do a full re-render to see the change so click on the re-render button next to the eyeball. The fonts will now be much prettier.
Vector modules
The above tasks have only covered a few raster modules. Don't let this give you the idea that GRASS is just for raster maps -- the vector engine and modules are every bit as full-featured as the raster ones. GRASS maintains a fully topological vector system which allows all sorts of very powerful analyses.
Continuing with the watershed basins created above, next we'll convert them into vector polygons. In the Raster menu select 'Map type conversions → Raster to vector'. In the r.to.vect dialog that opens make sure that basins @user1 is selected for the input map, give a name for the output map like basins_areas (vector map names must be SQL compliant), and change feature type to 'area'. In the Attributes tab tick the box to use raster values as category numbers, since these will match the values in our stream segment raster map created earlier. Then click on [Run]. Once the new vector map is displayed, you might right click on it in the Layer Manager list and change its opacity level. Also if you right click on the basins_areas vector map in the 'Layer List' you can turn off rendering of area centroids by going into 'Properties' and un-ticking it in the 'Selection' tab.
Next we'll add some attributes to those new areas, containing the average elevation in each basin. In the Vector menu select 'Update attributes → Update area attributes from raster' to launch the v.rast.stats module. Use basin_areas as the vector polygon map, the 'elevation' raster to calculate the statistics from, make the column prefix elev, and click [Run] then close the dialog when it is finished. You can query the values in the 'Map Display' window using the fifth icon from the left and after verifying that the vector-areas map is selected in the 'Layer List', clicking on a vector area in the map canvas.
You can colorize the areas based on the average elevation values using the v.colors module. In the Vector menu select 'Manage colors → Color tables'. Select basin_areas for the input vector map, the elev_mean attribute column for the column containing the numeric range, and in the 'Colors' tab have it copy the colors from the 'elevation' raster map. After running that right-click on the basin_areas map in the Layer List and select 'Properties'. In the 'Colors' tab tick the box for getting colors from the map table column. Once you click [Apply] you should see the colors change in the 'Map Display' window.
Now let's look at the attribute table and SQL builder in more detail. In the 'Layer Manager' click the table icon, it's second from the left on the bottom row. This will open a view of the attached database table. For now we'll just do a simple database query to find watershed basins without a lot of variation in them. Where it says SELECT * FROM basin_areas WHERE pick elev_stdde from the pull down list for the standard deviation statistic, then in the text box to its right enter < 50 and click [Apply]. You'll notice the number of loaded records in the information bar along the bottom of the window has shrunk, and that all of the rows with large values for std. dev. are now gone from the displayed table. Right-click on the table data and choose Select all. Again right-click on the table data and this time choose Highlight selected features. You should see e.g. alluvial flood basins and mesas show up in the Map Display.
3D visualization
Start the 3D visualization suite from the File → NVIZ menu item and have fun exploring. You will have to select those raster and vector maps again from the Raster and Vector tabs.
Select Visualize→Raster Surfaces from the menu, and set the fine resolution to "1", then move the positioning puck and height slider around to get different views.
Other things to try
While not covered here, you may like to experiment with the new Cartographic Composer and object-oriented Graphical Modeling Tool; you'll find icons to launch them on the lower row of icons in the Layer Manager window. Further details can be found in wxGUI help pages.
The new GUI is written in Python, and if you're a fan of Python programming there are a number of great tools available to you. In the bottom of the 'Layer Manager' window click on the 'Python shell' tab and type help(grass.core) to see a listing of the functions available in the core GIS python library. Besides the core GIS functions there is also 'array' (NumPy), 'db' (database), 'raster', and 'vector' libraries available. For advanced use 'Pythons CTypes' is supported allowing the Python programmer access to GRASS's extensive C libraries.
Shutdown and the command line
When finished, exit the GRASS GUI with File→Exit. Before you close the GRASS terminal session as well, try a GRASS module by typing "g.manual --help" which will give you a list of module options. The GRASS command line is where the true power of the GIS comes into its own. GRASS is designed to allow all commands to be tied together in scripts for large bulk processing jobs. Popular scripting languages are Bourne Shell and Python and some neat tricks are included for both to make this scripting easier.
"g.manual -i" will launch a web browser with the module help pages. When done close the browser and type "exit" at the GRASS terminal prompt to leave the GIS environment.
Creating a new GRASS Location from pre-existing data
The GRASS location wizard enables you to create a new location in a few simple steps. It provides a number of ways to set the map projection: from a geodata file (Shapefile, GeoTIFF etc), using an EPSG code, setting projection and datum parameters manually, etc.
For a graphical guide, read on at GRASS Location Wizard.
Further reading
- Visit the GRASS website at http://grass.osgeo.org
- Visit the GRASS Wiki help site at http://grasswiki.osgeo.org/wiki
- How to start with GRASS
- More tutorials and overviews can be found here.
- Synopsis of GRASS modules, including menu positions (PDF, 100k) (HTML version) (slightly outdated)
- If the 400 GIS modules which come with GRASS aren't enough for you have a look at the many contributed add-ons at http://grass.osgeo.org/wiki/AddOns