First task

Produce a map showing the centroids of each municipality in just the state of Säo Paulo, and add the outer boundary of Säo Paulo state.

  1. open municipalities and filter for SP state
municipalities <- read_sf("municipalities/municipalities.shp")

municipalities_sp <- municipalities %>% filter(UF=="SP")
  1. Generate municipalities centroids and plot them
municipalities_centroids <- municipalities_sp %>% st_centroid()

municipalities_centroids %>% ggplot() + geom_sf()

  1. Dissolve SP state polygons to create SP state border
SP_border <- municipalities_sp %>% st_union()

SP_border %>% ggplot() + geom_sf()

  1. Plot SP centroids and Sp border together
SP_border %>% ggplot() + geom_sf()+
  geom_sf(data=municipalities_centroids)

Second Task

What is the mean Human Development Index of municipalities in each state of Brazil?

  1. Remember that HDI is a variable from municipalities data set. Open table to set it.

  2. Calculate mean HDI by state

br_states <- municipalities %>% group_by(UF) %>% summarise(IDHM_mean=mean(IDHM_10))

view(br_states)
  1. Plot the result
br_states %>% ggplot() +
  geom_sf(aes(fill=IDHM_mean))+  
  theme_classic() +
  scale_fill_continuous(low="red",high="green")

Third Task

produce a polyline/shapefile mapping the area of the municipality ‘Gaucha do Notre’ that is in the indigenous territory “Parque de xinqgu”

  1. Import indogenous park shapefile and plot it
indeginous <- read_sf("BC250_Terra_Indigena_A/BC250_Terra_Indigena_A.shp") %>% st_transform(4326)

br_states %>% ggplot() +
  geom_sf() +
  geom_sf(data = indeginous, fill="red")

  1. Create a shapefile for Gaucha do Notre e Xingu
Xingu <- indeginous %>% filter(nome=="Parque do Xingu") %>% st_transform(4326)
Gaucha <- municipalities %>% filter(NOME=="GAUCHA DO NORTE") %>% st_transform(4326)

3 Plot the shape files to see the overlap

Gaucha %>% ggplot() +
  geom_sf(fill="red") +
  geom_sf(data=Xingu, fill="blue", alpha=0.5)

4 create shapefile for intersction and plot it

intersection <-  Gaucha %>% st_intersection(Xingu)
intersection %>% ggplot() + geom_sf(fill="dark green")

5 plot all together

Gaucha %>% ggplot() +
  geom_sf(fill="red", alpha=0.5) +
  geom_sf(data=Xingu, fill="blue", alpha=0.5) +
  geom_sf(data = intersection, fill = "black")

you can calcualte the intersection area

st_area(intersection)
## 8109249396 [m^2]

Fourth Task

In the state of Acre (AC), which two social housing (MCMV) projects are closest to each other? Create 20km buffer around each housinh project.

  1. Import housing shapefile
Housing <- read_sf("MCMV_new/MCMV_new.shp")
  1. Select housing in AC state and plot that result
Housing_AC <- Housing %>% filter(UF=="AC")
br_states %>% filter(UF=="AC") %>% ggplot() + geom_sf() + geom_sf(data = Housing_AC)

  1. calculate distance between housing points and view results
distance <- Housing_AC %>%
  st_transform(29189) %>%
  st_distance() %>%
  as.data.frame()
  1. Generate Buffer around housing points
Housing_AC %>% st_transform(29189) %>%
  st_buffer(20000) %>%
  ggplot() + geom_sf(fill="dark green")

  1. plot it all together
br_states %>% filter(UF == "AC") %>% ggplot() +
  geom_sf()+
  geom_sf(data = (Housing_AC %>% st_transform(29189) %>% st_buffer(20000)), fill="dark green")+
  geom_sf(data = Housing_AC, color = "red")

Fifth Task

Across Brazil, which municipalities have the lowest and highest number of MCMV housing units (UH) in its territory? Create a map of the distribution of total housing units by municipality.

  1. Spatial join between Municipalities and housing
mun_Housing_units <- municipalities %>% st_join(Housing)
  1. calculate total of Housing units in each munincipality
mun_Housing_units <- mun_Housing_units %>%
  group_by(COD_MUN, NOME) %>%
  summarize(UH=sum(UH, na.rm = T)) %>%
  ungroup()
## `summarise()` has grouped output by 'COD_MUN'. You can override using the
## `.groups` argument.
  1. select municipality with most Housing units
mun_Housing_units %>% arrange(-UH) %>% slice(1) %>%pull(NOME)
## [1] "RIO DE JANEIRO"
mun_Housing_units %>% arrange(UH) %>% slice(1) %>%pull(NOME)
## [1] "CABIXI"
  1. plot the distribution of total housing units by municipality.
mun_Housing_units %>% ggplot()+ 
  geom_sf(aes(fill=UH), col=NA) +
  scale_fill_gradient(low="#ccece6", high="dark green", trans="log")+
  theme_classic()
## Warning: Transformation introduced infinite values in discrete y-axis