Giter VIP home page Giter VIP logo

week-2-digging-into-databases's Introduction

Spatial Databases

Lecture

Outline

  • 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

Dates Follow Along

  1. Date Parsing
 SELECT to_timestamp('April 1, 2020',
                     'Month DD, YYYY')
  1. Getting a timestamp type from a date and time
SELECT to_timestamp('2020/04/01 18:37:14',
                   'YYYY/MM/DD HH24:MI:SS')
  1. Casting from a string:
SELECT '2020-09-08'::date
  1. Parse a human readable date string to a date type:
SELECT to_date('08 Sep 2020', 'DD Mon YYYY')
  1. 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

Mapping Follow Along

  1. Create a new map with the Station Status data
  2. Add it as a new Layer
  3. Add it as a new Layer again
  4. 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
  1. 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.

  1. Play around with the queries. You can add an ORDER BY column in the ST_MakeLine function. Try out ST_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 the ORDER BY. Also, something weird happens with the random() one. Can you spot it?

  2. Does changing the order of the query affect the Convex Hull?

Homework

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.

Lab

Resources

Recommended Software

Text Editors

week-2-digging-into-databases's People

Contributors

andy-esch avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.