Here at PyData NYC, I heard a tutorial of how to use numpy and iPython notebooks. In a previous gist, I wrote drew all the zip codes of the Bronx in d3.js
This would be great for reproducing inforgraphics like Educational Attainment in New York City -- Brooklyn which looks a bit like a jigsaw puzzle:
Unzipping the 2010 NYC Census Tracts gave me 5 files:
nyct2010.dbf
nyct2010.prj
nyct2010.shp
nyct2010.shp.xml
nyct2010.shx
Looking up Shapefile (Español) I learned how *.shp
, *.shx
& *.dbf
extensions work.
Eventually, I found ogr2ogr
to switch between shape-files and geoJSON. You can just dump the zip
file online.
Using topoJSON
by Michael Bostock, we indeed get a 90% reduction from 8MB
to 800KB
and a partition of the map of Census Tracts into disjoint arcs. From gis.StackExchange:
The primary advantage of TopoJSON is size. By eliminating redundancy and using a more efficent fixed-precision integer
encoding of coordinates, TopoJSON files are often an order of magnitude smaller than GeoJSON files. The secondary advantage
of TopoJSON files is that encoding the topology has useful applications, such as topology-preserving simplification (similar
to MapShaper) and automatic mesh generation (as in the state-state boundaries in this example choropleth).
For the purposes of matplotlib
, we can just draw the 6195 arcs. Here is an example of an arc
in the TopoJSON sense:
>>> x['objects']['nyc']['geometries'][0]
{'type': 'Polygon', 'arcs': [[0, 1, 2, 3, 4]]}
The topojson file has valuable information about the scaling of our polygon
>>> x['transform']
{'translate': [913175.1090087891, 120121.8812543377], 'scale': [15.422282169623212, 15.273768652066204]}
The arcs and be posive or negatively oriented. Let's examine arc #1. Still somewhat mysterious
>>> x['arcs'][1]
[[3190, 3474], [-5, -1], [-10, -2], [-16, -4], [-17, -4], [3, -19], [4, -19], [-14, -3], [-1, 3], [-2, 9], [-4, 7], [-50, -10], [-39, -7]]
There are a few good libraries that I am excited about. Leaflet or CartoDB are useful for mapping all of the world. We would like to focus on New York States. My goal is something easy to use, that produces good results. I have a few examples I am following.
- AtlasPR
- A map of Puerto Rico using JavaScript d3.js
- 3 scales: municipality, barrio and island
- State.ly
- a CSS Font whose glyphs are US States
- easy Chropleth maps
It makes me really happy to say NYC OpenData website has improved substantially since last time I checked!