Demo for entrance & exit number for subway stations

Demin Hu
Data Mining the City
2 min readOct 14, 2017

Thanks to William’s great help!!! Now I am trying to show the entrance & exit number for subway stations.The numbers of points moving towards / away from the station stands for the number of people passing the Turnstile between 12:00–04:00.

import spatialpixel.mapping.slippymapper as slippymapper
import csv
def setup():
size(1000, 800, P2D)
global nyc
nyc = slippymapper.SlippyMapper(40.7541529, -73.9696404, 14, 'carto-darkall', width, height)
with open('entrance01.csv') as f:
reader = csv.reader(f)
header = reader.next()
for row in reader:
traffic000 = float(row[1])
traffic400 = float(row[2])
latitude = float(row[8])
longitude = float(row[9])
data = {
'traffic000':traffic000,
'traffic400':traffic400,
'latitude':latitude,
'longitude':longitude,
}
nyc.addMarker(latitude, longitude, StationMarker(data))
nyc.render()
def draw():
background(255)
nyc.draw()
#mark.draw()
class StationMarker(slippymapper.DataMarker):
def __init__(self, data):
super(StationMarker, self).__init__(data)

self.points = []
def drawMarker(self, x, y, marker):

traffic000 = self.data['traffic000']
traffic400 = self.data['traffic400']

diam = log(traffic000)
marker.stroke(255, 0, 0)
marker.noFill()
marker.ellipse(x, y, diam, diam)
numPoints = traffic400 - traffic000
if len(self.points) == 0:
for i in xrange(numPoints):
self.points.append(MovingPoint(x, y, -1))

for pt in self.points:
pt.draw()

class MovingPoint(object):
def __init__(self, x, y, direction=1):
self.x = x
self.y = y
self.theta = random(0, TWO_PI)
self.radius = int(random(0, 20))
self.direction = direction

def draw(self):
stroke(255,0,0)
x = self.x + ((self.radius + self.direction * frameCount) % 20) * cos(self.theta)
y = self.y + ((self.radius + self.direction * frameCount) % 20) * sin(self.theta)
point(x, y)

--

--