7. Data Processing Part-3: Classify raster datasets#

We need to classify raster datasets in different categories. For example, slope can be classified into 10 degrees intervals. Grass GIS uses rules file for classifying raster data. To reclassify a raster data in Grass-GIS we use r.reclass or r.recode. The r.recode will create a new raster map but r.reclass will refer to the existing raster map. Further, r.reclass uses integer values only. You can chose one of these two to reclassify as per your convenience. In this tutorial, both will be used for the purpose of learning.

7.1. Classify Slope raster#

To classify sloper raster, create a text data file in a notepad or other text editor such notepad++ and copy the following text.

Rules text for slope classification

0 thru 15 = 1 0~15
15 thru 30 = 2 15~30
30 thru 45 = 3 30~45
45 thru 60 = 4 45~60
60 thru 75 = 5 65~70
75 thru 90 = 6 75~90

The above rule means that orginal slope values from 0 to 15 will be replaced by 1 in the output map and labeled as 0~15 and so on. Save the file as slopecl.txt. Run the following code in the console.

We have created a mapset called NewBasin and we are using it as current mapset therefore, the name of raster map should be used properly.

r.reclass input=slope@NewBasin output=recl.slope rules=path/to/slopecl.txt

It will produce a reclassified and labelled map of slope with values ranging from 1 to 6. Following figure shows the reclassified slope map.

https://mrakhilesh.com/GIS/image/slopeclass.png

Fig. 7.1 Slope Class Map#

7.2. Classify aspect data#

We generally use 4 or 8 directions. In this exercise, we will use 8 directions; North, North-East, East, South-East, South, South-West, West and North-West. As the aspect map has values ranging from 0 to 360, we use following rules.txt file for classification. 0 aspect represents flat cell.

Rules text for aspect classification

0:0:0
0.0001:22.5:1
22.5:67.5:2
67.5:112.5:3
112.5:157.5:4
157.5:202.5:5
202.5:247.5:6
247.5:292.5:7
292.5:337.5:8
337.5:360:1

r.recode input=aspect@NewBasin output=recl.aspect rules=path/to/aspectcl.txt

We can label a raster using the following code. It helps us to display the raster legend with labels as shown in the following figure.

r.category map=recl.aspect@NewBasin cats=1-8 rules=path/to/aspectlabel.txt

The file named aspectlabel.txt should have the following format.

Labels for reclassified aspect

1 East
2 North East
3 North
4 North West
5 West
6 South West
7 South
8 South East

https://mrakhilesh.com/GIS/image/aspectclass.png

Fig. 7.2 Aspect Class Map#

7.3. Classify NDVI#

NDVI values range from -1 to 1. The values below 0 generally represent water bodies. As such, following classification rule was created.

Rules text for NDVI classification

-1:0:1
0.0001:0.1:2
0.1:0.2:3
0.2:0.3:4
0.3:0.4:5
0.4:0.5:6
0.5:0.6:7
0.6:0.7:8
0.7:1.0:9

https://mrakhilesh.com/GIS/image/ndviclass.png

Fig. 7.3 Reclassified NDVI map#

7.4. Classify NDWI#

NDWI values range can be obtained by running code r.info map=ndwi. In my case the information shows: Range of data: min = -0.4883721 max = 0.5444221. It may be different for other areas. Following classification rule was created to classify NDWI.

Rules text for NDWI classification

-0.6:-0.4:1
-0.4:-0.2:2
-0.2:0.0:3
0.0:0.2:4
0.2:0.4:5
0.4:0.6:6

https://mrakhilesh.com/GIS/image/ndwiclass.png

Fig. 7.4 Reclassified NDWI map#

7.5. Classify Profile Curvature#

Range of Data: min = -0.1029236 max = 0.09147612

Classification rules:

Rules text for Profile Curvature classification

-0.1:-0.05:1
-0.05:-0.01:2
-0.01:0.0:3
-0.0:0.01:4
0.01:0.05:5
0.05:0.1:6 \

https://mrakhilesh.com/GIS/image/profcurvclass.png

Fig. 7.5 Reclassified Profile Curvature map#

7.6. Classify Tangent Curvature#

Range of Data: min = -0.1612968 max = 0.09415767

Classification rules:

Rules text for Tangent Curvature classification

-0.2:-0.05:1
-0.05:-0.01:2
-0.01:0.0:3
-0.0:0.01:4
0.01:0.05:5
0.05:0.1:6

https://mrakhilesh.com/GIS/image/tancurvclass.png

Fig. 7.6 Reclassified Tangent Curvature map#

7.7. Classify River Distance Raster#

Range of Data: min = 0 max = 7108.54459435966

Classification rules:

Rules text for River Distance classification

0:100:1
100:200:2
200:500:3
500:1000:4
1000:2000:5
2000:8000:6

We will label the river-distance for display using this code.

r.category map=recl.riverdist@NewBasin cats=1-6 rules=path/to/riverdistcat.txt --overwrite

Where riverdistcat.txt file is as follows:

Labels for reclassified river distance

1 0-100m
2 100-200m
3 200-500m
4 500-1000m
5 1000-2000m

https://mrakhilesh.com/GIS/image/riverdistclass.png

Fig. 7.7 Reclassified River Distance map#