library(geobr) # para carregar ados vetoriais dos locais desejados. Qualquer outro que carregue dados vetoriais (.shp), seja do R ou do dispositivo, também pode ser utilizado
## Loading required namespace: sf
library(elevatr) # para carregar os dados de altitude
library(raster) # para trabalhar com dados raster
## Carregando pacotes exigidos: sp
library(tidyverse) # para fazer o tratamento de dados e os grĂĄficos em ggplot
## ââ Attaching packages âââââââââââââââââââââââââââââââââââââââ tidyverse 1.3.1 ââ
## â ggplot2 3.3.6 â purrr 0.3.4
## â tibble 3.1.6 â dplyr 1.0.9
## â tidyr 1.2.0 â stringr 1.4.1
## â readr 2.1.2 â forcats 0.5.1
## ââ Conflicts ââââââââââââââââââââââââââââââââââââââââââ tidyverse_conflicts() ââ
## â tidyr::extract() masks raster::extract()
## â dplyr::filter() masks stats::filter()
## â dplyr::lag() masks stats::lag()
## â dplyr::select() masks raster::select()
Primeiramente, Ă© necessĂĄrio possuir os dados da localização espacial de onde os dados de altitude serĂŁo extraĂdos. Isso Ă© feito atravĂ©s do carregamento de um shapefile jĂĄ existente no dispositivo, ou carregando do R, caso este nĂŁo esteja baixado. Neste caso, serĂĄ utilizada a função read_municipality(), do package geobr.
amaraji<-read_municipality(code_muni = 2600906) # Carregando o shapefile do municĂpio de Amaraji - PE
## Using year 2010
##
Downloading: 2 kB
Downloading: 2 kB
Downloading: 2 kB
Downloading: 2 kB
Downloading: 10 kB
Downloading: 10 kB
Downloading: 18 kB
Downloading: 18 kB
Downloading: 18 kB
Downloading: 18 kB
Downloading: 18 kB
Downloading: 18 kB
Downloading: 26 kB
Downloading: 26 kB
Downloading: 34 kB
Downloading: 34 kB
Downloading: 34 kB
Downloading: 34 kB
Downloading: 34 kB
Downloading: 34 kB
Downloading: 42 kB
Downloading: 42 kB
Downloading: 42 kB
Downloading: 42 kB
Downloading: 51 kB
Downloading: 51 kB
Downloading: 51 kB
Downloading: 51 kB
Downloading: 51 kB
Downloading: 51 kB
Downloading: 59 kB
Downloading: 59 kB
Downloading: 59 kB
Downloading: 59 kB
Downloading: 59 kB
Downloading: 59 kB
Downloading: 67 kB
Downloading: 67 kB
Downloading: 67 kB
Downloading: 67 kB
Downloading: 75 kB
Downloading: 75 kB
Downloading: 75 kB
Downloading: 75 kB
Downloading: 75 kB
Downloading: 75 kB
Downloading: 83 kB
Downloading: 83 kB
Downloading: 83 kB
Downloading: 83 kB
Downloading: 83 kB
Downloading: 83 kB
Downloading: 91 kB
Downloading: 91 kB
Downloading: 91 kB
Downloading: 91 kB
Downloading: 99 kB
Downloading: 99 kB
Downloading: 99 kB
Downloading: 99 kB
Downloading: 110 kB
Downloading: 110 kB
Downloading: 110 kB
Downloading: 110 kB
Downloading: 120 kB
Downloading: 120 kB
Downloading: 120 kB
Downloading: 120 kB
Downloading: 120 kB
Downloading: 120 kB
Downloading: 120 kB
Downloading: 120 kB
Downloading: 130 kB
Downloading: 130 kB
Downloading: 130 kB
Downloading: 130 kB
Downloading: 130 kB
Downloading: 130 kB
Downloading: 140 kB
Downloading: 140 kB
Downloading: 140 kB
Downloading: 140 kB
Downloading: 140 kB
Downloading: 140 kB
Downloading: 150 kB
Downloading: 150 kB
Downloading: 160 kB
Downloading: 160 kB
Downloading: 160 kB
Downloading: 160 kB
Downloading: 160 kB
Downloading: 160 kB
Downloading: 170 kB
Downloading: 170 kB
Downloading: 180 kB
Downloading: 180 kB
Downloading: 180 kB
Downloading: 180 kB
Downloading: 190 kB
Downloading: 190 kB
Downloading: 190 kB
Downloading: 190 kB
Downloading: 200 kB
Downloading: 200 kB
Downloading: 200 kB
Downloading: 200 kB
Downloading: 200 kB
Downloading: 200 kB
Downloading: 200 kB
Downloading: 200 kB
Downloading: 210 kB
Downloading: 210 kB
Downloading: 220 kB
Downloading: 220 kB
Downloading: 230 kB
Downloading: 230 kB
Downloading: 240 kB
Downloading: 240 kB
Downloading: 240 kB
Downloading: 240 kB
Downloading: 240 kB
Downloading: 240 kB
Downloading: 240 kB
Downloading: 240 kB
Downloading: 240 kB
Downloading: 240 kB
Downloading: 250 kB
Downloading: 250 kB
Downloading: 250 kB
Downloading: 250 kB
Downloading: 260 kB
Downloading: 260 kB
Downloading: 260 kB
Downloading: 260 kB
amaraji # Conferindo os dados
## Simple feature collection with 1 feature and 4 fields
## Geometry type: MULTIPOLYGON
## Dimension: XY
## Bounding box: xmin: -35.56295 ymin: -8.456729 xmax: -35.37353 ymax: -8.261121
## Geodetic CRS: SIRGAS 2000
## code_muni name_muni code_state abbrev_state geom
## 10 2600906 Amaraji 26 PE MULTIPOLYGON (((-35.50934 -...
Para carregar os dados raster (.tif) de altitude, serĂĄ utilizada a função get_elev_raster(), do package elevatr. Nesse função, Ă© necessĂĄrio especificar a ĂĄrea que serĂŁo extraĂdos os dados, no comando locations= e que serĂĄ o objeto com os dados vetoriais, e o zoom do raster, no comando z=. O zoom vai de 1 a 14, entĂŁo serĂĄ testado com 3 zooms diferentes: 7, 9 e 14
amaraji_elev_7<-get_elev_raster(locations = amaraji,z=7,clip = "locations") # Carregando os dados de altitude para o municĂpio de Amaraji
## Warning in showSRID(SRS_string, format = "PROJ", multiline = "NO", prefer_proj = prefer_proj): PROJ/GDAL PROJ string degradation in workflow
## repeated warnings suppressed
## Discarded datum Sistema de Referencia Geocentrico para las AmericaS 2000 in Proj4 definition
## Mosaicing & Projecting
## Clipping DEM to locations
## Note: Elevation units are in meters.
amaraji_elev_7<-as.data.frame(amaraji_elev_7,xy=T) # TRansformando em um dataframe com variĂĄveis como x (longitude) e y (latitude)
colnames(amaraji_elev_7)<-c("Lon","Lat","Altitude") # Renomeando as colunas do dataframe
amaraji_elev_7 <- amaraji_elev_7[complete.cases(amaraji_elev_7), ] # Retira os dados NAs do dataframe
amaraji_elev_9<-get_elev_raster(locations = amaraji,z=9,clip = "locations") # Carregando os dados de altitude para o municĂpio de Amaraji
## Mosaicing & Projecting
## Clipping DEM to locations
## Note: Elevation units are in meters.
amaraji_elev_9<-as.data.frame(amaraji_elev_9,xy=T) # TRansformando em um dataframe com variĂĄveis como x (longitude) e y (latitude)
colnames(amaraji_elev_9)<-c("Lon","Lat","Altitude") # Renomeando as colunas do dataframe
amaraji_elev_9 <- amaraji_elev_9[complete.cases(amaraji_elev_9), ] # Retira os dados NAs do dataframe
amaraji_elev_14<-get_elev_raster(locations = amaraji,z=14,clip = "locations") # Carregando os dados de altitude para o municĂpio de Amaraji
## Mosaicing & Projecting
## Clipping DEM to locations
## Note: Elevation units are in meters.
amaraji_elev_14<-as.data.frame(amaraji_elev_14,xy=T) # TRansformando em um dataframe com variĂĄveis como x (longitude) e y (latitude)
colnames(amaraji_elev_14)<-c("Lon","Lat","Altitude") # Renomeando as colunas do dataframe
amaraji_elev_14 <- amaraji_elev_14[complete.cases(amaraji_elev_14), ] # Retira os dados NAs do dataframe
ggplot()+
geom_raster(data=amaraji_elev_7,aes(Lon, Lat, fill=Altitude))+
scale_fill_viridis_c()+
theme(text=element_text(family="TimesNewRoman"),
title=element_text(color="black",size=15),
axis.text = element_text(color="black",size=10),
axis.title = element_text(color="black",size=10),
panel.grid=element_line(color="#d3d3d3",size=.1),
axis.line=element_blank(),
plot.background=element_rect(fill="white",color="white"),
panel.background=element_rect(fill="white"),
panel.border = element_rect(colour = "black", fill = NA,size=0.5),
legend.key= element_rect(color="white",fill="white"),
strip.background = element_rect(colour="black",fill="grey75"))
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database
## Warning in grid.Call(C_stringMetric, as.graphicsAnnot(x$label)): font family not
## found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
ggplot()+
geom_raster(data=amaraji_elev_9,aes(Lon, Lat, fill=Altitude))+
scale_fill_viridis_c()+
theme(text=element_text(family="TimesNewRoman"),
title=element_text(color="black",size=15),
axis.text = element_text(color="black",size=10),
axis.title = element_text(color="black",size=10),
panel.grid=element_line(color="#d3d3d3",size=.1),
axis.line=element_blank(),
plot.background=element_rect(fill="white",color="white"),
panel.background=element_rect(fill="white"),
panel.border = element_rect(colour = "black", fill = NA,size=0.5),
legend.key= element_rect(color="white",fill="white"),
strip.background = element_rect(colour="black",fill="grey75"))
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
ggplot()+
geom_raster(data=amaraji_elev_14,aes(Lon, Lat, fill=Altitude))+
scale_fill_viridis_c()+
theme(text=element_text(family="TimesNewRoman"),
title=element_text(color="black",size=15),
axis.text = element_text(color="black",size=10),
axis.title = element_text(color="black",size=10),
panel.grid=element_line(color="#d3d3d3",size=.1),
axis.line=element_blank(),
plot.background=element_rect(fill="white",color="white"),
panel.background=element_rect(fill="white"),
panel.border = element_rect(colour = "black", fill = NA,size=0.5),
legend.key= element_rect(color="white",fill="white"),
strip.background = element_rect(colour="black",fill="grey75"))
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
Ficou claro que o aumento do zoom, criando acima uma maior pixelagem no raster, aumenta tambĂ©m aa resolução. Para mostrar os trĂȘs mapas, lado a lado, serĂĄ criado um novo dataframe contendo os 3 anteriores, e usando a função facet_wrap(), do package ggplot2, para plotar os 3 de uma vez.
# Verificando o nÂș de linhas de cada dataframe
nrow(amaraji_elev_7) # Verificando o nÂș de linhas no raster com zoom de 7
## [1] 654
nrow(amaraji_elev_9) # Verificando o nÂș de linhas no raster com zoom de 10
## [1] 10404
nrow(amaraji_elev_14) # Verificando o nÂș de linhas no raster com zoom de 14
## [1] 10590311
# Criando o novo dataframe fusionado
amaraji_elev<-rbind(amaraji_elev_7,amaraji_elev_9,amaraji_elev_14) # Criando o novo dataframe com a função rbind(), que "cola" os dataframes, um por cima do outro, em um novo dataframe
amaraji_elev$zoom<-rep(c("Zoom de 07","Zoom de 09","Zoom de 14"),c(654,10404,10590311)) # Criando uma nova variĂĄvel, para representar qual Ă© o nĂvel de zoom dos dados, utilizando a função rep()
ggplot()+
geom_raster(data=amaraji_elev,aes(Lon, Lat,fill=Altitude))+
facet_wrap(~zoom)+
scale_fill_viridis_c()+
theme(text=element_text(family="TimesNewRoman"),
title=element_text(color="black",size=15),
axis.text = element_text(color="black",size=10),
axis.text.x = element_text(color="black",size=10,angle=90),
axis.title = element_text(color="black",size=10),
panel.grid=element_line(color="#d3d3d3",size=.1),
axis.line=element_blank(),
plot.background=element_rect(fill="white",color="white"),
panel.background=element_rect(fill="white"),
panel.border = element_rect(colour = "black",fill=NA,size=0.5),
legend.key= element_rect(color="white",fill="white"),
strip.background = element_rect(colour="black",fill="grey75"))
## Warning: Raster pixels are placed at uneven horizontal intervals and will be
## shifted. Consider using geom_tile() instead.
## Warning: Raster pixels are placed at uneven vertical intervals and will be
## shifted. Consider using geom_tile() instead.
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, :
## font family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database
## Warning in grid.Call(C_textBounds, as.graphicsAnnot(x$label), x$x, x$y, : font
## family not found in Windows font database