Finding the trees in the woods
This is my first post here so will revise this a bit over the week as I learn more bear. I learned most of how to put this post together using maharshi's post Learning CUDA by optimizing softmax: A worklog which is a nice graphic format with prose, functions, images and code. For images I'm using Imgur.
I'm using R and QGIS to understand tree health on a steep hillside. R and QGIS are free statistical and GIS packages respectively.
My site has 2 hectares of trees (weeds and native) on an inaccessible steep broken hillside; higher up rough, boulder-strewn terraces with very steep land down slope - about 22°. The forest is very dense, and half hawthorn ( Crataegus monogyna), and remainder in tree fuchsia (Fuchsia excorticata), Pittosporum species, whiteywood - Alectryon excelsus and horopito - Pseudowintera colorata). Ultimately, I'll identify and segment the vegetation data to species level using R on the newly-available Sentinel2 L2A data. [url goes to Copernicus data platform and requires making a login] (Sentinel2 scans the planet weekly and the data enables identifying surface features including tree shapes and species) but first I need to locate the approximate tree positions which needs a filetype called a Canopy Height Model or CHM, and QGIS is most suited for making these.
First I want to determine tree cover and openings (and then verify on site), get an idea of tree canopy height and tree positions and number, and view terrain variability. I also want to see how close my model matches reality using this data. Later I'll see if tree form and health vary with the rocky surface - and if that's a real effect, and that will help me manage the site better.
Visual outline of process, at left the elevation model, centre the canopy height model, and at right the red points in the image represent the centres of the tree canopies.
While there is a lot of information on R, working on the command line and file paths are often left out - very confusing for us gui folk, so I will cover these aspects. To simplify the process I work from a local folder - nothing worse learning new software and being frustrated by network issues. Some content below includes code blocks that include comments and I use R's standard #Comment format to document what I'm doing to separate comments from R Code
. I use > to indicate that the following is a menu item.
This post assumes a Windows system and that you have R [https://cran.r-project.org/bin/windows/base/] and QGIS [https://www.qgis.org/download/] installed (although both also run on Mac and Linux).
Some very basic R basics
R only reads forward slashes (or double backslashes, but I will only use / here).
With errors, first look very, very closely at path and file name. Extra spaces, wrong slash types and errant punctuation characters are often the cause.
After loading R you see a blank interface, so first I ask R where it is working from, and change if I want it to work from my local folder.
First, create a folder in Windows to work to/from, and ask R in case it is already using it:
getwd()
#getwd means tell me what the working directory is
#R replies:
[1] "C:/Users/myname/Documents"
#R says it's working from myname. This is not where I want R to work from, so;
setwd(file.path("C:/Users/myname/Documents/RWorking"))
R will then save and read files in this folder.
The next post will cover building a canopy height model CHM from the data, and the processes involved.