Skip to content

Commit

Permalink
updated tutorial to use GeoJSON rather than KML + Google Maps
Browse files Browse the repository at this point in the history
  • Loading branch information
econchick committed Feb 1, 2014
1 parent 1363688 commit 865a091
Show file tree
Hide file tree
Showing 11 changed files with 327 additions and 502 deletions.
2 changes: 1 addition & 1 deletion website/_posts/DataViz/2013-01-01-Landing.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ url: "/dataviz/"
[Part 0: Setup]({{ get_url("/dataviz/part-0/")}}) – Initial setup for our Data Visualization tutorial.
[Part 1: Parse]({{ get_url("/dataviz/part-1/")}}) – Parse our sample SF crime data.
[Part 2: Graph]({{ get_url("/dataviz/part-2/")}}) – Graph our sample data with matplotlib.
[Part 3: Map]({{ get_url("/dataviz/part-3/")}}) – Plot our sample data on Google Maps.
[Part 3: Map]({{ get_url("/dataviz/part-3/")}}) – Plot our sample data on a map with GeoJSON.
[Extended]({{ get_url("/dataviz/extended/")}}) – How Data Visualization is used in real life, and where to go after finishing the tutorial.
346 changes: 142 additions & 204 deletions website/_posts/DataViz/2013-01-02-Part-3-Map.md

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions website/_posts/DataViz/2013-01-05-Part-0-Setup-for-DataViz.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ $ mkvirtualenv DataVizProj
```bash
(DataVizProj)$ pip install numpy
(DataVizProj)$ pip install matplotlib
(DataVizProj)$ pip install geojson
```

