geo co - rtd denver

17
GEO Colorado RTD Transit Data using CartoDB

Upload: mikegiddens

Post on 27-Jan-2015

118 views

Category:

Technology


3 download

DESCRIPTION

Presentation on CartoDB at the Colorado Meetup using the RTD Denver transportation routes.

TRANSCRIPT

Page 1: Geo CO - RTD Denver

GEO Colorado

RTD Transit Data using CartoDB

Page 2: Geo CO - RTD Denver

Key Points

• Introduce CartoDB

• Explain about CartoCSS

• SQL via CartoDB API's

• Telling your story

Page 3: Geo CO - RTD Denver

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

Page 4: Geo CO - RTD Denver

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!!!

Page 8: Geo CO - RTD Denver

Data & Software

Shapefiles Used

• http://www.rtd-denver.com/Developer.shtml

Software Used

• HTML, JavaScript, CSS

• jQuery

• CartoDB, Leaflet, CloudMade Tiles

Page 9: Geo CO - RTD Denver

Interative Line Routes

Page 11: Geo CO - RTD Denver

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/

Page 12: Geo CO - RTD Denver

CartoCSS

#busroutes{

line-width:2;

[new_route="16"]{

line-color:#BD362F

}

[new_route="1"]{

line-color:#51A351

}

}

Page 13: Geo CO - RTD Denver

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.

Page 14: Geo CO - RTD Denver

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/

Page 15: Geo CO - RTD Denver

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!!!

Page 16: Geo CO - RTD Denver

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‘

Page 17: Geo CO - RTD Denver

Better Methods & Missing API’s

• PgRoute http://pgrouting.org/

• API for route time tables

• Preferred Transfer locations