Closed layik closed 5 years ago
In for sure, this is fantastic work @layik and great work on identifying that endpoint!
So just to be clear, this is like:
x
number of most travelled ODnow go away and do your uptake
for these?
Would ukboundaries
cause an issue? Can we get it into pct
??
BTW the lines that this function pulls in are more detailed that the lines in the PCT because the PCT simplifying things by using this function to convert 2 lines between the same zones into a single line:
https://www.rdocumentation.org/packages/stplanr/versions/0.0.2/topics/onewayid
> object.size(ukboundaries::cas2003_vsimple)
9857296 bytes
> 9857296/1024/1024
[1] 9.40065
Yes just take the vital and small data from ukboundaries
and put it in there is my thinking...
Right, will do!!
But wait...
Waiting... can be done tomorrow!
ukboundaries::msoa2011_vsimple
that's the one we want, right?
That will be useful for sure.
zones = ukboundaries::msoa2011_vsimple[
grepl(area, ukboundaries::msoa2011_vsimple$msoa11nm,
ignore.case = T), ]
OK would be renamed pct_area_desire_lines_msoa
or similar.
But you said:
> object.size(ukboundaries::cas2003_vsimple)
oh, just my bad :) try again
> object.size(ukboundaries::msoa2011_vsimple)
10616416 bytes
> 10616416/1024/1024
[1] 10.1246
In other words, it's too big:
pryr::object_size(ukboundaries::msoa2011_vsimple)
#> Using default data cache directory ~/.ukboundaries/cache
#> Use cache_dir() to change it.
#> 8.04 MB
Created on 2019-03-07 by the reprex package (v0.2.1)
or whichever does this job, you know these objects much much better than me.
yep! too big.
So why not just take the dataframe and remove the geometry...
pryr::object_size(sf::st_drop_geometry(ukboundaries::msoa2011_vsimple))
#> Using default data cache directory ~/.ukboundaries/cache
#> Use cache_dir() to change it.
#> 1.41 MB
Created on 2019-03-07 by the reprex package (v0.2.1)
And you could just use...
pryr::object_size(ukboundaries::msoa2011_vsimple$msoa11cd)
#> Using default data cache directory ~/.ukboundaries/cache
#> Use cache_dir() to change it.
#> 548 kB
Created on 2019-03-07 by the reprex package (v0.2.1)
and the name of course...
We are working on the exact lines :)
Although pls convert it with as.character()
first : )
> pryr::object_size(ukboundaries::msoa2011_vsimple[,c("msoa11cd", "msoa11nm")])
7.76 MB
:( much bigger with string names
No, that's included the geometry. sf
geometry
columns are sticky.
oh!
Try:
reprex::reprex(
pryr::object_size(sf::st_drop_geometry(ukboundaries::msoa2011_vsimple[,c("msoa11cd", "msoa11nm")]))
)
Right, let me put that in and rewrite above! about 1mb
> pryr::object_size(sf::st_drop_geometry(ukboundaries::msoa2011_vsimple[,c("msoa11cd", "msoa11nm")]))
1.13 MB```
Will be useful for the advanced pct courses. You up for helping on those?
Also try running the actual command:
reprex::reprex(
pryr::object_size(sf::st_drop_geometry(ukboundaries::msoa2011_vsimple[,c("msoa11cd", "msoa11nm")]))
)
it should copy the result onto your clipboard.
Sure, looks like I am learning this thing :)
I know don't worry, had ran that line as you pasted it :)
Let's get the pkg ready to open to the world first...
Here :)
pryr::object_size(sf::st_drop_geometry(ukboundaries::msoa2011_vsimple[,
c("msoa11cd", "msoa11nm")]))
#> Using default data cache directory ~/.ukboundaries/cache
#> Use cache_dir() to change it.
#> 1.13 MB
Created on 2019-03-07 by the reprex package (v0.2.1)
Yay!
Let me send this PR, need to add/doc data first.
Hypothesis: that will become your default way of sharing reproducible examples in R. R for Reproducibility!
OK. Over and out for now. Amazing work brother. I'm off to 💤 land.
stplanr::od2line
needs the geometry I think to get the zones centroids. Discuss tomz or later.
Latest thinking on this: create a function to get_centroids_ew()
. PR to follow.
I think PR https://github.com/ITSLeeds/pct/pull/8 solves 3 issues:
The new function can build on this I think.
pct_area_desire_lines = function(area = "sheffield", n = 100) {
if(!exists("area"))
stop("area is required.")
if(length(area) != 1L)
stop("'package' must be of length 1")
if(is.na(area) || (area == "") || !is.character(area))
stop("invalid area name")
census_file = file.path(tempdir(), "wu03ew_v2.csv")
if(!exists(census_file)) {
download.file("https://s3-eu-west-1.amazonaws.com/statistics.digitalresources.jisc.ac.uk/dkan/files/FLOW/wu03ew_v2/wu03ew_v2.zip",
file.path(tempdir(), "wu03ew_v2.zip"))
unzip(file.path(tempdir(), "wu03ew_v2.zip"), exdir = tempdir())
}
od_all = readr::read_csv(census_file)
zones_all = pct::get_centroids_ew() # TODO: some warning?
zones = zones_all[
grepl(area, zones_all$msoa11nm,
ignore.case = T), ]
od_area = od_all[od_all$`Area of residence` %in% zones$msoa11cd &
od_all$`Area of workplace` %in% zones$msoa11cd, ]
od_area = od_area[od_area$`Area of residence` !=
od_area$`Area of workplace`, ]
od_area = od_area[order(od_area$`All categories: Method of travel to work`,
decreasing = TRUE),]
od_area = od_area[1:n,]
area_desire_lines = stplanr::od2line(
flow = od_area[,c(2,1)], zones)
area_desire_lines
}
d = pct_area_desire_lines(area = "wakefield")
#> Parsed with column specification:
#> cols(
#> `Area of residence` = col_character(),
#> `Area of workplace` = col_character(),
#> `All categories: Method of travel to work` = col_double(),
#> `Work mainly at or from home` = col_double(),
#> `Underground, metro, light rail, tram` = col_double(),
#> Train = col_double(),
#> `Bus, minibus or coach` = col_double(),
#> Taxi = col_double(),
#> `Motorcycle, scooter or moped` = col_double(),
#> `Driving a car or van` = col_double(),
#> `Passenger in a car or van` = col_double(),
#> Bicycle = col_double(),
#> `On foot` = col_double(),
#> `Other method of travel to work` = col_double()
#> )
#> Parsed with column specification:
#> cols(
#> X = col_double(),
#> Y = col_double(),
#> objectid = col_double(),
#> msoa11cd = col_character(),
#> msoa11nm = col_character()
#> )
Created on 2019-03-08 by the reprex package (v0.2.1)
And mapview
will show you this!
Great work sir!
od_area = od_area[order(od_area$`All categories: Method of travel to work`,
decreasing = TRUE),]
od_area = od_area[1:n,]
That is clever. I'm sooooo glad you're not wedded to the tidyverse
. Compsci thinking not narrow thinking.
I dislike this though:
$`All categories: Method of travel to work`
Please override wherever you dislike! All I am doing is trying to use code that is R Foundation and not "tidyverse" foundation.
In base r but
requires
ukboundaries and stplanr.Thoughts @Robinlovelace. I can send a PR too.