This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library("RPostgreSQL") | |
driver <- dbDriver("PostgreSQL") | |
connection <- dbConnect(driver, dbname="", password="", user="", host="localhost") | |
# get the full result set from the table | |
d <- dbGetQuery(connection,"SELECT t1, t2, ST_Azimuth(ST_StartPoint(line)::geography, ST_EndPoint(line)::geography) AS azimuth, ST_Distance(ST_StartPoint(line)::geography,ST_EndPoint(line)::geography)/1000 AS distance, white AS commuters FROM wbcommute_38300 WHERE t1 != t2 AND t1 = 684;") | |
dbDisconnect(connection) | |
# this is the number of commuter-kilometers |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# make dead-ends ratio map | |
library('ks') | |
library('raster') | |
# connect to database | |
library("RPostgreSQL") | |
driver <- dbDriver("PostgreSQL") | |
connection <- dbConnect(driver, dbname="", password="", user="", host="localhost") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
generic areal apportionment of average | |
*/ | |
--table1.id | |
--table1.geom | |
--table1.value | |
--table2.geom | |
--table2.weight |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
generic areal apportionment of SUM | |
*/ | |
--table1.id | |
--table1.geom | |
--table1.value | |
--table2.geom | |
--table2.weight |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# run tarjan with igraph | |
# name of the table | |
city = 'helsinki' | |
modes = c('car','bike','foot') | |
# connect to database | |
library("RPostgreSQL") | |
driver <- dbDriver("PostgreSQL") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# toy code for playing with discrete choice models and logistic regression | |
# sample size | |
n = 2000 | |
# generate random independents | |
x1 = scale(runif(n)) | |
x2 = scale(runif(n)) | |
x3 = scale(runif(n)) | |
# 'actual' utility function that I made up | |
uy = -3 + -2 * x1 + 2 * x2 + 0.5 * x3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DROP TABLE IF EXISTS gtfs_ttc_agency; | |
CREATE TABLE gtfs_ttc_agency( | |
agency_id int, | |
agency_name text, | |
agency_url text, | |
agency_timezone text, | |
agency_lang text, | |
agency_phone text, | |
agency_fare_url text | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library('deldir') # voronoi stuff | |
library('rgdal') # postgis and spatial stuff | |
library('sp') # spatial stuff | |
library('raster') # more spatial stuff | |
library('splancs') # csr() for generating random points | |
# function from http://carsonfarmer.com/2009/09/voronoi-polygons-with-r/ | |
voronoipolygons = function(layer,bounding_box) { | |
require(deldir) | |
crds = layer@coords |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# assign a random location to every person in greater cinci | |
# inside their home census block | |
import psycopg2, random | |
from shapely import wkb | |
from shapely.geometry import Point | |
# connect to the census DB | |
conn_string = ("host='localhost' dbname='' user='' password=''") | |
census_conn = psycopg2.connect(conn_string) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# this script takes a set of points, in this case bus stops | |
# and does a centroidal voronoi tesselation weighted by | |
# those points from an initial uniform random seeding. The effect | |
# is an even-ish distribution of sample points accross the space. | |
# My goal is to use these as representative ODs for a travel time | |
# matrix that effectively samples a whole transit network. | |
library('deldir') # voronoi stuff | |
library('rgdal') # projections | |
library('sp') # spatial data types |
OlderNewer