1 Packages exigidos

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()

2 Carregando os dados

2.1 Carregando os dados vetorais

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 -...

2.2 Carregando os dados espaciais

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

2.2.1 Zoom de 7

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

2.2.2 Zoom de 9

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

2.2.3 Zoom de 14

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

3 Criando o ggplot

3.1 Zoom de 7

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

3.2 Zoom de 9

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

3.3 Zoom de 14

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

3.4 Para faciliatar a comparação

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.

3.4.1 Criando o novo dataframe

# 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()

3.4.2 Criango o ggplot

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