- Slides
- Follow along demo
- Housekeeping
- Office Hours - OHQ and office hour times
- Updates to Syllabus
- Homework via GitHub classroom (check class Canvas page for link to assignment)
- Introduction to databases
- PostgreSQL
- Review of SQL queries
- Keywords (SELECT, FROM, LIMIT, WHERE, GROUP BY, ORDER BY)
- Anatomy of a SQL query
- Data types
- Date type follow along
- Documentation
- Spatial SQL (PostGIS)
- Geometry data type (points, lines, polygons, other)
- What you can do with geometry / functions available
- Mapping follow along
- Structure of CARTO, a web application
- Homework
- Date Parsing
SELECT to_timestamp('April 1, 2020',
'Month DD, YYYY')
- Getting a timestamp type from a date and time
SELECT to_timestamp('2020/04/01 18:37:14',
'YYYY/MM/DD HH24:MI:SS')
- Casting from a string:
SELECT '2020-09-08'::date
- Parse a human readable date string to a date type:
SELECT to_date('08 Sep 2020', 'DD Mon YYYY')
- Extracting part of a date:
SELECT
EXTRACT(month from '2020-09-08'::date) as date_month,
EXTRACT(day from '2020-09-08'::date) as date_day,
EXTRACT(year from '2020-09-08'::date) as date_year
- Create a new map with the Station Status data
- Add it as a new Layer
- Add it as a new Layer again
- Choose one Layer and add this SQL to it, making sure to update your username/schema instead of mine:
SELECT
the_geom,
ST_Transform(the_geom, 3857) as the_geom_webmercator,
1 as cartodb_id
FROM (
SELECT ST_MakeLine(the_geom) as the_geom
FROM andyepenn.indego_station_status
) as _w
- Choose another Layer and add this SQL to it, again making sure to change the username/schema for the table:
SELECT
the_geom,
ST_Transform(the_geom, 3857) as the_geom_webmercator,
1 as cartodb_id
FROM (
SELECT ST_ConvexHull(ST_Collect(the_geom)) as the_geom
FROM andyepenn.indego_station_status
) as _w
A convex hull is a bounding shape that minimally encompasses all the external points/lines/polygons, kind of like a rubber band around your fingers.
-
Play around with the queries. You can add an
ORDER BY column
in theST_MakeLine
function. Try outST_MakeLine(the_geom ORDER BY id)
,ST_MakeLine(the_geom ORDER BY addresszipcode)
,ST_MakeLine(the_geom ORDER BY random())
. Yes, that's a weird spot for theORDER BY
. Also, something weird happens with therandom()
one. Can you spot it? -
Does changing the order of the query affect the Convex Hull?
Due by Sept 15, 11:59pm ET via GitHub classroom
Submit Homework 1 through GitHub classroom. Check our class Canvas page announcements for the signup link.
Note: You need a GitHub account to complete the assignment. If you are unfamiliar with it, please ask Andy or Felix for assistance. Thursday's Lab will have a 10-15 minute portion on GitHub.
Text Editors