Skip to content

Commit

Permalink
Add NaPTAN investigations
Browse files Browse the repository at this point in the history
  • Loading branch information
mattkerlogue committed Jan 1, 2021
1 parent eb1ab43 commit 3aae8d0
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions playground.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

library(tidyverse)

### Initial investigations -----

# get coastline
world_coastline <- rnaturalearth::ne_coastline(scale = 10, returnclass = "sf")

Expand Down Expand Up @@ -54,3 +56,43 @@ ggplot() +
geom_sf(data = nearest_coast, colour = "red") +
xlim(-3.4, -2.8) +
ylim(56.3, 56.5)


### Tweet 2: DfT NaPTAN/NPTG data

# download NAPTAN data
naptan_url <- "https://naptan.app.dft.gov.uk/DataRequest/Naptan.ashx?format=csv"
dest_file <- paste0("data/source/naptan/naptan", Sys.Date(), "_download.zip")
unzip_loc <- paste0("data/source/naptan/", gsub(".zip", "", basename(dest_file)))
dir.create(unzip_loc)

download.file(naptan_url, dest_file)
unzip(dest_file, exdir = unzip_loc)

stops <- read_csv(paste0(unzip_loc, "/Stops.csv"),
col_types = cols(.default = col_character()))
stops_in_area <- read_csv(paste0(unzip_loc, "/StopsInArea.csv"),
col_types = cols(.default = col_character()))
rail_ref <- read_csv(paste0(unzip_loc, "/RailReferences.csv"),
col_types = cols(.default = col_character()))
metro_ref <- read_csv(paste0(unzip_loc, "/MetroReferences.csv"),
col_types = cols(.default = col_character()))

stop_types <- read_csv("data/source/naptan/stop_types.csv")

live_stops <- stops %>%
janitor::clean_names() %>%
filter(status == "act") %>%
select(atco_code, naptan_code, common_name, street, locality_name,
parent_locality_name, nptg_locality_code, longitude, latitude, stop_type) %>%
left_join(stop_types, by = c("stop_type" = "type")) %>%
filter(open_access)

rail_metro <- live_stops %>%
filter(mode == "rail" | mode == "metro")

air_ferry <- live_stops %>%
filter(mode == "air" | mode == "ferry")

bus_stops <- live_stops %>%
filter(mode == "bus")

0 comments on commit 3aae8d0

Please sign in to comment.