Download - Geo CO - RTD Denver
GEO Colorado
RTD Transit Data using CartoDB
Key Points
• Introduce CartoDB
• Explain about CartoCSS
• SQL via CartoDB API's
• Telling your story
CartoDB
• Geospatial mapping
• Data stored in the cloud
• PostGIS engine
• Supports CartoCSS
• SQL API
• Leaflet and Google Maps Libraries
• Graphical Editor for Point & Polygons
• Lots of Examples
• Free 5MB account
• FAST!!!
www.cartodb.com
RTD Transit Data Example
Goal: To create an interactive map to get the
nearest location from where I am at and to find
any intersecting routes based on my
destination.
Requirements:
• Use open data
• Use open source software
• Real Time Interaction
• Enjoyable to users
• Make it informative and Fast!!!
Existing Portal
http://www.rtd-denver.com
Existing Portal
http://www.rtd-denver.com
Existing Portal
http://www.rtd-denver.com
Data & Software
Shapefiles Used
• http://www.rtd-denver.com/Developer.shtml
Software Used
• HTML, JavaScript, CSS
• jQuery
• CartoDB, Leaflet, CloudMade Tiles
Interative Line Routes
DEMO
http://goo.gl/NWhpG
http://silverbiology.com/projects/cartodb/casestudies/denverrtd/
Resources
CartoCSS:
• http://mapbox.com/tilemill/docs/manual/carto/
• http://mapbox.com/carto/latest.html
CartoDB: http://www.cartodb.com
Leaflet: http://leaflet.cloudmade.com/
CartoCSS
#busroutes{
line-width:2;
[new_route="16"]{
line-color:#BD362F
}
[new_route="1"]{
line-color:#51A351
}
}
SQL Queries
# All stops for a single route
SELECT * FROM
(SELECT * FROM
(SELECT replace(regexp_split_to_table(routes, E','), ' ', '') as
new_route, bsid, the_geom FROM busstops) as a
WHERE a.new_route='6') as b
Regexp_split_to_table ref: http://www.postgresql.org/docs/8.3/static/functions-matching.html
Example: “6, 12, 8, 112, 104” will be transformed to individual rows.
SQL Queries
#closest bus stops
SELECT * FROM busstops
ORDER BY the_geom <-> st_setsrid(st_makepoint(-106, 39),4326)
LIMIT 5
Indexed Nearest Neighbor Search
• Using the <-> operator, you get the nearest neighbor using the centers of
the bounding boxes to calculate the inter-object distances.
• Using the <#> operator, you get the nearest neighbor using the bounding
boxes themselves to calculate the inter-object distances.
Ref: http://blog.opengeo.org/tag/knn/
WGS 84 (4326) http://spatialreference.org/ref/epsg/4326/
SQL Queries
# returns a row if the bus stops are on the same route
SELECT c.* FROM busroutes c JOIN
(SELECT a.new_route, a.bsid, b.bsid FROM
(SELECT replace(regexp_split_to_table(routes, E','), ' ', '') as
new_route, bsid, the_geom FROM busstops WHERE bsid =
'{{{START STOP ID}}}') as a
JOIN (SELECT replace(regexp_split_to_table(routes, E','), ' ', '') as
new_route, bsid, the_geom FROM busstops WHERE bsid = '{{{END
STOP ID}}}') as b ON a.bsid = b.bsid) as d
ON d.new_route = c.route
How to write a query to graph routes for 1st or 2nd degree route. Bus transfers!!!
Failed Queries???
#Only show the line between two points that fall on the bus route
SELECT st_transform( ST_Line_Substring(the_geom,
(SELECT ST_Line_Locate_Point(
(SELECT ST_GeometryN(the_geom,5) FROM busroutes WHERE route='6')
,
(SELECT the_geom FROM (SELECT replace(regexp_split_to_table(routes, E','), ' ', '') as new_route,
bsid, the_geom FROM busstops WHERE bsid = 12978) as a WHERE a.new_route='6'
))),
(SELECT ST_Line_Locate_Point(
(SELECT ST_GeometryN(the_geom,5) FROM busroutes WHERE route='6'),
(SELECT the_geom FROM (SELECT replace(regexp_split_to_table(routes, E','), ' ', '') as new_route,
bsid, the_geom FROM busstops WHERE bsid = 10227) as a WHERE a.new_route='6'
)))), 3857) as the_geom_webmercator
FROM busroutes WHERE route = '6‘
Better Methods & Missing API’s
• PgRoute http://pgrouting.org/
• API for route time tables
• Preferred Transfer locations