Urban Form Figure-Ground Diagrams

I previously demonstrated how to create figure-ground square-mile visualizations of urban street networks with OSMnx to consistently compare city patterns, design paradigms, and connectivity. OSMnx downloads, analyzes, and visualizes street networks from OpenStreetMap but it can also get building footprints. If we mash-up these building footprints with the street networks, we get a fascinating comparative window into urban form:

Figure-ground map of building footprints and street network in New York, San Francisco, Monrovia, and Port au Prince from OpenStreetMap data, created in Python with OSMnx

Continue reading Urban Form Figure-Ground Diagrams

Square-Mile Street Network Visualization

The heart of Allan Jacobs’ classic book on street-level urban form and design, Great Streets, features dozens of hand-drawn figure-ground diagrams in the style of Nolli maps. Each depicts one square mile of a city’s street network. Drawing these cities at the same scale provides a revealing spatial objectivity in visually comparing their street networks and urban forms.

We can recreate these visualizations automatically with Python and the OSMnx package, which I developed as part of my dissertation. With OSMnx we can download a street network from OpenStreetMap for anywhere in the world in just one line of code. Here are the square-mile diagrams of Portland, San Francisco, Irvine, and Rome created and plotted automatically by OSMnx:

OSMnx: Figure-ground diagrams of one square mile of Portland, San Francisco, Irvine, and Rome shows the street network, urban form, and urban design in these cities

Continue reading Square-Mile Street Network Visualization

OSMnx: Python for Street Networks

OSMnx: New York City urban street network visualized and analyzed with Python and OpenStreetMap dataOSMnx is a Python package for downloading administrative boundary shapes and street networks from OpenStreetMap. It allows you to easily construct, project, visualize, and analyze complex street networks in Python with NetworkX. You can get a city’s or neighborhood’s walking, driving, or biking network with a single line of Python code. Then you can simply visualize cul-de-sacs or one-way streets, plot shortest-path routes, or calculate stats like intersection density, average node connectivity, or betweenness centrality. You can download/cite the paper here.

In a single line of code, OSMnx lets you download, construct, and visualize the street network for, say, Modena Italy:

import osmnx as ox
ox.plot_graph(ox.graph_from_place('Modena, Italy'))

OSMnx: Modena Italy networkx street network in Python from OpenStreetMap Continue reading OSMnx: Python for Street Networks

R-tree Spatial Indexing with Python

r-tree spatial index with python geopandas: Thumbnail of Walnut Creek, California city boundary and street intersections inside and outside city limitsA spatial index such as R-tree can drastically speed up GIS operations like intersections and joins. Spatial indices are key features of spatial databases like PostGIS, but they’re also available for DIY coding in Python. I’ll introduce how R-trees work and how to use them in Python and its geopandas library. All of my code is in this notebook in this urban data science GitHub repo.

Continue reading R-tree Spatial Indexing with Python

Visualize Foursquare Location History

I started using Foursquare at the end of 2012 and kept with it even after it became the pointless muck that is Swarm. Since I’ve now got 4 years of location history (ie, check-ins) data, I decided to visualize and map it with Python, matplotlib, and basemap. The code is available in this GitHub repo. It’s easy to re-purpose to visualize your own check-in history: you just need to plug in your Foursquare OAuth token then run the notebook.

First the notebook downloads all my check-ins from the Foursquare API. Then I mapped all of them, using matplotlib basemap.

Map of Foursquare Swarm check-in location history Continue reading Visualize Foursquare Location History

Scientific Python for Raspberry Pi

Raspberry Pi 3 Model BA guide to setting up the Python scientific stack, well-suited for geospatial analysis, on a Raspberry Pi 3. The whole process takes just a few minutes.

The Raspberry Pi 3 was announced two weeks ago and presents a substantial step up in computational power over its predecessors. It can serve as a functional Wi-Fi connected Linux desktop computer, albeit underpowered. However it’s perfectly capable of running the Python scientific computing stack including Jupyter, pandas, matplotlib, scipy, scikit-learn, and OSMnx.

Despite (or because of?) its low power, it’s ideal for low-overhead and repetitive tasks that researchers and engineers often face, including geocoding, web scraping, scheduled API calls, or recurring statistical or spatial analyses (with small-ish data sets). It’s also a great way to set up a simple server or experiment with Linux. This guide is aimed at newcomers to the world of Raspberry Pi and Linux, but who have an interest in setting up a Python environment on these $35 credit card sized computers. We’ll run through everything you need to do to get started (if your Pi is already up and running, skip steps 1 and 2). Continue reading Scientific Python for Raspberry Pi

Urban Informatics and Visualization at UC Berkeley

The fall semester begins next week at UC Berkeley. For the third year in a row, Paul Waddell and I will be teaching CP255: Urban Informatics and Visualization.

This masters-level course trains students to analyze urban data, develop indicators, conduct spatial analyses, create data visualizations, and build Paris open datainteractive web maps. To do this, we use the Python programming language, open source analysis and visualization tools, and public data.

This course is designed to provide future city planners with a toolkit of technical skills for quantitative problem solving. We don’t require any prior programming experience – we teach this from the ground up – but we do expect prior knowledge of basic statistics and GIS.

Our teaching materials, including IPython Notebooks, tutorials, and guides are available in this GitHub repo, updated as the semester progresses.

Continue reading Urban Informatics and Visualization at UC Berkeley

Using geopandas on Windows

projected-shapefile-gps-coordinatesThis guide was updated in June 2016 to reflect changes to the dependencies and the ability to install with Python wheels.

I recently went through the exercise of installing geopandas on Windows and getting it to run. Having learned several valuable lessons, I thought I’d share them with the world in case anyone else is trying to get this toolkit working in a Windows environment (also see this GitHub gist I put together).

It seems that pip installing geopandas works fine on Linux and Mac. However, several of its dependencies have C extensions that cause compilation failures with pip on Windows. This guide gets around that issue. For preliminaries, I have this working on Windows 7, 8, and 10. My Python environments are Anaconda, 64-bit, with both Python 2.7 and 3.5. I’m running geopandas version 0.2 with GDAL 2.0.2, Fiona 1.7.0, pyproj, and shapely 1.5.16.

Continue reading Using geopandas on Windows

Visualizing Summer Travels Part 5: Python + Matplotlib

This post is part of a series on visualizing data from my summer travels.

I’ve previously discussed visualizing the GPS location data from my summer travels with CartoDB, Leaflet, and Mapbox + Tilemill. Today I will explore visualizing this data set in Python, using the matplotlib plotting library. All of my code is available in this GitHub repo, particularly this notebook.

Continue reading Visualizing Summer Travels Part 5: Python + Matplotlib

Reducing Spatial Data Set Size with Douglas-Peucker

In a previous post I discussed how to reduce the size of a spatial data set by clustering. Too many data points in a visualization can overwhelm the user and bog down on-the-fly client-side map rendering (for example, with a javascript tool like Leaflet). So, I used the DBSCAN clustering algorithm to reduce my data set from 1,759 rows to 158 spatially-representative points. This series of posts discusses this data set in depth.

Continue reading Reducing Spatial Data Set Size with Douglas-Peucker