Category: Software

I played “Cities: Skylines” for the first time

I wouldn’t have guessed that this city simulation video game turned eight years old last month. I’ve known about it for a long time, and I even subscribe to the r/CitiesSkylines subreddit to see screenshots that people post showing their cities.

screenshot of a town created by u/Tramter123 (posted to Reddit) showing a lot of surface car parking lots
The screen grab above isn’t mine. It looks like u/Tramter123 got carried away trying to recreate Any American City and built a lot of surface parking lots. I will need to learn how that affects traffic flows and land values in the game’s mechanics.

What changed is that last week I was having dinner with a friend and he described the videos published by City Planner Plays, a practicing urban planner who resides in Madison, Wisconsin. I watched a video with a title that caught my attention (it was about monorails and trams) and a couple of days later I decided to try it out.

My first gaming session was a little frustrating or stressful…I don’t think having studied how cities happen and how they happened has given me any insight into how to be successful at this game.

I’m still learning how to manipulate the game yet I’m already familiar with the process of this game that it shares with many others: as something grows, you unlock more resources but have to respond to more needs. In Cities: Skylines, the population grows, a cemetery is unlocked, and then someone dies so you have to build a cemetery immediately.

In Rollercoaster Tycoon, the goal was to increase your park’s visitors by building more rides. As attendance grew so did the level of trash and the number of janitors that had to be hired, but sometimes you had to wait to earn more revenue because you couldn’t afford a third janitor yet.

My little town in CS is called Springvalley, which started with being connected to an expressway interchange. The water source is a river. I tried to build a quay and some waterfront property but the city is on a cliff and I wasted a bunch of money trying to level and reshape the earth.

Since Springvalley reached a population of 2,500 people this evening (during my second session of the day) the game unlocked transit. Okay, I think this is why I want to keep playing – I want to see if I can design a transit network bound by whatever constraints the game has implemented.

City-building in real life

I posed a couple of questions to myself after playing. City-building is kinda fun [yeah, duh] but is it possible to make real-life city building fun and more broadly enjoyed?

Relatedly, are there ways I can modify and use Chicago Cityscape to guide people through the local city-building process using the fun and mechanism games like Cities: Skylines (and its predecessor, SimCity)? Read Anthony Moser’s response.


Enjoy this short video of the camera following a bus to the industrial district (and excuse all of the pollution).

Creating a PostgreSQL PostGIS function to get around a DataTables Editor limitation

DataTables is a fantastic software that turns any HTML table into an interactive and editable one.

Chicago Cityscape uses DataTables on pretty much every page. DataTables also provides server-side processing for PHP to grab the right data from a database and show it to the user, 10 records at a time (the number of records can be changed by the user to show more records at a time).

Screenshot showing my new function, using the function, and the results.

Problem

One of the problems I’ve had to get around is that the DataTables Editor script recognizes a SELECT statement with only one function per field. If there’s a second function that’s manipulating a field in the SELECT statement then the ALIAS won’t work and the JavaScript will not be able to read and show the data properly.

I almost always use the two functions ST_AsGeoJSON and ST_Transform on my geographic data to (1) transform it from the SRID of 3435 to 4326 for displaying on web mercator maps, and (2) converting the GIS data into GeoJSON strings for easy transference to the Leaflet JavaScript library.

This is a known issue – see this thread on the DataTables forums – that Allan, the DataTables creator, has acknowledged and provided an alternative solution for.

Solution

It turns out that it’s easy to write a function that combines both functions.

CREATE OR REPLACE FUNCTION ST_TAGJP (field geometry, srid int =4326, simplify int =5)
  RETURNS text
RETURN ST_AsGeoJSON(ST_Transform(field, srid), simplify);

The code above is a function I call ST_TAGJP that combines the two functions I already described, and is flexible by letting the user specify in the arguments the table and field, the SRID to transform (reproject) to, and the simplify variable that can be used in ST_AsGeoJSON that tells it how many decimal points to use in coordinates.

Converting a transit agency’s GTFS to shapefile and GeoJSON with QGIS

