- Joins espaciais
- Calculando uma medida de clustering: Moran's I
- Trabalhando com rasters
- Novas visualizações
## [1] "try 2 ..." ## [1] "try 3 ..."
merged <- merged %>% st_transform(4326) intersects <- sf_points %>% st_join(merged,st_intersects)
## Simple feature collection with 4 features and 4 fields ## geometry type: POINT ## dimension: XY ## bbox: xmin: -39.12264 ymin: -8.284964 xmax: -34.87859 ymax: -8.047961 ## epsg (SRID): 4326 ## proj4string: +proj=longlat +datum=WGS84 +no_defs ## OBJECTID NM_MUNICIP Shape_Area COD_MUN_IBGE geometry ## 3 5436 RECIFE 0.01791730 2611606 POINT (-34.87859 -8.047961) ## 2 5436 RECIFE 0.01791730 2611606 POINT (-34.88087 -8.071733) ## 1 5349 CARUARU 0.07553961 2604106 POINT (-35.97019 -8.284964) ## 4 5442 SALGUEIRO 0.13839231 2612208 POINT (-39.12264 -8.069573)
intersects %>% group_by(NOME_MUNICIPIO) %>% count()
NOME_MUNICIPIO | n |
---|---|
CARUARU | 1 |
RECIFE | 2 |
SALGUEIRO | 1 |
sf_points %>% st_distance()
## Units: m ## [,1] [,2] [,3] [,4] ## [1,] 0.000 2641.044 123114.0 467814.3 ## [2,] 2641.044 0.000 122332.1 467544.2 ## [3,] 123114.037 122332.064 0.0 348199.7 ## [4,] 467814.282 467544.169 348199.7 0.0
sf_points %>% st_transform(22524) %>% st_buffer(10000) %>% ggplot() + geom_sf() + theme_classic() + coord_sf(datum=NA)
library(dismo) sf_voronoi <- merged %>% st_centroid() %>% as("Spatial") %>% voronoi() %>% st_as_sf() %>% st_intersection(st_union(shapefile %>% st_transform(4326)))
1 - Tirar ilhas (sem vizinhos)
library(spdep) neighbours1 <- merged %>% as("Spatial") %>% poly2nb(queen=TRUE) merged_contig <- merged %>% filter(card(neighbours1)!=0)
## Neighbour list object: ## Number of regions: 183 ## Number of nonzero links: 698 ## Percentage nonzero weights: 2.084266 ## Average number of links: 3.814208 ## Link number distribution: ## ## 1 2 3 4 5 6 7 8 9 ## 10 36 38 41 29 18 5 4 2 ## 10 least connected regions: ## 3 26 39 49 51 110 144 151 171 179 with 1 link ## 2 most connected regions: ## 101 122 with 9 links
2 - Identificar vizinhos para cada feature
neighbours2 <- merged_contig %>% as("Spatial") %>% poly2nb(queen=TRUE)
## Neighbour list object: ## Number of regions: 183 ## Number of nonzero links: 698 ## Percentage nonzero weights: 2.084266 ## Average number of links: 3.814208 ## Link number distribution: ## ## 1 2 3 4 5 6 7 8 9 ## 10 36 38 41 29 18 5 4 2 ## 10 least connected regions: ## 3 26 39 49 51 110 144 151 171 179 with 1 link ## 2 most connected regions: ## 101 122 with 9 links
3 - Criar 'ponderação' de vizinhos
neighbours_weights <- neighbours2 %>% nb2listw(style="W")
## Characteristics of weights list object: ## Neighbour list object: ## Number of regions: 183 ## Number of nonzero links: 698 ## Percentage nonzero weights: 2.084266 ## Average number of links: 3.814208 ## ## Weights style: W ## Weights constants summary: ## n nn S0 S1 S2 ## W 183 33489 183 110.6125 776.2645
4 - Calcular a estatÃstica Moran's I para a variável desejada
merged_contig %>% pull(Vote_Pct) %>% moran(neighbours_weights,length(neighbours2),Szero(neighbours_weights)) %>% with(I)
## [1] 0.5724341
raster()
para abrir arquivos de tipo .tifgmap
satellite <- gmap("Recife, Brazil",zoom=16,type="satellite")
## [1] "try 2 ..." ## [1] "try 3 ..."
satellite %>% as("SpatialPixelsDataFrame") %>% as.data.frame() %>% ggplot() + geom_tile(aes(x=x,y=y,fill=get(names(satellite)))) + coord_equal()
terrain <- gmap("Recife, Brazil",zoom=16,type="terrain") terrain %>% as("SpatialPixelsDataFrame") %>% as.data.frame() %>% ggplot() + geom_tile(aes(x=x,y=y,fill=get(names(terrain)))) + coord_equal()
devtools::install_github("jbaileyh/geogrid") library(geogrid)
library(geogrid) sf_hex_grid <- merged %>% calculate_grid(grid_type="hexagonal") sf_hex_grid <- merged %>% assign_polygons(sf_hex_grid) hex_map <- sf_hex_grid %>% st_as_sf() %>% ggplot() + geom_sf(aes(fill=Vote_Pct)) + geom_text(aes(x=V1,y=V2,label=substr(NM_MUNICIP,1,2)),size=2,col="white") + theme_classic() + coord_sf(datum=NA) + xlab("") + ylab("")