The good folks at Sanborn were kind enough to send us a sample extract of processed 3D building data from their 3D Cities archive, so I set out to see what we could do with it using TileMill and the building symbolizer in Mapnik.

Mapping 3D buildings

Out of the box, the Sanborn 3D data is ready to map. To make it fast in TileMill, I reprojected the data to Spherical Mercator and added a Mapnik shape index. Then seeing the buildings pop up was just a matter of adding the shapefile as a layer in TileMill and setting the building-height: 100; style. The Sanborn data contains a bld_h_m value for each polygon, which is the shape’s building height in meters. To accurately extrude shapes according to this value, we need to do a slight patch to TileMill so we can set building-height: "[bld_h_m]";, which uses the data value instead of a fixed number.

Finally, to get the polygons to render in the right order, I imported the data into PostGIS and sorted it with ORDER BY ST_YMax(ST_Envelope(the_geom)) DESC.

Other (ab)uses for 3d in TileMill

In the past, we’ve hacked around with using the building symbolizer to show data, particularly like major earthquakes:

Japan earthquake in 2011

If you’re looking to add some basic depth to your map features, you can get creative with the building symbolizer. It supports three basic styles for the color and height of extruded shapes. There’s a lot you can do with these styles, particularly by stacking lots of semi-transparent features.

Here, I’ve made a 3D population density map by taken randomly distributed points within census tract polygons and summarized them on a diamond grid. Looking close up, you can see this is just a grid with lots of extruded shapes.

Close up of the 3D population grid

TileMill’s not intended to be a substitute for a full 3D rendering application, but it’s quite powerful for building data and some quirky visualizations. Check it out and let us know (@mapbox) what you make.