Many years ago I wrote a tutorial on how to use an ArcGIS plugin to convert a transit agency’s GTFS package – a group of files that describe when and where their buses and trains stop – into files that could easily be manipulated by popular GIS desktop software.

That was so long ago, before I became an expert in using QGIS, a free and open source alternative to ArcGIS.

This tutorial will show you how to convert GTFS to a shapefile and to GeoJSON so you can edit and visualize the transit data in QGIS.

Prerequisites

First you’ll need to have QGIS installed on your computer (it works with Linux, Mac, and Windows). Second you’ll need a GTFS package for the transit agency of your choice (here’s the one for Pace Suburban Bus*, which operates all suburban transit buses in Chicagoland). You can find another transit agency around the world on the GTFS Data Exchange website.

Section 1: Let’s start

  1. Open QGIS.
  2. Load your GTFS data into the QGIS table of contents (also called the Layers Panel). Click Layer>Add Layer>Add Delimited Text Layer. You will be adding one or two files depending on which ones are provided.

    QGIS add delimited text layer

    Add delimited text layer.

  3. Now, here it can get tricky. Not all transit agencies provide a “shapes.txt” file. The shapes.txt file draws out the routes of buses and trains. If it’s not provided, that’s fine, but if you turn them into routes based on the stops.txt data, then you will have funny looking and impossible routes.

    QGIs browse for the stops.txt file

    Browse for the stops.txt file

  4. Click on “Browse…” and find the “stops.txt”. QGIS will read the file very quickly and determine which fields hold the latitude and longitude coordinates. If its determination is wrong, you can choose a different “X field” (longitude) and “Y field” (latitude).
  5. Click “OK”. A new dialog box will appear asking you to choose a coordinate reference system (EPSG). Choose or filter for “WGS 84, EPSG:4326”. Then click “OK”.
  6. The Pace bus stops in the Chicagoland region are now drawn in QGIS!

    Pace bus stops are shown

    Pace bus stops are shown

  7. If the GTFS package you downloaded includes a “shapes.txt” file (that represents the physical routes and paths that the buses or trains take), import that file also by repeating steps 4 and 5.

Section 2: Converting the stops

It’s really easy now to convert the bus or train stops into a shapefile or GeoJSON representing all of those points.

  1. Right-click the layer “stops” in the table of contents (Layers Panel) and click “Save As…”.
  2. In the “Save vector layer as…” dialog box, choose the format you want, either “ESRI Shapefile” or “GeoJSON”. **
  3. Then click “Browse” to tell QGIS where in your computer’s file browser you want to save the file. Leave the “CRS” as-is (EPSG:4326).

    Convert the bus stops to a shapefile or GeoJSON.

    Convert the Pace bus stops to a shapefile or GeoJSON.

  4. Then click “OK” and QGIS will quickly report that the file has been converted and saved where you specified in step 3.

Section 3: Converting the bus or train routes

The “shapes.txt” file is a collection of points that when grouped by their route number, show the physical routes and paths that buses and trains take. You’ll need a plugin to make the lines from this data.

  1. Install the plugin “Points to Paths”. Click on Plugins>Manage and Install Plugins… Then click “All” and search for “points”. Click the “Points to Paths” plugin and then click the “Install plugin” button. Then click “Close”.

    Install the Points to Paths plugin.

    Install the Points to Paths plugin.

  2. Pace bus doesn’t provide the “shapes.txt” file so we’ll need to find a new GTFS package. Download the GTFS package provided by the Chicago Transit Authority, which has bus and rail service in Chicago and the surrounding municipalities.
  3. Load the CTA’s “shapes.txt” file into the table of contents (Layers Panel) by following steps 4 and 5 in the first section of this tutorial.  Note that this data includes both the bus routes and the train routes.

    QGIS load CTA bus and train stops

    Import CTA bus and train stops into QGIS

  4. Now let’s start the conversion process. Click on Plugins>Points to Paths. In the next dialog box choose the “shapes” layer as your “Input point layer”.
  5. Select “shape_id” as the field with which you want to “Point group field”. This tells the plugin how to distinguish one bus route from the next.
  6. Select “shape_pt_sequence” as the field with which you want to “Point order field”. This tells the plugin in what order the points should be connected to form the route’s line.
  7. Click “Browse” to give the converted output shapefile a name and a location with your computer’s file browser.
  8. Make sure all  of the options look like the one in this screenshot and then click “OK”. QGIS and the plugin will start working to piece together the points into lines and create a new shapefile from this work.

    These are the options you need to set to convert the CTA points (stops) to paths (routes).

    These are the options you need to set to convert the CTA points to paths (routes).

  9. You’ll know it’s finished when the hourglass or “waiting” cursor returns to a pointer, and when you see a question asking if you would like the resulting shapefile added to your table of contents (Layers Panel). Go ahead and choose “Yes”.

    QGIS: CTA bus and train points are converted to paths (routes)

    The CTA bus and train points, provided in a GTFS package, have been converted to paths (routes/lines).

  10. Now follow steps 1-4 from Section 3 to convert the routes/lines data to a shapefile or GeoJSON file.**

