library(sf)
## Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
library(tmap)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(tidyverse)
## -- Attaching packages --------------------------------------- tidyverse 1.3.0 --
## √ tibble 3.0.3 √ purrr 0.3.4
## √ tidyr 1.1.2 √ stringr 1.4.0
## √ readr 1.4.0 √ forcats 0.5.0
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
This study uses the geographical boundary of LSOA and need to process five factors. We choose 1)crime rate as dependent variable and urban vitality as independent variables. There are four factors of urban vitality which are the 2)road network density, 3)POIs density, 4)POIs diversity and 5)population density.
London LSOA boundary is chosen as the geographical boundary for spatial analysis. Lower Layer Super Output Areas (LSOA) are a geographic hierarchy which contain 4835 geographical boundaries. Import a shapefile of LSOA. You can download the file from https://data.london.gov.uk/dataset/statistical-gis-boundary-files-london
# Get the London LSOA Boundaries
LD_LSOA <- st_read(
'D:/F_SCUA-UCL/CASA05/workshop_1/statistical-gis-boundaries-london/statistical-gis-boundaries-london/ESRI/LSOA_2011_London_gen_MHW.shp') #You can change it to your own path
# Quick view the map
qtm(LD_LSOA)
The next step is to calculate the area of each region for further analysis
# Calculate area
LD_LSOA_area <- st_area(LD_LSOA)
LD_LSOA_area <- LD_LSOA_area %>% as.numeric(as.character(LD_LSOA_area))
# Add a colomn of area to LD_LSOA
LD_LSOA$area<- LD_LSOA_area
# Transform geographic coordinate to 4326
LD_LSOA <- LD_LSOA %>%
st_transform(4326)
# Remove useless data
LD_LSOA <- LD_LSOA %>%
select('LSOA11CD', 'LSOA11NM','POPDEN', 'geometry', 'area')
head(LD_LSOA)
## Simple feature collection with 6 features and 4 fields
## geometry type: MULTIPOLYGON
## dimension: XY
## bbox: xmin: -0.0997488 ymin: 51.50974 xmax: 0.09360014 ymax: 51.54279
## geographic CRS: WGS 84
## LSOA11CD LSOA11NM POPDEN area
## 1 E01000001 City of London 001A 112.9 133320.77
## 2 E01000002 City of London 001B 62.9 226191.27
## 3 E01000003 City of London 001C 227.7 57302.97
## 4 E01000005 City of London 001E 52.0 190738.76
## 5 E01000006 Barking and Dagenham 016A 116.2 144195.85
## 6 E01000007 Barking and Dagenham 015A 69.6 198134.81
## geometry
## 1 MULTIPOLYGON (((-0.09728867...
## 2 MULTIPOLYGON (((-0.08812915...
## 3 MULTIPOLYGON (((-0.09678574...
## 4 MULTIPOLYGON (((-0.07323094...
## 5 MULTIPOLYGON (((0.09115207 ...
## 6 MULTIPOLYGON (((0.07774095 ...
Road network data comes from Open Street Map. Download from http://download.geofabrik.de/europe/great-britain/england/greater-london.html. The road density of a region is calculated by dividing the total number of road lengths (meter) by the area of the region (square meter).
# Read data
LD_road <- st_read('D:/F_SCUA-UCL/Final/GIS_Final/data/street/gis_osm_roads_free_1.shp')
## Reading layer `gis_osm_roads_free_1' from data source `D:\F_SCUA-UCL\Final\GIS_Final\data\street\gis_osm_roads_free_1.shp' using driver `ESRI Shapefile'
## Simple feature collection with 325369 features and 10 fields
## geometry type: LINESTRING
## dimension: XY
## bbox: xmin: -0.5177851 ymin: 51.28324 xmax: 0.3385625 ymax: 51.69869
## geographic CRS: WGS 84
# Intersect the road and boundaries
road_intersect <- LD_road %>%
st_join(., LD_LSOA)
## although coordinates are longitude/latitude, st_intersects assumes that they are planar
# Calculate the length of road in each region
length <- st_length(road_intersect)
length <- as.numeric(length)
road_intersect$length <- length
# Calculate the account length of each region
road_intersect <- road_intersect %>%
group_by(LSOA11CD, ) %>%
summarise(.,sum(length))
## `summarise()` ungrouping output (override with `.groups` argument)
# Remove NA
road_intersect <- road_intersect%>%
filter(LSOA11CD != '')%>%
st_drop_geometry()
# Join the road data to LD_LSOA
LSOA_road_account <- left_join(LD_LSOA, road_intersect, by=c('LSOA11CD'= 'LSOA11CD'))
# Calculate road density
LSOA_road_account$density <- LSOA_road_account$`sum(length)` / LSOA_road_account$area
# plot
tm_shape(LSOA_road_account)+
## boundries
tm_borders(col = "white",alpha = 0.01, lwd = 0.01)+
## fill color
tm_fill(col = 'density',n = 5,style = 'quantile', palette = "YlGnBu",colorNA = "gray",
legend.show = TRUE,legend.hist = FALSE,
title = 'Road Density')+
tm_compass(size = 2.5, text.size = 0.7, type = "arrow", position=c("left", "bottom"))+ #compass
tm_scale_bar(width = 0.15, position=c("left", "bottom"), text.size = 0.5)+ ## bar
# tm_xlab("Longitude") + tm_ylab("Latitude") # coordinate
tm_layout(title = "a.Density of Road Network(per m2)",
main.title = "", title.size = 0.77)