Kevin McMahonChicago based mobile app developer.


Yesterday I had the pleasure of doing a talk exploring Core Location at the 4th annual Chicago Code Camp. Really enjoyed the audience participation and hopefully everyone left with a better understanding of Core Location.

Code on Github

A collection of some of my favorite links, tweets and quotes from February. While these aren't a comprehensive look at or summary of February 2012, they do capture the things that I found interesting, thought provoking, and/or cool over the past month.

Favorite Links

Favorite Quotes

  • “Chaos was the law of nature, order was the dream of man.” – Henry Adams
  • "All men will benefit, if we can invoke the wonders of science instead of its terrors." – JFK

A collection of some of my favorite links, tweets and quotes from January. While these aren't a comprehensive look at or summary of January 2012, they do capture the things that I found interesting, thought provoking, and/or cool over the past month.

Favorite Links

Favorite Tweets

  • @dansinker:"The first rule of John Kerry fight club…" contains at least 75 subclauses."
  • @citizenparker: MUTABILITY! From hell’s heart I stab at thee (until another operation inadvertently changes my state to “not stabbing”)

Quotes

Sometimes location data isn't neatly packaged in a SHP file, and it requires some massaging before it can be used in spatial queries. In this post I'll take a look at importing latitude and longitude data from a CSV file into our PostGIS database and transforming those coordinates into geometry data that can be spatially queried against.

Step 0 - Initial Starting Point

  • Get a CSV dataset. For this example I'll be using the Individual Landmarks dataset exported as CSV. You can get a copy of the CSV file that I am using for the example here. We already have the latitude and longitude and the extra location field isn't something that we'll use so I removed the location column prior to exporting the dataset. You can hide the column by selecting the arrows on the column heading in the table (shown here) or via the manage screen and deselecting the location column from the list of available columns (shown here).

  • A PostgreSQL database with PostGIS installed.

Step 1 - Create the table in the database

Use the following SQL to create a table to hold the landmark data.

Step 2 - Copy the CSV data into the database

To run the copy command, login to the database and execute the following command :

There are a couple of things to note with the copy command:

  1. The first argument passed to the copy command specifies the tablename (landmarks) and the columns which the CSV files map to. Our table includes a column gid that is an auto-incremented id which is used as a primary key as well as the_geom geometry column. The CSV does not include either of these columns in the data we are copying. If we don't specify the specific columns that the fields in the CSV map to, errors will occur when attempting to copy the data.
  2. The DELIMITERS argument specifies your delimiter.
  3. The CSV argument at the end lets PostgreSQL know that the file is CSV.
  4. The HEADER argument lets PostgreSQL know that the file includes the headers on the first line.

Here is a look at our data after the import. Note that the_geom has no data. We'll take care of that in the next step.

A look at the newly imported landmark data sans geometry.

Step 3 - Translate latitude and longitude into POINT geometry

Now that we have the data imported, we need to convert the latitude and longitude columns to a PostGIS POINT geometry. The following SQL will update the_geom column in the landmarks table with a POINT geometry created from the row's latitude and longitude columns. In order to create the POINT, the ST_GeomFromText method is used. This method allows us to create a POINT, which is a PostGIS geometry type, textually with the latitude and longitude values being specified in the construction of the type.

Here is a look at the data with the the_geom column populated with POINT data.

Geometry populated landmarks table

Step 4 - Run some queries

Now that all the POINT geometries have been created for our landmark rows we can write some spatial queries against our data. Here are just a few of the types of queries we can run.

Using the ward geometry we have from a previous example, we can run a query that returns all the landmarks in the 43rd Ward.

This query returns the 5 closest landmarks to a given latitude and longitude :

A quest to find the name and url of a gadget review site that I had tweeted about a few months ago led me to the TwimeMachine web app. TwimeMachine lets you read your old tweets and, while I was looking for the gadget website, I got a chance to take a stroll down memory lane and revisit some of my favorite links and quotes from the past year. I pulled out some of my favorites and have shared them below. While these lists aren't a comprehensive look at or summary of 2011, they do capture the things that I found interesting, thought provoking, and/or cool over the past year.

My Favorite Links from 2011

My Favorite Quotes from 2011

  • "I’m impressed with the people from Chicago. Hollywood is hype. New York is talk. Chicago is work." -Michael Douglas

  • "The arts are not a way to make a living. They are a very human way of making life more bearable." -- Kurt Vonnegut

  • "Another flaw in the human character is that everybody wants to build and nobody wants to do maintenance." -- Kurt Vonnegut

  • @zachklein: Just told to me: "Schools are the coal-fired power plants of education."

My Favorite Funny Tweets from 2011

  • @jonlech "Next year HTML5 will replace native apps" is the new "Next year will be the year of Linux on the desktop".

  • @hubs: What doesn't kill you makes you smaller. ~Super Mario

  • @dcurtis: The Container Store is like a strip club for people with OCD.

  • @larrybraverman: GUYS IF EGYPT CAN TAKE DOWN MUBARAK WE CAN TAKE DOWN TICKETMASTER