Skip to content

Script to download and rename shapefiles, so we can create the geopackages for OD SP 2023#53

Open
beatrizmilz wants to merge 2 commits into
mainfrom
issue-48-nova-od
Open

Script to download and rename shapefiles, so we can create the geopackages for OD SP 2023#53
beatrizmilz wants to merge 2 commits into
mainfrom
issue-48-nova-od

Conversation

@beatrizmilz

Copy link
Copy Markdown
Collaborator

This is related to #48

@hsvab asked me how did we generate the .gpkg files for the previous OD data, so she could run for 2023.

This happens in the file data-raw/sao_paulo/prep_data-sao_paulo.R:

# Maps -------------------------------------------------------------------------
for (year in years) {
for (harmonization in harmonize) {
for (level in city_levels) {
filename_map <- paste0(
compose_file_path(
city,
year,
harmonization
),
"/",
level,
year,
"_region.shp"
)
file_to_upload <- paste0(
compose_file_path(
city,
year,
harmonization
),
"/",
compose_name(
city,
year,
harmonization,
level
),
".gpkg"
)
# File name translating
file_to_upload <- gsub("Zonas",
"zone",
file_to_upload,
ignore.case = TRUE
)
file_to_upload <- gsub("Municipios",
"municipality",
file_to_upload,
ignore.case = TRUE
)
file_to_upload <- gsub("Distritos",
"district",
file_to_upload,
ignore.case = TRUE
)
if (file.exists(filename_map) == TRUE) {
# Reading shape files, if it exists
od_map <- sf::read_sf(filename_map)
# Writing a gpkg unique file
sf::write_sf(od_map, file_to_upload)
# Uploading a file to a specific release from odbr repo (see parameter)
piggyback::pb_upload(
file = file_to_upload,
repo = repository,
tag = tag
)
rm("od_map")
}
}
}
}

More especifically, in this part:

if (file.exists(filename_map) == TRUE) {
# Reading shape files, if it exists
od_map <- sf::read_sf(filename_map)
# Writing a gpkg unique file
sf::write_sf(od_map, file_to_upload)

BUT the .shp file has to have an exact file name in order for this code to work.
For example:

> filename_map
[1] "data-raw/sao_paulo/2023/not_harmonized/Zonas2023_region.shp"

In the file data-raw/download-and-rename-shapefiles.R (created in this PR) I documented the process of downloading the .zip from OD São Paulo 2023, moving and renaming the files so it works when you run the code in data-raw/sao_paulo/prep_data-sao_paulo.R.

Let me know if this helped or if you need anything else!

Bea

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant