Classwork 7

Map of Kadavanthra, Kochi

Setup

library(rnaturalearth)
library(rnaturalearthdata)

Attaching package: 'rnaturalearthdata'
The following object is masked from 'package:rnaturalearth':

    countries110
# Run this in your console first
# devtools::install_github("ropensci/rnaturalearthhires")
library(rnaturalearthhires)

# Plotting Maps
library(tidyverse) # Maps using ggplot() + geom_sf()
── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
✔ dplyr     1.1.4     ✔ readr     2.1.5
✔ forcats   1.0.0     ✔ stringr   1.5.1
✔ ggplot2   4.0.0     ✔ tibble    3.3.0
✔ lubridate 1.9.4     ✔ tidyr     1.3.1
✔ purrr     1.1.0     
── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
✖ dplyr::filter() masks stats::filter()
✖ dplyr::lag()    masks stats::lag()
ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggformula) # Maps using gf_sf()
Loading required package: scales

Attaching package: 'scales'

The following object is masked from 'package:purrr':

    discard

The following object is masked from 'package:readr':

    col_factor

Loading required package: ggridges

New to ggformula?  Try the tutorials: 
    learnr::run_tutorial("introduction", package = "ggformula")
    learnr::run_tutorial("refining", package = "ggformula")
library(tmap) # Thematic Maps, static and interactive
library(tmaptools)
library(tmap.mapgl)
library(osmdata) # Fetch map data from osmdata.org
Data (c) OpenStreetMap contributors, ODbL 1.0. https://www.openstreetmap.org/copyright
library(sfheaders) # Handcrafted Map data
## Interactive Maps
library(leaflet) # interactive Maps
library(leaflet)
library(leaflet.providers)
library(leaflet.extras)
library(threejs) # Globe maps in R. Part of the htmlwidgets family of packages
Loading required package: igraph

Attaching package: 'igraph'

The following objects are masked from 'package:lubridate':

    %--%, union

The following objects are masked from 'package:dplyr':

    as_data_frame, groups, union

The following objects are masked from 'package:purrr':

    compose, simplify

The following object is masked from 'package:tidyr':

    crossing

The following object is masked from 'package:tibble':

    as_data_frame

The following objects are masked from 'package:stats':

    decompose, spectrum

The following object is masked from 'package:base':

    union
# For Spatial Data Frame Processing
library(sf)
Linking to GEOS 3.13.0, GDAL 3.10.1, PROJ 9.5.1; sf_use_s2() is TRUE
# https://boundingbox.klokantech.com CSV:
# 77.574028,12.917262,77.595073,12.939895
bbox_1 <- matrix(c(76.297617,9.945678,76.308722,9.967725), byrow = FALSE, nrow = 2,
    ncol = 2, dimnames = list(c("x", "y"), c("min", "max")))
bbox_1
        min       max
x 76.297617 76.308722
y  9.945678  9.967725
bbox_1
        min       max
x 76.297617 76.308722
y  9.945678  9.967725
buildings <- st_read("my-osm-data/buildings.gpkg")
Reading layer `buildings' from data source 
  `C:\Users\diyab\OneDrive\Documents\DiyaData\classwork\maps\my-osm-data\buildings.gpkg' 
  using driver `GPKG'
Simple feature collection with 1187 features and 82 fields
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: 76.29733 ymin: 9.945705 xmax: 76.30903 ymax: 9.967958
Geodetic CRS:  WGS 84
roads <- st_read("my-osm-data/roads.gpkg")
Reading layer `roads' from data source 
  `C:\Users\diyab\OneDrive\Documents\DiyaData\classwork\maps\my-osm-data\roads.gpkg' 
  using driver `GPKG'
Simple feature collection with 740 features and 45 fields
Geometry type: LINESTRING
Dimension:     XY
Bounding box:  xmin: 76.29536 ymin: 9.943133 xmax: 76.31063 ymax: 9.978089
Geodetic CRS:  WGS 84
trees <- st_read("my-osm-data/trees.gpkg")
Reading layer `trees' from data source 
  `C:\Users\diyab\OneDrive\Documents\DiyaData\classwork\maps\my-osm-data\trees.gpkg' 
  using driver `GPKG'
Simple feature collection with 1003 features and 3 fields
Geometry type: POINT
Dimension:     XY
Bounding box:  xmin: 76.29058 ymin: 9.936576 xmax: 76.31755 ymax: 9.979565
Geodetic CRS:  WGS 84
greenery <- st_read("my-osm-data/greenery.gpkg")
Reading layer `greenery' from data source 
  `C:\Users\diyab\OneDrive\Documents\DiyaData\classwork\maps\my-osm-data\greenery.gpkg' 
  using driver `GPKG'
Simple feature collection with 11 features and 11 fields
Geometry type: POLYGON
Dimension:     XY
Bounding box:  xmin: 76.29058 ymin: 9.943617 xmax: 76.3092 ymax: 9.979565
Geodetic CRS:  WGS 84

plotting map

gf_sf(data = roads, geometry = ~geom, color = "grey") %>%
  gf_sf(data = buildings, geometry = ~geom, fill = ~building) %>%
  gf_sf(data = greenery, geometry = ~geom, fill = "palegreen3") %>%
  gf_sf(data = trees, geometry = ~geom, color = "darkgreen") %>%
  gf_theme(theme_light)

gf_sf(data = roads, geometry = ~geom, color = "grey") %>%
  gf_sf(data = buildings %>%  filter(building=="apartments"), geometry = ~geom, fill = "purple") %>%
  gf_sf(data = greenery, geometry = ~geom, fill = "palegreen3") %>%
  gf_sf(data = trees, geometry = ~geom, color = "darkgreen") %>%
  gf_theme(theme_light)