Created
April 9, 2010 22:33
-
-
Save bmander/361664 to your computer and use it in GitHub Desktop.
This file contains 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
BufferedReader reader; | |
String line; | |
class ShapePoint { | |
public int shape_id; | |
public float lat; | |
public float lon; | |
ShapePoint( int shape_id, float lat, float lon ) { | |
this.shape_id = shape_id; | |
this.lat = lat; | |
this.lon = lon; | |
} | |
} | |
class Stop { | |
public int stop_id; | |
public float lat; | |
public float lon; | |
Stop( int stop_id, float lat, float lon ) { | |
this.stop_id = stop_id; | |
this.lat = lat; | |
this.lon = lon; | |
} | |
} | |
Vector load_shapes(String filename) { | |
Vector ret = new Vector(); | |
reader = createReader( filename ); | |
boolean first = true; | |
while( true ) { | |
try { | |
line = reader.readLine(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
line = null; | |
} | |
if(first){ | |
first=false; | |
continue; | |
} | |
if (line == null) { | |
// Stop reading because of an error or file is empty | |
break; | |
} else { | |
String[] pieces = split(line, ","); | |
int route = int(pieces[0]); | |
float lat = float(pieces[1]); | |
float lon = float(pieces[2]); | |
ret.add( new ShapePoint( route, lat, lon ) ); | |
} | |
} | |
return ret; | |
} | |
Vector load_stops(String filename) { | |
Vector ret = new Vector(); | |
reader = createReader( filename ); | |
boolean first = true; | |
while( true ) { | |
try { | |
line = reader.readLine(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
line = null; | |
} | |
if(first){ | |
first=false; | |
continue; | |
} | |
if (line == null) { | |
// Stop reading because of an error or file is empty | |
break; | |
} else { | |
String[] pieces = split(line, ","); | |
int stop_id = int(pieces[0]); | |
float lat = float(pieces[4]); | |
float lon = float(pieces[5]); | |
ret.add( new Stop( stop_id, lat, lon ) ); | |
} | |
} | |
return ret; | |
} | |
Vector shapepoints; | |
Vector stops; | |
float resolution; | |
float viewPortLeft; | |
float viewPortTop; | |
float INFINITY = 1000000000.0; | |
float left = INFINITY; | |
float bottom = INFINITY; | |
float right = -INFINITY; | |
float top = -INFINITY; | |
void setup() { | |
size(1500,1500); | |
smooth(); | |
shapepoints = load_shapes( "D:\\My Documents\\nyct_subway_100308\\shapes.txt" ); | |
stops = load_stops( "D:\\My Documents\\nyct_subway_100308\\stops.txt" ); | |
for(int i=0; i<shapepoints.size(); i++) { | |
ShapePoint sp = (ShapePoint)shapepoints.get(i); | |
left = min(left, sp.lon); | |
bottom = min(bottom, sp.lat); | |
right = max(right, sp.lon); | |
top = max(top, sp.lat); | |
} | |
println( left ); | |
println( bottom ); | |
println( right ); | |
println( top ); | |
resolution = width/(right-left); | |
viewPortLeft = left; | |
viewPortTop = top; | |
strokeWeight(0.00001); | |
background(128); | |
stroke(255); | |
scale(resolution); | |
translate( -viewPortLeft, viewPortTop ); | |
fill(255,200,200,128); | |
for(int i=0; i<stops.size(); i++){ | |
Stop stop = (Stop)stops.get(i); | |
ellipse( stop.lon, -stop.lat, 0.005, 0.005 ); | |
} | |
for(int i=0; i<shapepoints.size()-1; i++) { | |
ShapePoint sp1 = (ShapePoint)shapepoints.get(i); | |
ShapePoint sp2 = (ShapePoint)shapepoints.get(i+1); | |
point( sp1.lon, -sp1.lat ); | |
strokeWeight(0.00001); | |
if(sp1.shape_id == sp2.shape_id) { | |
line( sp1.lon, -sp1.lat, sp2.lon, -sp2.lat ); | |
} | |
} | |
save("mtasubway.png"); | |
} | |
void draw() { | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment