Thursday 13 November 2014

The Urban Fabric of Los Angeles

I've recently become a bit obsessed with looking at the urban fabric of different cities. I've looked at building footprints in English Cities, Scottish Cities, and collected data on a number of US cities, including San Francisco, New York, Chicago and Los Angeles. I've blogged and tweeted about this quite a bit over the past few months and the reason I'm so fascinated by it is that it provides some really interesting visual insights into the spatial structure of cities. I also find it fascinating to make visual comparisons between cities, as in my 'Urban Fabric of English Cities' blog post from October 2014. Now I'm going to look at Los Angeles. I've only been there once but I found it fascinating in so many ways (urban structure; fragmented political, social, racial geography; freeways; congestion; In-N-Out Burger...). Famously, Los Angeles is also the most populous of the 3,144 counties of the United States with a population of just over 10 million. The first image below shows all 3,000,000 or so buildings in LA county - all 4,000 square miles of it (for comparison, London is 607 square miles).

Los Angeles County - population 10 million (higher res)

Anyone who knows anything about American cities will understand that the concept of a 'city' and a 'boundary' is not necessarily as straightforward as it might appear - well, at least not to me as a British person. The City of Los Angeles is a rather odd shape and has a population of about 3.8 million. The image below shows the urban fabric (building footprints) for the City of Los Angeles.

The City of Los Angeles - population 3.8 million (full resolution)

Finally, I've produced a map showing the wider Los Angeles metro area (within Los Angeles County), with the urban footprint of the City of Los Angeles highlighted. The wider metro area extends beyond the boundary of Los Angeles County and has about 13 million people. What's the point of all this? Partly a mapping experiment and partly to illustrate the idiosyncrasies of political and administrative boundaries in urban areas compared to the underlying urban fabric. This is very acutely demonstrated in the case of Los Angeles.

The City of Los Angeles in context (higher res)

If you like these images and want them in higher resolution versions just get in touch via twitter - @undertheraedar or e-mail. I've linked to a high res version for the LA city map.

Data source: Los Angeles County - Countywide Building Outlines

Friday 7 November 2014

Automatic map production with QGIS

This longer post explains how to automate map production in QGIS using the atlas generation tool. It's based on QGIS 2.4 but will work in later versions and some earlier versions too. I've found this tool immensely useful and a great time saver so I'm sharing the method here. Similar outcomes are possible in ArcMap's Data Driven Pages but I find that the rendering quality of QGIS is better, so I use this approach. Before going any further, here are some example outputs from the atlas tool - it shows some recent mayoral election results from Toronto, which I saw on twitter via Patrick Cain. You can download the PDF mapbook and the individual images files below.

Download the complete map book of results (150MB PDF)

Download individual image files for the whole city (58MB)

I'll explain how you can produce multiple maps and also how I achieved some of the effects in the image above. This tutorial tells you how to produce one map per page. For multiple maps per page (as above) I'll say more at the end. There are two data layers in my map - one layer for the 44 wards of Toronto and one for the election results. The election results were posted on CartoDB by Zack Taylor from the University of Toronto Scarborough with his interactive map so that's the data I'm using here. I've used this dataset because a) it's very interesting and b) I wanted to compare a small number of variables across single areas of a city and produce a map book from it.

I added my layers to QGIS and then I styled them as I wanted. Basically, this involved copying the ward boundary layer and making the top one just a hollow black outline style by changing the symbology to 'No Brush' and a black outline of about 0.5 width. Here's what I did to create the glow effect round each ward... On the copy of the ward layer I symbolised it using the 'Inverted Polygon' and then in the Sub-renderer options in the same window I selected 'Rule-based' (screenshot below).




