-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLU_changes.Rmd
182 lines (151 loc) · 3.87 KB
/
LU_changes.Rmd
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
---
title: "landUseChanges"
author: "Andres, Raquel, Mauricio"
date: "7/25/2018"
output: ioslides_presentation
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r}
```
##Read data
```{r}
library(raster)
#read alrge scale
LU_2014<-raster('~/landuse_disease/Rasterall/ACRE_2014/AC_2014_RASTER.tif')
LU_2004<-raster('~/landuse_disease/Rasterall/ACRE_2004/AC_2004_RASTER.tif')
#read study area
#LUSA<-raster('~/landuse_disease/Raster/ComposicaoBuffer500m_TC14.tif')
#change projection
#LUSA_ll<-projectRaster(from =LUSA,to =LU_2014)
e <- extent(-75, -71, -9, -7)
LU_2014_SA=crop(LU_2014,e)
LU_2004_SA=crop(LU_2004,e)
png(filename = "~/landuse_disease/SA_raster2004.png",width = 10,height = 6,units = "cm",res = 300)
plot(LU_2004_SA)
dev.off()
png(filename = "~/landuse_disease/SA_raster2014.png",width = 10,height = 6,units = "cm",res = 300)
plot(LU_2014_SA)
dev.off()
```
##Land uses in 2004
```{r}
require(png) #read png files
require(grid) #graphics layout
img <- readPNG("~/landuse_disease/SA_raster2004.png")
grid.raster(img)
```
##Land uses 2014
```{r}
img <- readPNG("~/landuse_disease/SA_raster2014.png")
grid.raster(img)
```
##Evaluate the frequency of land-types
```{r frecuencias, cache = TRUE}
f04<-freq(LU_2004_SA)
f14<-freq(LU_2014_SA)
f04=as.data.frame(f04)
f14=as.data.frame(f14)
dat_LU14<-as.data.frame(LU_2014_SA@data@attributes)
dat_LU04<-as.data.frame(LU_2004_SA@data@attributes)
f04$value %in% f14$value
m_tableLUchange<-merge(dat_LU14,dat_LU04,by="color")
```
##Changes in Land-use
```{r,out.width="60%"}
barplot(height = (m_tableLUchange$Count.x-m_tableLUchange$Count.y)/(m_tableLUchange$Count.x+m_tableLUchange$Count.y),names.arg=m_tableLUchange$tc_2014,cex.name=0.4,las=2)
```
##RECLASIFICATION
Both Images were reclasified
18 Land-types where reduced to 8 types
```{r}
#Others 18
#pastos 19
#regeneration 20
#forest 21
#Urban 22
#Mix 23
#Agriculture 24
#deforested 25
#mining 26
names_LUtypes=c(
"Others",
"Pastos",
"Regeneration",
"Forest" ,
"Urban" ,
"Mixed",
"Agriculture",
"deforested",
"mining")
rc_v_2014=c(1,18,
2,19,
3,20, #check if deforestation is it own class
4,23,
5,19,
6,19,
7,22,
8,18,
9,21,
10,24,
11,19,
12,25,
13,26,
14,20,
15,18)
rc_v_2004=c(1,18,
2,22,
3,25, #check if deforestation is it own class
4,21,
5,18,
6,23,
7,18,
8,18,
9,19,
10,19,
11,19,
12,20,
13,20)
reclass_matrix_2014=matrix(rc_v_2014, ncol=2, byrow=TRUE)
reclass_matrix_2004=matrix(rc_v_2004, ncol=2, byrow=TRUE)
LU_rc2004 <- reclassify(LU_2004_SA, reclass_matrix_2004)
LU_rc2014 <- reclassify(LU_2014_SA, reclass_matrix_2014)
```
##Create the tranissiton matrix
```{r, eval=FALSE}
Matrix_transitions=matrix(ncol=9,nrow=9)
colnames(Matrix_transitions)<-names_LUtypes
rownames(Matrix_transitions)<-colnames(Matrix_transitions)
for (i in 18:26){
for (j in 18:26){
if(j!=i){
antes=(LU_rc2004==i)
despues=(LU_rc2014==j)
differencia=(antes - despues)
temp_im=(antes +(differencia==0))
ff_before=as.data.frame(freq(antes))
ff_after<-as.data.frame(freq(temp_im))
if(length(which(ff_after$value==2))!=0){
Matrix_transitions[(i-17),(j-17)]<-ff_after$count[which(ff_after$value==2)]/ff_before$count[which(ff_before$value==1)]
}
else{
Matrix_transitions[(i-17),(j-17)]<-0
}
}
else{
Matrix_transitions[(i-17),(j-17)]=NA
}
print(c(i,j))
print(Matrix_transitions)
}
}
saveRDS(Matrix_transitions,file = "transition_matrix.rds")
```
##Transition probabilities between land-use types
```{r,out.width="60%"}
Matrix_transitions<-readRDS("~/landuse_disease/transition_matrix.rds")
lattice::levelplot(Matrix_transitions)
```