3D Printing Manhattan

It’s my very first “thing”.  I’m fairly new to 3D printing, and have had my build-it-yourself printrbot for a couple of months… I’ve only been downloading and printing models published by others on Thingiverse, but this weekend I successfully turned geospatial data into a simple 3D model.  I’ll recount the process to you here.

The New York City Department of City Planning has tons of very useful geospatial datasets published on their website under the brand “Bytes of the Big Apple”.  You can download a shapefile that has the boundaries of all 5 boroughs and open it in QGIS.

QGIS_2.4.0-Chugiak_and_Add_New_Post_‹_Chris_Whong_—_WordPress_and_Repetier-Host_Mac_0.56

For a simple first project, I wanted to print Manhattan.  But just extruding the whole polygon of Manhattan would not be very exciting, so poking a central-park-sized hole out of the middle of it seemed like a good idea.

First, I isolated Manhattan from the citywide shapefile in QGIS by selecting the polygon and “saving as”.  (I had to manually remove all of the little islands that are included in Manhattan)  I used NYC’s PLUTO dataset to isolate Central Park’s Polygon, which I then layered on top of Manhattan’s polygon to use as a guide.  To “poke a hole” in the Manhattan Polygon, you can use QGIS’ Add Ring tool, which lets you trace out a region to be removed from the original polygon.  I simply traced the Central Park polygon to add a Central-Park sized hole in the Manhattan Polygon.

QGIS_2.4.0-Chugiak_and_Add_New_Post_‹_Chris_Whong_—_WordPress_and_Repetier-Host_Mac_0.56 2

So the central park hole is poked, but the polygon still has all of the hudson river piers and other “bumps” in the perimeter that won’t lend themselves well to 3D printing.  Next, I needed to simplify the polygon, so I used a really sweet online tool called Mapshaper.  (This simplification can be done in QGIS, but mapshaper is just a lot of fun and lets you drag a slider and see the changes in real-time)

Mapshaper lets you drag a slider to simplify the polygon, and you can see the Hudson River piers disappear before your eyes. What started out as this:

mapshaper 2

 

ends up like this:

mapshaper

I had attempted without much luck to use a QGIS plugin called qgis2threejs to convert a shapefile into an STL (3D model), but it didn’t seem to like inner rings (holes inside polygons).   To my surprise I found a node library that converted Shapefiles to STLs (appropriately named shp2stl!) and it worked like a charm.  Big thanks to Doug McCune for this awesome node package!

The readme has a nice little demo script that uses the library that you can just copy, swap out the filenames, and edit the parameters you want.  I downloaded my mapshaper-simplified Manhattan shapefile as simple.shp.  I tell the script to extrudeBy the FID field of the shapefile (FID has a value of 1 for my lone polygon, but if we had multiple polygons, we could extrude by some element of the data to get a 3D map).  The height will be 5 (this will end up being 5mm to the 3D printer), and since there is only 1 polygon, the whole thing will be extruded to the same height.

var fs = require('fs');
var shp2stl = require('shp2stl');

var file = 'simple.shp';

shp2stl.shp2stl(file, 
    {
        width: 100, //in STL arbitrary units, but typically 3D printers use mm
        height: 5,
        extraBaseHeight: 0,
        extrudeBy: "FID",
        simplification: 0,

        binary: true,
        cutoutHoles: false,
        verbose: true,
        extrusionMode: 'straight'
    },
    function(err, stl) {
        fs.writeFileSync('hole.stl',  stl);
    }
);

The node script spits out an STL file that’s ready for 3D Printing!  This file can be opened in Repetier Host, which can convert it into code for the printer, and send it on its way!

Repetier-Host_Mac_0.56_and_shape.js

Here’s the result:

10698642_10152592304105660_1040446194543930730_n 10606585_10152592304160660_992331449691663476_n

My first thing now resides on Thingiverse if you want to download and print it yourself.

What I really want to be able to do is extrude buildings to their relative heights so I can 3D print little slices of neighborhoods.  I was messing around with this recently, but haven’t found an easy solution just yet.

Thanks for reading!

Leave a Reply

Your email address will not be published. Required fields are marked *