Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
require 'csv'
require 'json'
require 'pp'
i = 0
features = []
start_line = []
end_line = []
## Loop through each row of the data
CSV.foreach("paths_final.csv") do |row|
## Get the lat and lon and convert to float
lat = row[1].to_f
lon = row[2].to_f
## Get the week day, month, and day of the month
week_day = row[3]
month = row[4]
day = row[5]
## If the first row, then there is only start of the line
if (i <= 1 )
start_line = [lon,lat]
end_line = [lon,lat]
## Add the new geoJSON data to the features array
features << {type:'Feature', properties: {week_day: week_day, month: month, day: day }, geometry: {type:'LineString', coordinates: [start_line,end_line] } }
## The end of the line is not the start of the next line
start_line = end_line
i += 1
## Add it to the entire geoJSON set
geoJSON = {type: 'FeatureCollection', features: features}
## Write to JS file for web visualization"final.js","w") do |f|
## Write to geoJSON for TileMill"final.geoJSON","w") do |f|
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.