-
Notifications
You must be signed in to change notification settings - Fork 0
/
NorthernOntario_1.R
52 lines (32 loc) · 1.43 KB
/
NorthernOntario_1.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
library(raster)
library(sp)
library(rgdal)
library(dplyr)
#######################################################################
#' set working directory and identify name of image file
wd <- setwd("c:/personal/r")
par(mai=c(1.02,0.82,0.82,0.42))
image.lst <- c(1000, 1001, 1002, 1003, 1004, 1005)
#' Specify out raster with "filename" argument also test the pixel value (pix).
#' Pixel values can be adjusted for each TIF tile specifically.
#' identify variable (val) to encode the pixels greater than a certain value
val <- 1200
pix <- c(20, 20, 20, 20, 20, 20)
# start loop
for (i in 1: length(image.lst)){
# call each image
image.name <- paste0("Ontario", image.lst[i],".tif")
#######################################################################
#' load Tif as raster image
no <- raster(image.name)
plot(no) # plot image
#' use the locator function to identify the pixel value to use in the
#' calculator function below
#pxy <- locator(1) # click on plot where you want to query pixel value
#extract(no, cbind(pxy$x, pxy$y))) # returns value associated with click query
r05 <- no
#' write the raster to points while subsetting for user defined variable: PIX
r2.points <- rasterToPoints(r05, fun = function(x){x>pix[i]})
# write points out to CSV
write.csv(r2.points, file = paste0("Ontario", image.lst[i], "_", pix[i], ".csv"))
}