Notes

* As of this writing, the schedules in Pace’s GTFS package are accurate as of January 18, 2016. It appears their download link always points to the latest version. Transit schedules typically change several times each year. Pace says, “Only one package is posted at any given time, typically representing Pace service from now until a couple of months in the future. Use the Calendar table to see on which days and dates service in the Trips table are effective.”

** Choose GeoJSON if you want to show this data on a web map (like in Leaflet or the Google Maps API), or if you want to share the data on GitHub.

Why the Slow Roll Chicago working group uses GitHub to collaborate

When the Slow Roll Chicago project in the transportation breakout group began in December at Hack Night, the emails started flying right away.

This was mainly because there was a lot to say at the start, as we needed to agree on the group’s mission and plan.

Problems using email started immediately, though. Not only were there many emails going back and forth among people listed on the TO and CC fields, there were people who weren’t able to take part in these discussions.

That happened because it was difficult to keep track of who had been added to the discussion and who hadn’t, especially when it came to integrating new members of the group.

I wanted to overcome these problems by using a proper collaboration tool.

Email wasn’t just limiting our discussion quality and member inclusion, it was also limiting file storage, file sharing, and file versioning (which file is the latest?). Email has tended to demand a lot of attention, and there’s a lot of wasted time typing responses. I wanted to use a tool that didn’t have such demands, and that helped organize responses into actionable requests and delegation.

Using email made it impossible to see what tasks people were working on, and the progress they were making at any given moment.

Finally, email tends to be private but our work needed to be public so that it could be independently verified but also replicated for use in other locales.

I believe that it’s easier to train people on how to use a new tool well than to retrain on how to use an existing tool – email – better.

GitHub has solved all of these problems for our group while also creating a secure and versioned programming code storage system for the final outcome: a website.

Hack Night being a tech-oriented meetup is a good reason to use and teach this modern tool widely used by people in technology industries. Many of our members are still learning it but they have support from people within our group and from others who attend Hack Night.

GitHub handles our discussions, task assignments, task progress, notes, and files. Here’s how:

When you want to discuss a new idea, like using dynamic images to show what a building could look like under certain conditions, you would make a new “issue”, titled, “Use dynamic images to show the user some building design possibilities”. Use rich text and images in the issue to describe and visualize the idea.

GitHub has granular notifications settings that alert project members to this new “issue” after which they can respond to your idea. After it’s decided that the issue should be resolved in a specific way, you can assign the issue a desired milestone (a future project version) and project members.

One milestone could be “Preview to the management team” which is a previously-discussed status that should happen in a couple weeks. A second milestone could be “Post-launch” – things to finish after launching the product – that’s defined offline.

Each milestone tracks the issues that you’ve associated with it so you can see progress. When the assigned members finish a task, they “resolve” the issue by closing it.

Need documentation? For many coding or GIS projects, a data dictionary may be necessary and GitHub provides each project repository with a wiki in which you would describe how the project is set up, and what certain fields or values mean.

Finally, GitHub can store files – any kind, and as many versions. If you need to update a CSV file of street addresses for the project, just make the edits in your preferred editor on the desktop and then “commit” your changes with a short description of what you changed. Sync this commit back to the repository so that all project members now have access to the file.

