Difference between revisions of "Using map algebra in GRASS"
Line 31: | Line 31: | ||
this will give you a raster that is the inverse of file A |
this will give you a raster that is the inverse of file A |
||
− | the other way to do map calc is without the command line using the map calculator built into the GUI which is accessed using the button shown below |
+ | the other way to do map calc is without the command line using the map calculator built into the GUI which is accessed using the button shown below. |
− | [[File:GRASS map calculator loc.png|400px|thumb| |
+ | [[File:GRASS map calculator loc.png|400px|thumb|center|location of map calculator]] |
− | and the calculation looks like this. |
||
[[File:GRASS map calculator.png|400px|thumb|center|map calculator]] |
[[File:GRASS map calculator.png|400px|thumb|center|map calculator]] |
||
Line 41: | Line 40: | ||
== Examples == |
== Examples == |
||
+ | |||
+ | ==== Subtracting raster to fit into study area ==== |
||
+ | |||
+ | For this first example the DEMs that are used can be obtained from the Government of Canada website. However, this example will work with any raster file in the same situation. |
||
+ | to start I have two DEMs one that is smaller than the other as you can see in the picture. |
||
+ | [[File:Ex 1 1.png|500px|thumb|center]] |
||
+ | In order to subtract the excess from the large DEM to make it the same size as the as the smaller DEM which for this example will be our study area I used the command |
||
+ | |||
+ | "r.mapcalc --overwrite expression=DEM = DEM@elmin if( DEM@elmin, DEM__2_@elmin)" (elmin is the mapset name just happens that is my username on my computer). |
||
+ | |||
+ | the result as you can see in this picture is that both rasters fit in the study area. |
||
+ | [[File:Ex 1 2.png|500px|thumb|center]] |
||
+ | |||
+ | ==== Creating map indexes using landsat data ==== |
||
+ | |||
+ | for this example I have obtained some data from USGS which is free to get you just need to create account with them. |
||
+ | |||
+ | |||
have landsat data from USGS as well as DEM from the Government of Canada website just have to take screenshots of my process going through this |
have landsat data from USGS as well as DEM from the Government of Canada website just have to take screenshots of my process going through this |
||
will be demonstrating both subtracting extra raster space to fit the raster into a certain study area as well as making different indexes from landsat imagery all using map algebra again have the data just need to take screenshots and explain how each step works. |
will be demonstrating both subtracting extra raster space to fit the raster into a certain study area as well as making different indexes from landsat imagery all using map algebra again have the data just need to take screenshots and explain how each step works. |
Revision as of 01:21, 21 December 2020
Using Map Algebra and the command line in GRASS
Contents
Introduction
GRASS is a geographic information system (GIS) software that is used for geospatial data management and analysis. If you find yourself working on raster data specifically in GRASS it may be very useful to know how to use map algebra in order to manipulate the data so that you can properly analyze it. also it is important to know how to use this tool using the command line instead of the graphical user interface (GUI) and so to that end for this whole page all of the examples will be done using the command line commands.
Map algebra
What is Map Algebra?
map algebra is a way in GRASS to perform arithmetic on raster layers in maps. the way that it works is that it will take two raster layers and it performs an operation on them based on what you tell it to do. for example if you wanted to cut a raster image down to the study area of another you could do that by using the fallowing command:
r.mapcalc --overwrite rasterAnew=”if(rasterB, rasterA)”
this command basically tells the program that for the new raster that you are creating if raster B(the study area) is in that location then put raster A(the raster you are cutting) there, meaning that the end result should be whatever you are measuring in raster A in just the area of raster B.
What can you do with Map Algebra?
there is a lot that you actually can do with map algebra it is not just limited to changing the shape of raster files it can also be used to shift raster files geographically or to edit the values of each pixel of raster files meaning that you could subtract or add raster layers to landsat photos. this is one way to create colour photos from landsat imagery if you add the red green and blue layers together you get real colour photos. you can also use this technique to make different indexes from satellite photos which can be used to tell things like plant life from the inferred layer and the red layer to create an NDVI index.
The method for using these operators works like this:
- Start with the command which in this case is: r.mapcalc
- Then you want to add the file you are creating: newFile=
- Then you add in your operator and variables for example: !fileA which means not file A
r.mapcalc newFile= !fileA
this will give you a raster that is the inverse of file A
the other way to do map calc is without the command line using the map calculator built into the GUI which is accessed using the button shown below.
Examples
Subtracting raster to fit into study area
For this first example the DEMs that are used can be obtained from the Government of Canada website. However, this example will work with any raster file in the same situation. to start I have two DEMs one that is smaller than the other as you can see in the picture.
In order to subtract the excess from the large DEM to make it the same size as the as the smaller DEM which for this example will be our study area I used the command
"r.mapcalc --overwrite expression=DEM = DEM@elmin if( DEM@elmin, DEM__2_@elmin)" (elmin is the mapset name just happens that is my username on my computer).
the result as you can see in this picture is that both rasters fit in the study area.
Creating map indexes using landsat data
for this example I have obtained some data from USGS which is free to get you just need to create account with them.
have landsat data from USGS as well as DEM from the Government of Canada website just have to take screenshots of my process going through this
will be demonstrating both subtracting extra raster space to fit the raster into a certain study area as well as making different indexes from landsat imagery all using map algebra again have the data just need to take screenshots and explain how each step works.
Conclusion
waiting until all the other sections are done will say how important this skill is and try to relate it to real world
References
“Mapcalc Manual.” GRASS GIS Manual: R.mapcalc, GRASS Development Team, grass.osgeo.org/grass76/manuals/r.mapcalc.html.