← Methods 3

In-class Exercises

Part 1: the Field Calculator

  1. Download today's data if you haven't already.
  2. Open queens_census_tracts_joined in QGIS.
  3. We are going to use the Field Calculator and Refactor functions of QGIS to clean up the attribute table and perform some calculations on it.
  4. Use the field calculator to divide renters by households. Put the result in a field called s_renters. The expression should look like this:
    "renters" / "households"
    and make the field a Decimal number with Output field length 10 and Precision 8.
  5. Use the field calculator to create a new field called medincome2 that is med_income but an integer rather than text. This is tricky because some of the values in med_income cannot be converted to numbers. You'll need to use an expression like this:
    if( "med_income" = '-',
        NULL,
        to_int("med_income"))
  6. Turn off editing mode by clicking the pencil icon and save the changes to the shapefile when prompted.
  7. Refactor the attribute table (using Refactor in the search bar) to get rid of some fields we no longer need:
    • owners
    • renters
    • med_income
    and rename medincome2 to med_income.

Part 2: Modeling

In this part we will use the data we worked with in the previous part to make a simple model. We will attempt to make a model that can predict where there will be more pressure on renters due to Airbnb listings in their neighborhoods.

  1. Continue with the file from the previous part. If you did not complete the previous part, open the shapefile in part2_start.
  2. Open the Airbnb listings shapefile in airbnb_listings_20181001_queens and use Count points in polygons to determine how many Airbnb listings exist in each census tract.
  3. Using the field calculator, create two new fields. The new fields should scale each field using scale_linear.
    1. First, med_income has a minimum value of 15474, maximum value of 151964, so we use this expression in the field calculator:
      scale_linear("med_income", 
          15474, 151964,
          1, 0)
      Add an s_ at the beginning of the new field name to indicate that it is scaled. In this case, med_income becomes s_income (since you can only use 10 characters in a name). s_income should be a decimal number field with length 10 and precision 8.
    2. Follow a similar process for NUMPOINTS (created when we calculated the Airbnb listings per tract):
      scale_linear("NUMPOINTS", 
          minimum points, maximum points,
          0, 1)
      You'll need to find the minimum and maximum values for NUMPOINTS. Make the resulting field s_airbnb, also a decimal number with length 10 and precision 8.
  4. Create a graduated style for the tracts. For the column expression, add each of the scaled fields (s_airbnb, s_renters, s_income) together.

Part 3: Carto

  1. Zip the shapefile in airbnb_listings_20181001_queens.
  2. Log in to your Carto account, go to the Datasets section, and upload the zip file to your Carto account.
  3. Create a map with the uploaded dataset.
  4. Change the styles of the points:
    1. Style the points by value with the room_type column to make a categorized style.
    2. Style the points by value with the price column to make a graduated style.
  5. Publish the map and get the public link for it.