New iOS app offers most advanced Divvy route directions

Chicago Bike Route for iOS

Walking directions from my house to the Divvy station at the CTA California Blue Line station, and then from there to the Divvy station at LaSalle/Illinois Streets. Lastly, there’s walking directions to some arbitrary N LaSalle Street address.

Adam Gluck and Andrew Beinstein showed up at OpenGov Hack Night on July 16, 2013, to show off the technical concept of their forthcoming app for iOS devices. I looped them into the Divvy app-making progress I and others were undertaking (documented on a shared Google Doc).

They said they would make their app was going quite different from all of the eight apps for using Divvy that have since launched before theirs: it would offer directions for walking to the nearest Divvy station with available bikes, directions to the Divvy station nearest their destination with open docks, and then walking directions from that end station to their destination.

Chicago Bike Route launched Friday last week. Currently only three of the eight iOS apps released before Chicago Bike Route have routing. CBR takes directions to a new level by giving you directions from where you are to where you want to go, and not necessarily from a specific Divvy station (like my Chicago Bike Guide does). Instead, CBR gives you complete directions between origin and destination and smartly picks the nearest Divvy station with available bikes. Now, I believe most often this will just be the nearest Divvy station, period, as it’s relatively rare for a station to lack bicycles.

The app uses Google Directions and for every trip makes a maximum of three calls to their API; counts against the app’s free quota from Google. The first call gets walking directions from the origin to the nearest Divvy station with available bikes, and the second call gets bicycling directions to the Divvy station with available docks nearest the destination, and the third call (assuming the destination isn’t that Divvy station) gets walking directions from the end Divvy station to your destination. The next step, I believe, is to have the app use a prediction model to accurately choose the end Divvy station. A lot can happen at that Divvy station in the 30 minutes (or whatever) it takes to get there. It may not have open docks when you arrive.

Two other suggestions I have: an improvement to the autocomplete destination function because it didn’t recognize “Chicago city hall” or its address, “121 N LaSalle Street”; and adding a “locate me” button. Additionally I’d like them to add some basic resources to advise users on where they can get more information about Divvy or bicycling in Chicago.

Adam and Andrew are going to publish a “dock surfing” function in the app that will incorporate multiple segments on Divvy to make a trip longer than the free 30 minute period. This would probably mean a fourth call to the Google Directions API. I emailed Adam and Andrew to learn more about the app development.

Video of Beinstein and Gluck presenting their app to Hack Night. Created by Christopher Whitaker for Smart Chicago Collaborative.

Why did you make Chicago Bike Route?

We made the app because we wanted to make something civic related. We thought that Divvy was an exciting new civic program coming into existence, and we kept seeing it all over the place. It also solves a real problem in public transportation that we notice and hear about a lot living in Hyde Park called the “last mile problem.” We also had the data in our hands from having attended civic hack night at 1871 when Divvy came and we thought “let’s make a native Divvy app!” And that’s what we did. We also released a framework for interacting with the Divvy API natively for developers who don’t want to get their hands dirty playing around with the iOS frameworks.

What makes your app stand out from the pack?

I think the routing but also the simplicity of design of the app.  We wanted it to be something you could just open up and use and was like all the other mapping utilities that one has on their phone (Google Maps, Apple Maps). And that’s what we did. You open it, enter an address, and you get routed to that address. Something that people could use to get up and running with Divvy with basically no familiarity with the system.

What features are you planning for the future?

Bike surfing! Seriously though. We think that it would be a really useful feature for some people, and also help reduce the cost of using the bikes. It would be useful for the regular riders where the $2 additional charge could really add up but also if you are someone who is not part of the program and are just taking the bike out for a joy ride. It can actually get kind of expensive, since every half hour after the first hour in a half is an additional $8, rather than $4.50 for members. You would also be less familiar with the bike stations under that situation. We also need to integrate with Chicago public transportation. But, we also want to keep with the simplicity, and create a user experience with basically no learning curve, and we are a little cautious to throw something in that could complicate things.