* **NOTE** Sometimes, matplotlib is finicky as well. If you are on a Mac and "pip install matplotlib" did not work, you are probably missing the supporting packages freetype2 and libpng. Windows users do not need to worry about his as these packages are already included in the standard matplotlib Windows installers. For Mac users, below are detailed instructions on how to install them.
Expand Down Expand Up @@ -90,6 +91,7 @@ After installing these three packages, type "pip install matplotlib" again and i
(DataVizProj)$ python
>>> import numpy
>>> import matplotlib
>>> import geojson
```
* If you have no errors (you would just see the `>>>` prompt), then you’re good to go. You can close out of the Python interpreter by pressing `CTRL+D`. If you do have errors, I’d try downloading [numpy](http://scipy.org/Download) and [matplotlib](http://matplotlib.org/downloads.html) manually.

Expand Down
18 changes: 6 additions & 12 deletions website/_posts/DataViz/2013-01-06-Intro-DataViz.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ This tutorial is meant to push you out of the Excel mindset just a little bit, a

### The Project

The project we will create takes the sample data from the repository that you will download (a.k.a. clone) in [Part 0: Setup]( {{ get_url("Part-0-Setup-for-DataViz")}}), parse the sample data from columns and rows to a list of dictionaries, then render that data in two different graphs and in [Google Maps](http://maps.google.com).
The project we will create takes the sample data from the repository that you will download (a.k.a. clone) in [Part 0: Setup]( {{ get_url("Part-0-Setup-for-DataViz")}}), parse the sample data from columns and rows to a list of dictionaries, then render that data in two different graphs and in [GitHub](http://gist.github.com) as a map.

The sample data that is included is a snapshot of public crime filings from the San Francisco police. Once you’ve gone through this tutorial, feel free to find other data that interests you, and rework our visualization functions.

Expand All @@ -23,7 +23,7 @@ Understand how to:
* import a Python file
* take a raw file and parse its data with Python’s data structures
* make a simple graph
* produce a Google Maps-readable file
* produce a GeoJSON file for mapping

What else you will be exposed to:

Expand All @@ -44,18 +44,12 @@ We won't be using much of NumPy, but it is required that we install this library

[matplotlib](http://matplotlib.org/) is another popular scientific library that gives the developer tools to produce 2D figures. No longer do you need your [TI-89](http://www.amazon.com/Texas-Instruments-Titanium-Calculator-Packaging/dp/B0001EMLZ2) calculator where you must punch in long lines of formulas, waiting precious seconds for it to render a graph that may be too zoomed in to realize you are missing an important axis point. Packed with detailed [examples](http://matplotlib.org/examples/index.html), you are able to make publication/presentation-quality graphs from the comfort of your keyboard.

### Intro to Google Mapping
### Intro to GeoJSON

It’d be kind of cool to place all the coordinates in our data on a map, wouldn’t it? Google Maps allows folks to upload KML-type documents, which is essentially a type of an XML document for displaying geographic-related data.
[GeoJSON](http://en.wikipedia.org/wiki/GeoJSON) is a derivative of [JSON](http://en.wikipedia.org/wiki/JSON), and very similar to [TopoJSON](http://en.wikipedia.org/wiki/Topojson). It’s a data format for simple geological feature, including coordinate points.

Google has a great KML [intro](https://developers.google.com/kml/documentation/) and [tutorial](https://developers.google.com/kml/documentation/kml_tut) for those interested.
We’ll be using a third-party module to help us in creating GeoJSON files: [`geojson`](https://pypi.python.org/pypi/geojson/1.0).

Wikipedia has a pretty readable [explanation](http://en.wikipedia.org/wiki/XML) of XML, and w3 has a simple [tutorial](http://www.w3schools.com/xml/) if you want to learn more (_side comment_: w3 is not the greatest for learning front-end related web development, but fine for quick references).

Both KML and XML, as well as HTML and XHTML, follow the [DOM](http://en.wikipedia.org/wiki/Document_Object_Model) convention, Document Object Model. It’s basically how you interact with different objects through defined functions.

As you are starting to realize the awesomeness of Python, you can assume there is an `xml` module in the standard library. How convenient! Python’s `xml.dom` module uses the DOM convention and gives us access to functions that HTML, XML, and KML will understand when we build our own KML document.

For the record, do not use Python’s `xml` library in production code until the core developers have implemented security fixes. For information, you can read [here](http://blog.python.org/2013/02/announcing-defusedxml-fixes-for-xml.html).
[GitHub](https://github.com) has an awesome feature that allows folks to paste GeoJSON files into [Gists](https://gist.github.com), and it automatically renders as a map.

[Continue on to the Setup for DataViz →]( {{ get_url("dataviz/part-0")}})
4 changes: 2 additions & 2 deletions website/_site/archives/2013/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,10 @@ <h2><a href="/archives/">Archives</a> &rsaquo; 2013</h2>
<dd><a href="/dataviz/part-3/">Part 3: Map</a><small>Tagged <span>&raquo;</span> <a href="/tags/DataViz/">DataViz</a></small></dd>

<dt>Jan 01</dt>
<dd><a href="/dataviz/extended/">Extended</a><small>Tagged <span>&raquo;</span> <a href="/tags/DataViz/">DataViz</a></small></dd>
<dd><a href="/dataviz/">Data Visualization</a><small>Tagged <span>&raquo;</span> <a href="/tags/dataviz/">dataviz</a></small></dd>

<dt>Jan 01</dt>
<dd><a href="/dataviz/">Data Visualization</a><small>Tagged <span>&raquo;</span> <a href="/tags/dataviz/">dataviz</a></small></dd>
<dd><a href="/dataviz/extended/">Extended</a><small>Tagged <span>&raquo;</span> <a href="/tags/DataViz/">DataViz</a></small></dd>


</dl>
Expand Down
4 changes: 2 additions & 2 deletions website/_site/archives/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -243,10 +243,10 @@ <h2>Archives</h2>
<dd><a href="/dataviz/part-3/">Part 3: Map</a><small>Tagged <span>&raquo;</span> <a href="/tags/DataViz/">DataViz</a></small></dd>

<dt>Jan 01</dt>
<dd><a href="/dataviz/extended/">Extended</a><small>Tagged <span>&raquo;</span> <a href="/tags/DataViz/">DataViz</a></small></dd>
<dd><a href="/dataviz/">Data Visualization</a><small>Tagged <span>&raquo;</span> <a href="/tags/dataviz/">dataviz</a></small></dd>

<dt>Jan 01</dt>
<dd><a href="/dataviz/">Data Visualization</a><small>Tagged <span>&raquo;</span> <a href="/tags/dataviz/">dataviz</a></small></dd>
<dd><a href="/dataviz/extended/">Extended</a><small>Tagged <span>&raquo;</span> <a href="/tags/DataViz/">DataViz</a></small></dd>


</dl>
Expand Down
2 changes: 1 addition & 1 deletion website/_site/dataviz/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ <h2><a href="/dataviz/">Data Visualization</a></h2>
<a href="/dataviz/part-0/">Part 0: Setup</a> – Initial setup for our Data Visualization tutorial.<br>
<a href="/dataviz/part-1/">Part 1: Parse</a> – Parse our sample SF crime data.<br>
<a href="/dataviz/part-2/">Part 2: Graph</a> – Graph our sample data with matplotlib.<br>
<a href="/dataviz/part-3/">Part 3: Map</a> – Plot our sample data on Google Maps.<br>
<a href="/dataviz/part-3/">Part 3: Map</a> – Plot our sample data on a map with GeoJSON.<br>
<a href="/dataviz/extended/">Extended</a> – How Data Visualization is used in real life, and where to go after finishing the tutorial.</p>
</dd>
</dl>
Expand Down
18 changes: 6 additions & 12 deletions website/_site/dataviz/intro/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ <h2>Introduction to the Data Visualization Tutorial</h2>

<p>This tutorial is meant to push you out of the Excel mindset just a little bit, and introduce you to the popular Python library, <a href="http://matplotlib.org/">matplotlib</a>. </p>
<h3 id="the-project">The Project</h3>
<p>The project we will create takes the sample data from the repository that you will download (a.k.a. clone) in <a href="/Part-0-Setup-for-DataViz">Part 0: Setup</a>, parse the sample data from columns and rows to a list of dictionaries, then render that data in two different graphs and in <a href="http://maps.google.com">Google Maps</a>.</p>
<p>The project we will create takes the sample data from the repository that you will download (a.k.a. clone) in <a href="/Part-0-Setup-for-DataViz">Part 0: Setup</a>, parse the sample data from columns and rows to a list of dictionaries, then render that data in two different graphs and in <a href="http://gist.github.com">GitHub</a> as a map.</p>

<p>The sample data that is included is a snapshot of public crime filings from the San Francisco police. Once you’ve gone through this tutorial, feel free to find other data that interests you, and rework our visualization functions.</p>
<h3 id="goals">Goals</h3>
Expand All @@ -96,7 +96,7 @@ <h3 id="goals">Goals</h3>
<li>import a Python file</li>
<li>take a raw file and parse its data with Python’s data structures</li>
<li>make a simple graph</li>
<li>produce a Google Maps-readable file</li>
<li>produce a GeoJSON file for mapping</li>
</ul>

<p>What else you will be exposed to:</p>
Expand All @@ -117,18 +117,12 @@ <h3 id="intro-to-numpy-and-matplotlib">Intro to NumPy and matplotlib</h3>
<p>We won&#39;t be using much of NumPy, but it is required that we install this library before we can install and use <code>matplotlib</code>.</p>

<p><a href="http://matplotlib.org/">matplotlib</a> is another popular scientific library that gives the developer tools to produce 2D figures. No longer do you need your <a href="http://www.amazon.com/Texas-Instruments-Titanium-Calculator-Packaging/dp/B0001EMLZ2">TI-89</a> calculator where you must punch in long lines of formulas, waiting precious seconds for it to render a graph that may be too zoomed in to realize you are missing an important axis point. Packed with detailed <a href="http://matplotlib.org/examples/index.html">examples</a>, you are able to make publication/presentation-quality graphs from the comfort of your keyboard.</p>
<h3 id="intro-to-google-mapping">Intro to Google Mapping</h3>
<p>It’d be kind of cool to place all the coordinates in our data on a map, wouldn’t it? Google Maps allows folks to upload KML-type documents, which is essentially a type of an XML document for displaying geographic-related data. </p>
<h3 id="intro-to-geojson">Intro to GeoJSON</h3>
<p><a href="http://en.wikipedia.org/wiki/GeoJSON">GeoJSON</a> is a derivative of <a href="http://en.wikipedia.org/wiki/JSON">JSON</a>, and very similar to <a href="http://en.wikipedia.org/wiki/Topojson">TopoJSON</a>. It’s a data format for simple geological feature, including coordinate points.</p>

<p>Google has a great KML <a href="https://developers.google.com/kml/documentation/">intro</a> and <a href="https://developers.google.com/kml/documentation/kml_tut">tutorial</a> for those interested. </p>
<p>We’ll be using a third-party module to help us in creating GeoJSON files: <a href="https://pypi.python.org/pypi/geojson/1.0"><code>geojson</code></a>. </p>

<p>Wikipedia has a pretty readable <a href="http://en.wikipedia.org/wiki/XML">explanation</a> of XML, and w3 has a simple <a href="http://www.w3schools.com/xml/">tutorial</a> if you want to learn more (<em>side comment</em>: w3 is not the greatest for learning front-end related web development, but fine for quick references). </p>

<p>Both KML and XML, as well as HTML and XHTML, follow the <a href="http://en.wikipedia.org/wiki/Document_Object_Model">DOM</a> convention, Document Object Model. It’s basically how you interact with different objects through defined functions.</p>

<p>As you are starting to realize the awesomeness of Python, you can assume there is an <code>xml</code> module in the standard library. How convenient! Python’s <code>xml.dom</code> module uses the DOM convention and gives us access to functions that HTML, XML, and KML will understand when we build our own KML document.</p>

<p>For the record, do not use Python’s <code>xml</code> library in production code until the core developers have implemented security fixes. For information, you can read <a href="http://blog.python.org/2013/02/announcing-defusedxml-fixes-for-xml.html">here</a>.</p>
<p><a href="https://github.com">GitHub</a> has an awesome feature that allows folks to paste GeoJSON files into <a href="https://gist.github.com">Gists</a>, and it automatically renders as a map.</p>

<p><a href="/dataviz/part-0">Continue on to the Setup for DataViz &rarr;</a></p>

Expand Down
8 changes: 6 additions & 2 deletions website/_site/dataviz/part-0/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ <h3 id="setup">Setup</h3>
<li><strong>NOTE</strong> Sometimes, NumPy is finicky. If the previous step returns errors, try:</li>
</ul>
<div class="code"><div><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2</pre></div></td><td class="code"><div class="highlight"><pre><span class="o">(</span>DataVizProj<span class="o">)</span><span class="nv">$ </span>pip install numpy
2
3</pre></div></td><td class="code"><div class="highlight"><pre><span class="o">(</span>DataVizProj<span class="o">)</span><span class="nv">$ </span>pip install numpy
<span class="o">(</span>DataVizProj<span class="o">)</span><span class="nv">$ </span>pip install matplotlib
<span class="o">(</span>DataVizProj<span class="o">)</span><span class="nv">$ </span>pip install geojson
</pre></div>
</td></tr></table></div></div>
<ul>
Expand Down Expand Up @@ -175,9 +177,11 @@ <h3 id="setup">Setup</h3>
</ul>
<div class="code"><div><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre>1
2
3</pre></div></td><td class="code"><div class="highlight"><pre><span class="o">(</span>DataVizProj<span class="o">)</span><span class="nv">$ </span>python
3
4</pre></div></td><td class="code"><div class="highlight"><pre><span class="o">(</span>DataVizProj<span class="o">)</span><span class="nv">$ </span>python
&gt;&gt;&gt; import numpy
&gt;&gt;&gt; import matplotlib
&gt;&gt;&gt; import geojson
</pre></div>
</td></tr></table></div></div>
<ul>
Expand Down
Loading

0 comments on commit 865a091

Please sign in to comment.