Created
November 9, 2011 23:23
-
-
Save mattwigway/1353519 to your computer and use it in GitHub Desktop.
Selecting a line from NextBus data
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
SELECT loc_a.oid, loc_a.vehicle, loc_a.route, loc_a.direction, transform(ST_MakeLine(loc_a.the_geom, loc_b.the_geom), 26945) AS the_geom, | |
(ST_Length(transform(ST_MakeLine(loc_a.the_geom, loc_b.the_geom), 26945))/ | |
(EXTRACT(EPOCH FROM loc_b.time) - EXTRACT(EPOCH FROM loc_a.time))) * | |
2.23693629 AS mph, loc_a.time AS starttime, loc_b.time AS endtime | |
INTO acrt.lametrolines | |
FROM | |
(SELECT *, ROW_NUMBER() OVER (ORDER BY vehicle, time) AS num FROM acrt.nextbus) AS loc_a | |
JOIN | |
(SELECT *, ROW_NUMBER() OVER (ORDER BY vehicle, time) AS num FROM acrt.nextbus) AS loc_b | |
ON (loc_a.vehicle = loc_b.vehicle AND | |
loc_a.route = loc_b.route AND | |
loc_a.direction = loc_b.direction AND | |
(loc_a.num + 1) = loc_b.num) | |
WHERE loc_a.time <> loc_b.time; | |
ALTER TABLE acrt.lametrolines ADD COLUMN traversal int2; | |
UPDATE acrt.lametrolines SET traversal = EXTRACT(EPOCH FROM endtime - starttime); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment