Skip to content

Commit

Permalink
raster analysis3 august 15
Browse files Browse the repository at this point in the history
  • Loading branch information
Mariember committed Aug 15, 2024
1 parent 7ff8052 commit be7ef24
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions _posts/qgis/2024-07-06-raster-analysis.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,27 @@ Trees are defined as vegetation taller than 5m in height. ‘Forest Cover Loss

### 2. Calculating raster area
#### 2.1. Raster clipping
1. 1. Open QGIS and in the QGIS Browser Panel, locate the directory where you added the data and add files <span style="font-family:Consolas; color:#AF1B03">estonia.gpkg</span> and <span style="font-family:Consolas; color:#AF1B03">Hansen_GFC_2023_lossyear_60N_020E.tif</span> to QGIS.
1. Open QGIS and in the QGIS Browser Panel, locate the directory where you added the data and add files <span style="font-family:Consolas; color:#AF1B03">estonia.gpkg</span> and <span style="font-family:Consolas; color:#AF1B03">Hansen_GFC_2023_lossyear_60N_020E.tif</span> to QGIS.
2. Save your project with an appropriate name, for example raster_analysis.
3. Now lets clip the raster layer to the vector boundary, so only Estonia will be left. To do that search Clip raster by mask layer in the Processing toolbox and open it. Choose <span style="font-family:Consolas; color:#AF1B03">Hansen_GFC_2023_lossyear_60N_020E.tif</span> layer as the Input Layer and <span style="font-family:Consolas; color:#AF1B03">estonia.gpkg</span> layer as the Mask Layer. Enter 0 as the nodata value.
3. Now lets clip the raster layer to the vector boundary, so only Estonia will be left. To do that search Clip raster by mask layer in the Processing toolbox and open it. Choose <span style="font-family:Consolas; color:#AF1B03">Hansen_GFC_2023_lossyear_60N_020E</span> layer as the Input layer and <span style="font-family:Consolas; color:#AF1B03">estonia</span> layer as the Mask layer. Enter 0 as the nodata value.
![image](../../images/7_clip raster.png)
4. In the Advanced Parameters section choose Low compression. Double click on the value box and write LZW. Save the file as <span style="font-family:Consolas; color:#AF1B03">forest_est_wgs84.tif</span> and click `Run`..
4. In the Advanced Parameters section choose Low compression. Double click on the value box and write LZW. Save the file as <span style="font-family:Consolas; color:#AF1B03">forest_est_wgs84.tif</span> and click `Run`.
![image](../../images/7_clip raster2.png)
5. Right-click <span style="font-family:Consolas; color:#AF1B03">Hansen_GFC_2023_lossyear_60N_020E.tif</span> layer and select Remove Layer.

#### 2.2. Reprojecting raster
6. Next we need to reproject the raster layer to the Estonian coordinate system. In the Processing Toolbox search Warp(Reprojet) and open it. Choose <span style="font-family:Consolas; color:#AF1B03">forest_est_wgs84.tif</span> as the Input Layer and EPSG:3301 as the Target CRS. In the Advanced Parameters choose Low Compression and LZW like before. Save the file as <span style="font-family:Consolas; color:#AF1B03">forest_est_reprojected.tif</span> and click `Run`.
6. Next we need to reproject the raster layer to the Estonian coordinate system. In the Processing Toolbox search Warp(Reprojet) and open it. Choose <span style="font-family:Consolas; color:#AF1B03">forest_est_wgs84</span> as the Input Layer and EPSG:3301 as the Target CRS. In the Advanced Parameters choose Low Compression and LZW like before. Save the file as <span style="font-family:Consolas; color:#AF1B03">forest_est_reprojected.tif</span> and click `Run`.
![image](../../images/7_warp.png)
7. Remove the <span style="font-family:Consolas; color:#AF1B03">forest_est_wgs84.tif</span> layer. Let's set the project layer to the UTM zone. Click on <span style="font-family:Consolas; color:#AF1B03">forest_est_reprojected.tif</span> layer and choose `Layer CRS ► Set Project CRS from Layer`.
![image](../../images/7_layer crs.png)

#### 2.3. Styling raster
8. Now let's change the symbology of the raster layer to a more suitable one. Double click on <span style="font-family:Consolas; color:#AF1B03">forest_est_reprojected.tif</span> to open Symbology. Choose Singleband pseudocolor as the Render type, Equal Interval as the mode and 23 classes. Also choose a colour ramp to your liking, for example Viridis. Then click `OK`.
8. Now let's change the symbology of the raster layer to a more suitable one. Double click on <span style="font-family:Consolas; color:#AF1B03">forest_est_reprojected</span> to open Symbology. Choose Singleband pseudocolor as the Render type, Equal Interval as the mode and 23 classes. Also choose a color ramp to your liking, for example Viridis. Then click `OK`.
![image](../../images/7_symbology.png)

#### 2.4. Calculating areas
9. Now let's calculate the area for each class. Search Raster layer unique values report in the Processing toolbox and open it. Choose <span style="font-family:Consolas; color:#AF1B03">forest_est_reprojected.tif</span> as the Input layer. Save the file as <span style="font-family:Consolas; color:#AF1B03">class_areas.gpkg</span> and click `Run`.
9. Now let's calculate the area for each class. Search Raster layer unique values report in the Processing Toolbox and open it. Choose <span style="font-family:Consolas; color:#AF1B03">forest_est_reprojected</span> as the Input layer. Save the file as <span style="font-family:Consolas; color:#AF1B03">class_areas.gpkg</span> and click `Run`.
![image](../../images/7_unique values.png)
10. Right-click on the <span style="font-family:Consolas; color:#AF1B03">class_areas.gpkg</span> layer and open Attribute Table. The column m2 contains the area for each class in square meters.
11. Let's convert the area to square kilometers. To do that, search Field calculator in the Processing toolbox and open it. Select <span style="font-family:Consolas; color:#AF1B03">class_areas.gpkg</span> as the Input layer. Enter the Field name as area_sqkm and for the result field type choose decimal (double). In the Expression window enter round("m2" / 1000000, 2). This will convert the square meters to square kilometers. Save the file as <span style="font-family:Consolas; color:#AF1B03">class_area_sqkm.xlsx</span> and click `Run`.
11. Let's convert the area to square kilometers. To do that, search Field calculator in the Processing Toolbox and open it. Select <span style="font-family:Consolas; color:#AF1B03">class_areas</span> as the Input layer. Enter the Field name as area_sqkm and for the result field type choose decimal (double). In the Expression window enter <span style="font-family:Consolas">round("m2" / 1000000, 2)</span>. This will convert the square meters to square kilometers. Save the file as <span style="font-family:Consolas; color:#AF1B03">class_area_sqkm.xlsx</span> and click `Run`.
![image](../../images/7_field calc.png)
Binary file modified images/7_clip raster.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit be7ef24

Please sign in to comment.