Skip to content

Instantly share code, notes, and snippets.

@AndrewTheTM
Last active October 8, 2015 13:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewTheTM/39fec66e5f7f3cb5872b to your computer and use it in GitHub Desktop.
Save AndrewTheTM/39fec66e5f7f3cb5872b to your computer and use it in GitHub Desktop.
R+OMX County Flow
modelPath = "C:\\Modelrun\\Model80\\Base\\"
source("http://raw.githubusercontent.com/osPlanning/omx/dev/api/r/omx.R")
ZtoC = A1201[,c("TAZ","COUNTY")] # This is the TAZ-County equivalence table
hbwpk = readMatrixOMX(paste(modelPath,"HBWPK.OMX",sep=""),"M1")
cnames = rbind('HAMILTO', 'CLERMON', 'BUTLER', 'WARREN', 'BOONE', 'CAMPBEL', 'KENTON', 'DEARBOR') #could probably also do rbind(unique(ZtoC$COUNTY))
hbwpk.cf = matrix(0,length(cnames),length(cnames))
for(ic in 1:length(cnames)){
for(jc in 1:length(cnames)){
hbwpk.cf[ic,jc] = sum(hbwpk[which(seq(1:nrow(hbwpk)) %in% ZtoC[which(ZtoC$COUNTY == cnames[ic]),"TAZ"]),
which(seq(1:ncol(hbwpk)) %in% ZtoC[which(ZtoC$COUNTY == cnames[jc]),"TAZ"])])
}
}
# Optional
rownames(hbwpk.cf) = cnames
colnames(hbwpk.cf) = cnames
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment