municipalities <- read_sf("OGIS Brazilian Munipalities/municipalities.shp")
municipalities_sp <- municipalities %>% filter(UF=="SP")
print(municipalities_sp[1:10,])
## Simple feature collection with 10 features and 6 fields
## Geometry type: POLYGON
## Dimension: XY
## Bounding box: xmin: -52.65639 ymin: -25.31024 xmax: -47.73479 ymax: -22.1845
## Geodetic CRS: WGS 84
## # A tibble: 10 x 7
## COD_MUN NOME UF POP_201 IDHM_10 PIB_PER geometry
## <int> <chr> <chr> <dbl> <dbl> <dbl> <POLYGON [°]>
## 1 3509908 CANANEIA SP 12216 0.72 9201 ((-48.09754 -25.31023, -~
## 2 3509908 CANANEIA SP 12216 0.72 9201 ((-47.91403 -25.16738, -~
## 3 3509908 CANANEIA SP 12216 0.72 9201 ((-47.86343 -25.12852, -~
## 4 3505351 BARRA DO CHA~ SP 5305 0.66 7305 ((-49.25004 -24.44493, -~
## 5 3522653 ITAPIRAPUA P~ SP 3926 0.661 6822 ((-49.20744 -24.70042, -~
## 6 3523206 ITARARE SP 48143 0.703 12292 ((-49.25389 -24.31763, -~
## 7 3507159 BOM SUCESSO ~ SP 3623 0.66 8507 ((-49.25192 -24.40347, -~
## 8 3554300 TEODORO SAMP~ SP 21595 0.741 12599 ((-52.28946 -22.62776, -~
## 9 3504008 ASSIS SP 96336 0.805 14272 ((-50.5712 -22.68999, -5~
## 10 3528809 MARACAI SP 13382 0.771 32164 ((-50.5138 -22.6032, -50~
municipalities_centroids <- municipalities_sp %>% st_centroid()
municipalities_centroids %>% ggplot() + geom_sf()
SP_border <- municipalities_sp %>% st_union()
SP_border %>% ggplot() + geom_sf()
SP_border %>% ggplot() + geom_sf() + geom_sf(data=municipalities_centroids) + theme_classic()
print(municipalities[1:4, 3:5])
## Simple feature collection with 4 features and 3 fields
## Geometry type: POLYGON
## Dimension: XY
## Bounding box: xmin: -49.62303 ymin: -3.414883 xmax: -47.93154 ymax: -1.469574
## Geodetic CRS: WGS 84
## # A tibble: 4 x 4
## UF POP_201 IDHM_10 geometry
## <chr> <dbl> <dbl> <POLYGON [°]>
## 1 PA 72597 0.547 ((-48.8278 -2.601164, -48.83234 -2.635788, -48.93922 -2~
## 2 PA 85468 0.588 ((-48.92547 -3.406675, -48.96627 -3.212913, -48.91762 -~
## 3 PA 53787 0.506 ((-48.49495 -2.558588, -48.567 -2.482825, -48.66086 -2.~
## 4 PA 57914 0.586 ((-48.53014 -3.195302, -48.49342 -3.0943, -48.5534 -2.9~
br_states <- municipalities %>% group_by(UF) %>% summarize(IDHM_mean=mean(IDHM_10))
print(br_states[1:5,])
## Simple feature collection with 5 features and 2 fields
## Geometry type: GEOMETRY
## Dimension: XY
## Bounding box: xmin: -73.95055 ymin: -18.3494 xmax: -35.15229 ymax: 4.43706
## Geodetic CRS: WGS 84
## # A tibble: 5 x 3
## UF IDHM_mean geometry
## <chr> <dbl> <GEOMETRY [°]>
## 1 AC 0.586 POLYGON ((-69.34267 -10.95212, -69.19872 -10.94806, -69.01297~
## 2 AL 0.564 POLYGON ((-35.90323 -9.869403, -35.85563 -9.789107, -35.79578~
## 3 AM 0.565 POLYGON ((-60.75412 -0.841936, -60.76055 -0.761119, -60.975 -~
## 4 AP 0.658 MULTIPOLYGON (((-50.5029 2.099758, -50.52607 2.009225, -50.48~
## 5 BA 0.596 MULTIPOLYGON (((-46.04805 -13.30876, -46.1336 -13.37479, -46.~
br_states %>% ggplot() +
geom_sf(aes(fill=IDHM_mean)) +
theme_classic() +
scale_fill_continuous(low="red", high="green")
“Parque do Xingu”
indigenous <- read_sf("Indegenous Groups/BC250_Terra_Indigena_A.shp") %>% st_transform(4326)
br_states %>% ggplot() +
geom_sf() +
geom_sf(data=indigenous, fill="red")
Xingu <- indigenous %>% filter(nome=="Parque do Xingu") %>% st_transform(4326)
Gaucha <- municipalities %>% filter(NOME=="GAUCHA DO NORTE") %>% st_transform(4326)
Gaucha %>% ggplot() +
geom_sf(fill="red") +
geom_sf(data=Xingu, fill="blue", alpha=0.5)
intersection <- Gaucha %>% st_intersection(Xingu)
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries
intersection %>% ggplot() + geom_sf(fill="dark green")
Gaucha %>% ggplot() +
geom_sf(fill="red", alpha=0.5) +
geom_sf(data=Xingu, fill="blue", alpha=0.5) +
geom_sf(data = intersection, fill="black")
st_area(intersection)
## 8109249396 [m^2]
Housing <- read_sf("Housing/MCMV_new.shp")
Housing_AC <- Housing %>% filter(UF=="AC")
br_states %>% filter(UF=="AC") %>% ggplot() +
geom_sf() + geom_sf(data = Housing_AC)
distance <- Housing_AC %>%
st_transform(29189) %>%
st_distance() %>%
as.data.frame()
print(distance[1:5,])
## 1 2 3 4 5
## 1 0.00 [m] 24804.69 [m] 242315.19 [m] 287859.10 [m] 422339.2 [m]
## 2 24804.69 [m] 0.00 [m] 218072.03 [m] 263435.24 [m] 398549.5 [m]
## 3 242315.19 [m] 218072.03 [m] 0.00 [m] 46436.01 [m] 181680.9 [m]
## 4 287859.10 [m] 263435.24 [m] 46436.01 [m] 0.00 [m] 139918.1 [m]
## 5 422339.25 [m] 398549.47 [m] 181680.92 [m] 139918.06 [m] 0.0 [m]
## 6 7 8 9 10
## 1 592605.2 [m] 492622.07 [m] 596084.1 [m] 617807.7 [m] 704344.7 [m]
## 2 572944.9 [m] 468877.05 [m] 573086.5 [m] 594959.9 [m] 680777.6 [m]
## 3 387497.3 [m] 251979.33 [m] 359890.3 [m] 382594.3 [m] 464241.1 [m]
## 4 361461.1 [m] 209540.53 [m] 320046.9 [m] 343176.1 [m] 421487.9 [m]
## 5 248657.5 [m] 70363.19 [m] 180507.2 [m] 203859.1 [m] 282581.5 [m]
Housing_AC %>% st_transform(29189) %>%
st_buffer(20000) %>%
ggplot() + geom_sf(fill="dark green")
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")
mun_Housing_units <-municipalities %>% st_join(Housing)
print(mun_Housing_units[1:5,])
## Simple feature collection with 5 features and 11 fields
## Geometry type: POLYGON
## Dimension: XY
## Bounding box: xmin: -51.21642 ymin: -3.414883 xmax: -47.93154 ymax: -0.560798
## Geodetic CRS: WGS 84
## # A tibble: 5 x 12
## COD_MUN NOME UF.x POP_201 IDHM_10 PIB_PER geometry XCOORD
## <int> <chr> <chr> <dbl> <dbl> <dbl> <POLYGON [°]> <dbl>
## 1 1504703 MOJU PA 72597 0.547 3894 ((-48.8278 -2.601164, -4~ -48.8
## 2 1507953 TAILAN~ PA 85468 0.588 5405 ((-48.92547 -3.406675, -~ -48.9
## 3 1500206 ACARA PA 53787 0.506 4389 ((-48.49495 -2.558588, -~ NA
## 4 1508001 TOME A~ PA 57914 0.586 4765 ((-48.53014 -3.195302, -~ -48.2
## 5 1501808 BREVES PA 94779 0.503 3608 ((-49.9747 -1.30028, -50~ -50.5
## # ... with 4 more variables: YCOORD <dbl>, UF.y <chr>, UH <dbl>,
## # Project_ID <int>
mun_Housing_units <- mun_Housing_units %>%
group_by(COD_MUN,NOME) %>%
summarise(UH=sum(UH,na.rm = T)) %>%
ungroup()
## `summarise()` has grouped output by 'COD_MUN'. You can override using the
## `.groups` argument.
mun_Housing_units %>% arrange(-UH) %>% slice(1) %>% pull(NOME)
## [1] "RIO DE JANEIRO"
mun_Housing_units %>% ggplot() +
geom_sf(aes(fill=UH), col=NA) +
scale_fill_gradient(low="#ccece6",high="dark red",trans="log") +
theme_classic()
## Warning: Transformation introduced infinite values in discrete y-axis
library(deldir)
## deldir 1.0-6 Nickname: "Mendacious Cosmonaut"
##
## The syntax of deldir() has had an important change.
## The arguments have been re-ordered (the first three
## are now "x, y, z") and some arguments have been
## eliminated. The handling of the z ("tags")
## argument has been improved.
##
## The "dummy points" facility has been removed.
## This facility was a historical artefact, was really
## of no use to anyone, and had hung around much too
## long. Since there are no longer any "dummy points",
## the structure of the value returned by deldir() has
## changed slightly. The arguments of plot.deldir()
## have been adjusted accordingly; e.g. the character
## string "wpoints" ("which points") has been
## replaced by the logical scalar "showpoints".
## The user should consult the help files.
library(dismo)
## Warning: package 'dismo' was built under R version 4.1.3
## Loading required package: raster
## Warning: package 'raster' was built under R version 4.1.3
## Loading required package: sp
## Warning: package 'sp' was built under R version 4.1.3
##
## Attaching package: 'raster'
## The following object is masked from 'package:ggsn':
##
## scalebar
## The following object is masked from 'package:dplyr':
##
## select
sp_voronoi <- municipalities_centroids %>%
as("Spatial") %>%
voronoi() %>%
st_as_sf()
## Warning in proj4string(x): CRS object has comment, which is lost in output; in tests, see
## https://cran.r-project.org/web/packages/sp/vignettes/CRS_warnings.html
sp_voronoi %>% ggplot() +
geom_sf()
sp_voronoi_clip <- sp_voronoi %>% st_intersection(st_union(SP_border))
## Warning: attribute variables are assumed to be spatially constant throughout all
## geometries
sp_voronoi_clip %>% ggplot() + geom_sf()
mun_housin <- municipalities %>% st_join(Housing) %>%
group_by(COD_MUN) %>%
count()
mun_housin %>% ggplot() +
geom_sf(aes(fill=n),col=NA) +
scale_fill_gradient(low = "#ccece6", high = "dark green") +
theme_classic()