I then clicked to edit the rule so that my map looked as I want it to when I move to the atlas production phase in the Print Composer later on. You just need to select the colour patch and then click on Edit Rule (the little pencil and paper icon, as shown below). I wanted to make sure there was a glow effect around each individual ward when the atlas was zoomed to that feature so using tips from Nyall Dawson on shapeburst fill styles in QGIS 2.4, Hugo Mercier on inverted polygons and Nathan Woodrow on highlighting current atlas features I managed to achieve this - note the text in the Filter box in the second image below. You'll see that in the second screenshot I've symbolised the layer using a black to white shapeburst (this creates the black glow effect outside the active polygon, since we're using inverted polygon symbology). 

The final thing I did was to go back to the Fill colour patch on the second image below and change the transparency to 33%. This means that you'll be able to see surrounding areas but with a 'lights off' effect. You might find that when you do this your layer completely disappears but don't worry; it will come back on when you move to the Print Composer.




I then symbolised my Toronto 2014 mayoral election results layer using a graduated colour scheme using 'Pretty Breaks' so that it had breaks at 10%, 20%, 30% and so on. I then made sure I saved my project (!) and moved to the print composer (CTRL+P) and added a map to my page. 

This is where it gets a little confusing if you're new to it. Once the map is added, go to the Atlas generation tab on the right and click the 'Generate an atlas' box. You then need to set a 'Coverage layer'. This serves as the positioning device for each atlas page, so that when you produce an atlas QGIS will zoom to the extent of each feature to create a map for that area. So, in this example, I specified the coverage layer as the Ward boundary layer (the top one) because I wanted a map for each ward. Still on the Atlas generation tab, go down to Output and you can set to sort the atlas pages by features from your coverage layer. In my case I ticked the 'Sort by' box and used the NAME field so that my atlas would be organised alphabetically by neighbourhood name. Nothing will happen yet. I then went back to the Item properties tab and scrolled down until I could see 'Controlled by atlas' and then clicked that box. 

There are a number of options here but I chose a 'Margin around feature' of 25%. This means each map will zoom to your area and leave a nice margin around the ward - useful if you want to leave space for other map elements such as a legend. To finally make something happen, go to the Atlas menu and then select 'Preview Atlas' - the map will then zoom to your first feature - as you can see in the example below. If you then click on the blue Atlas preview arrows you can preview successive pages and the map will zoom to each feature in turn. You can also see that the inverted polygon glow is now active only for each active atlas feature (that's what the $id = $atlasfeatureid filter does).



I then added in a text item which would serve as a title but I wanted this to automatically change as I moved through the atlas so once I added a text item I then deleted the default text and clicked on 'Insert an expression' below the text box and used the Function list to insert the 'NAME' field in the Expression box (as below). What this means is that as you go through each successive page on the Atlas, QGIS will enter the name of the ward currently in view in the atlas. A good tip here is that you should size your text box and font appropriately so that the longest name in your dataset still fits within the box. You can spot mistakes in the Atlas preview but if you're generating hundreds of pages this is not always practical. 



If you close your project and open it up again, remember that you'll have to go to Atlas, Preview Atlas again. Now you just need to take some time to add any other map items you want, such as a legend, north arrow, and so on. Scale bars are a bit problematic but I don't normally use them for this kind of map. At this stage you'll want to check the Composition tab to check on the export resolution. Obviously, the higher it is, the longer it will take to export.

Finally, go back to the Atlas generation tab and look down to the Output options. By default, QGIS will call your individual map exports 'output_1', 'output_2' and so on but you can click the little expression button here and choose to name your individual files using a field from your Coverage layer. I did this when I exported my maps by using the NAME field and each file now has the name of a Toronto neighbourhood: immensely useful when you're generating hundreds of maps.

If you click the 'Single file export when possible' it means that (e.g.) you'll get one big PDF rather than individual ones for each area in your Coverage layer. I chose this option in the example at the start with 4 maps per page, but it creates large file sizes.

That's pretty much it. I have not explained everything here in relation to the basics because I'm really aiming this at people with experience of QGIS but feel free to get in touch if you need any tips. This kind of thing can also be done programatically in R, but since I don't have the coding skills of Alex Singleton et al. I'm using QGIS. 

Finally, here's the zipped folder (58MB) containing 44 neighbourhood maps of the Toronto 2014 Mayoral Elections - with 4 maps on each page relating to % voting Ford, Tory, Chow and Other candidates. Feel free to use these as you wish. I didn't do this as a Toronto mapping project but the results do look quite nice in my opinion.

People in this ward seem to like John Tory


Want multiple maps on each atlas page, each of which show a different variable?
To achieve the effect I have in the images at the top of this post, all I did was create a smaller map item in Print Composer using the symbology I wanted for the electoral results layer (e.g. % voting Ford) and then adding a legend for that frame and then locking the layers for that map item (see below). I would then create a duplicate of the electoral results layer, add a new map frame to Print Composer and repeat the process. Just re-symbolising the same layer will not work. Once I am happy with how a map looks, I simply lock the layers on Item properties so that it doesn't change. I wanted to show a little inset map to show the general location of the ward within the city of Toronto and I did this in a very similar way. The main different here is that in the 'Controlled by atlas' options I used a fixed scale.




Notes: apologies if I've made any of this too complicated or if I've missed anything. Do get in touch if you notice any errors. I'm sorry if the map projection is not the one Toronto natives would use or if I've made any other foreigner gaffes. The point of this was really to demonstrate the technique using an interesting recent dataset so hopefully I've achieved that.


Tuesday 4 November 2014

Manchester: a "Northern Powerhouse"

The announcement yesterday from the Chancellor that we need a "Northern Powerhouse" in England was greeted with much enthusiasm - and also a good bit of cynicism, given that it's not far from the General Election. After the announcement, the BBC asked whether more English cities should be like Manchester. What I wanted to know was how this nascent northern powerhouse compared to the already established southern one (London, I think). We all know the numbers - well most do - but what about spatial scale, density and visual comparisons? Given a previous bit of mapping on the urban fabric of England and the fact that I've been thinking about the 'underbounded' nature of the City of Manchester (as opposed to the city region), I thought I'd go a bit further with this post.

The first image here shows how Greater London compares to Greater Manchester - they're mapped at the same scale - and I've also put the Greater Manchester boundary over Greater Manchester and vice versa, just to show that they're not that radically different in size.

Greater Manchester - a large urban area (higher res version)

I've also produced the same image without the respective boundaries overlaid on each city, just to provide a quick visual comparison at the same scale.

Click for higher resolution image

Finally, in order to demonstrate the way in which the City of Manchester is really 'underbounded' in relation to its wider city region, I've shown just the urban fabric of the City of Manchester (i.e. building footprints) in relation to the ten local authority areas of Greater Manchester, beside Greater Manchester as a whole. 

Click for bigger version

I have some even higher resolution images if anyone is interested - if so, feel free to get in touch via e-mail or twitter (@undertheraedar). I just wanted to produce these images to illustrate the fact that Greater Manchester is actually very big (about 80% of the size of Greater London in area) though of course has far fewer people (about 33% of the population). It does seem like the most likely 'northern powerhouse' in England and it will be very interesting to see how things pan out over the coming years.