Skip to content

Commit d6f4f3a

Browse files
committed
Update again
1 parent bedd8ed commit d6f4f3a

File tree

5 files changed

+21
-45
lines changed

5 files changed

+21
-45
lines changed

NAMESPACE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# Generated by roxygen2: do not edit by hand
22

33
export(download_geography)
4-
export(geoinfo)
4+
export(geo_info)

R/utils.R

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
## Utility functions for Canadian geographic shapefiles and filenames
2-
3-
4-
5-
61
#' Download and unzip Canadian shapefiles
72
#'
83
#' Download and unzip Canadian shapefiles from Statistics Canada
@@ -33,13 +28,17 @@ download_geography <- function(geo_path, geo_dir = NULL) {
3328
geo_dir <- here::here("geography", geo_folder_name)
3429
}
3530

36-
temp <- tempfile()
31+
if (str_sub(geo_path, 1, 4) == "http") {
32+
# the path is a url pointing to statcan.gc.ca
33+
temp <- tempfile()
34+
utils::download.file(geo_path, temp)
35+
unzipped_files <- utils::unzip(temp, exdir = geo_dir)
36+
unlink(temp)
3737

38-
utils::download.file(geo_path, temp)
39-
40-
unzipped_files <- utils::unzip(temp, exdir = geo_dir)
41-
42-
unlink(temp)
38+
} else {
39+
# this assumes the path goes directly to a local/server folder
40+
unzipped_files <- utils::unzip(geo_path, exdir = geo_dir)
41+
}
4342

4443
shp_path <- stringr::str_subset(unzipped_files, pattern = ".shp")
4544

@@ -61,9 +60,9 @@ download_geography <- function(geo_path, geo_dir = NULL) {
6160
#'
6261
#' @examples
6362
#' \donttest{
64-
#' geoinfo("lpr_000a16a_e")
63+
#' geo_info("lpr_000a16a_e")
6564
#' }
66-
geoinfo <- function(filename) {
65+
geo_info <- function(filename) {
6766

6867
extract_codes <- canmap::code_pos
6968

README.Rmd

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ A list of useful links to clean up later:
5555

5656
### Parsing the filename for metadata
5757

58-
Suppose you've downloaded the geography file ```lpr_000a16a_e.zip```. The filename defines the important geographic characteristics of the file (you can process using the ```code_pos``` dataset for code positions, or ```get_geoinfo```).
58+
Suppose you've downloaded the geography file ```lpr_000a16a_e.zip```. The filename defines the important geographic characteristics of the file (you can process using the ```code_pos``` dataset for code positions, or ```geo_info```).
5959

6060
```{r codes, warning = FALSE, message = FALSE}
61-
str(geoinfo("lpr_000a16a_e"))
61+
str(geo_info("lpr_000a16a_e"))
6262
```
6363

6464
And each of these codes has a meaning that can be found (sometimes) in the geography guide that accompanies a downloaded file (but you can't find out the details until *after* you've downloaded it, and is missing some information).

data-raw/process_shapefile_info.r

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ library(usethis)
44
library(httr) # for later.
55

66

7-
# shapefile_info <- readr::read_csv("data-raw/shapefile_info.csv")
87
shapefile_paths <- readr::read_csv("data-raw/shapefile_paths.csv")
98

109
base_url_1 <- "http://www12.statcan.gc.ca/census-recensement/"
1110
base_url_2 <- "/geo/bound-limit/files-fichiers/"
1211

1312

1413
shapefile_paths %>% count(geo_code)
14+
1515
# only get shapefiles
1616
shapefile_paths <- shapefile_paths %>%
1717
filter(format == "ArcGIS (.shp)" & language == "english" & geo_code != "rnf") %>%
@@ -30,8 +30,6 @@ shapefile_paths <- shapefile_paths %>%
3030

3131
si <- shapefile_paths %>%
3232
distinct() %>%
33-
# select(path) %>%
34-
# slice(1:100) %>%
3533
rowwise() %>%
3634
mutate(http_type = path %>%
3735
httr::HEAD() %>%
@@ -45,35 +43,14 @@ shapefile_paths <- shapefile_paths %>% semi_join(si, by = "path")
4543

4644
usethis::use_data(shapefile_paths, overwrite = TRUE)
4745

48-
# x <- fs::dir_info("//fld6filer/fichiersGEOfiles/Geographie_2016_Geography/Spatial_Info_Products-Produits_d'info_spatiale", recursive = TRUE) %>%
49-
# mutate(ext = fs::path_ext(path),
50-
# filepath = fs::path_file(path) %>% fs::path_ext_remove()) %>%
51-
# select(filepath, ext, type, size, path)
52-
#
53-
# y <- x %>%
54-
# filter(type == "file" & ext == "zip") %>%
55-
# pull(filepath) %>%
56-
# map_df(get_geoinfo)
57-
#
58-
# # that's a lot, holy moly.s
59-
#
60-
# shapefile_paths <- x %>%
61-
# filter(type == "file" & ext == "zip") %>%
62-
# mutate(filepath = as.character(filepath)) %>%
63-
# left_join(y, by = c("filepath" = "filename"))
64-
65-
# usethis::use_data(shapefile_paths)
66-
67-
68-
6946

7047
############# and code info
7148

7249
code_book_ <- readr::read_csv("data-raw/code_book.csv")
7350
code_book <- dplyr::select(code_book_, -start_chr, -stop_chr, -long_desc)
7451
usethis::use_data(code_book, internal = FALSE, overwrite = TRUE)
7552

76-
# save this as well.
53+
# save this as well.
7754
code_pos <- code_book_ %>%
7855
dplyr::distinct(code_type, start_chr, stop_chr)
7956
usethis::use_data(code_pos, internal = FALSE, overwrite = TRUE)

man/geoinfo.Rd renamed to man/geo_info.Rd

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)