Installing Fiona on Ubuntu 14.04

This post consists of some quick notes on installing Fiona, a Python interface to OGR, which is a tool that one might want if working with GIS data on a regular basis. I’m trying to do things like convert shapefiles to geojson– without much luck until now (see below)– and this is one of the tools I’m looking at as part of the solution. If you want to install Fiona on Ubuntu 14.04 follow along.

I’ll be following the Fiona install instructions at github, using the Ubuntu 14.04-specific information. If you are on Windows, MAC, or another Linux flavor you should check the page for help with your OS.

So, first we need to install a library that Fiona wraps:

$ sudo apt-get install libgdal1-dev

Next, I’ll use pip to install the package as a user:

$ pip install --user fiona

We can get information on the install using pip show:

$ pip show fiona
---
Metadata-Version: 1.1
Name: Fiona
Version: 1.6.1
Summary: Fiona reads and writes spatial data files
Home-page: http://github.com/Toblerity/Fiona
Author: Sean Gillies
Author-email: sean.gillies@gmail.com
License: BSD
Location: /home/cstrelioff/.local/lib/python2.7/site-packages
Requires: cligj, click-plugins, six
Entry-points:
  [console_scripts]
  fio=fiona.fio.main:main_group
  [fiona.fio_commands]
  bounds=fiona.fio.bounds:bounds
  cat=fiona.fio.cat:cat
  collect=fiona.fio.cat:collect
  distrib=fiona.fio.cat:distrib
  dump=fiona.fio.cat:dump
  env=fiona.fio.info:env
  info=fiona.fio.info:info
  insp=fiona.fio.info:insp
  load=fiona.fio.cat:load

Okay, we have installed and are ready to go. I’ll use the command-line script, fio, included with the package for a quick demo using the shapefile exported from Alameda County School District Boundaries. To start, lets get information about the file:

$ fio info --indent 2 UnifiedSchool.shp
{
  "count": 29,
  "crs": "+datum=NAD83 +lat_0=36.5 +lat_1=37.0666666667 +lat_2=38.4333333333 +lon_0=-120.5 +no_defs +proj=lcc +units=us-ft +x_0=2000000 +y_0=500000.0",
  "driver": "ESRI Shapefile",
  "bounds": [
    6028235.836711481,
    1990996.2444430888,
    6280437.554092631,
    2157436.750131786
  ],
  "schema": {
    "geometry": "Polygon",
    "properties": {
      "DIST_NAME": "str:50",
      "DISTRICT_I": "int:10",
      "Shape_STAr": "float:19.11",
      "Shape_STLe": "float:19.11"
    }
  }
}

Finally, I will convert the shapefile into a geojson for visualizing on the web using leafletjs:

$ fio dump UnifiedSchool.shp --indent 2 --precision 2 > UnifiedSchool.json

and, checkout the result:

$ head UnifiedSchool.json
{
  "features": [
    {
      "geometry": {
        "coordinates": [
          [
            [
              -122.31,
              37.79
            ],

The main thing to notice is that the output has latitude and longitude values needed for leafletjs to show the regions correctly. The original shapefile did not have this formatting– very cool! Checkout the Fiona github page for examples on how to use the package. Also, you can check out the resulting map here. Try clicking on the districts to see the name as well as playing with the visible layers (upper-right corner of map). As always, comments and questions are welcome.

Tags

api [1]   arduino [1]   audio [2]   audio features [1]   babel [1]   Bayesian [7]   Beta [1]   blog setup [1]   bootstrap [1]   bottleneck [1]   c++ [1]   caret [1]   cmpy [1]   conditional probability [6]   coursera [1]   coursera intro to data science [3]   css [1]   cython [1]   d3 [2]   decision trees [2]   diy [1]   dropbox [1]   dsp [1]   e1071 [1]   essentia [1]   garmin [1]   geojson [1]   ggplot2 [1]   gis [2]   git [1]   gnuplot [1]   graphs [1]   html5 [1]   igraph [1]   ipython [1]   javascript [7]   joint probability [6]   json [1]   LaTeX [2]   LDA [1]   Lea [2]   machine learning [3]   marginal probability [6]   matplotlib [1]   meteor [2]   mir [1]   MongoDB [3]   music [2]   my python setup [5]   my ubuntu setup [10]   mysql [3]   networks [1]   networkx [1]   nodejs [5]   npm [3]   numexpr [1]   numpy [1]   octave [1]   Open Oakland [2]   openpyxl [1]   pandas [3]   patsy [1]   pip [2]   pweave [1]   pygraphviz [1]   pymc [1]   PySoundFile [2]   python [15]   Python [1]   python 2.7 [5]   python 3.4 [2]   pyyaml [1]   qgis [1]   R [1]   randomForest [1]   restview [1]   resume [1]   rpart [1]   running [1]   scikit-learn [3]   scipy [1]   screen [1]   server setup [1]   shapefile [1]   social networks [1]   Socrata [1]   sound [2]   sphinx [1]   sql [4]   sqlite3 [1]   ssh [1]   ssh keys [1]   statsmodels [1]   supervised learning [2]   sympy [1]   tableau [1]   tinkerer [2]   topic models [1]   tree [1]   ubuntu 14.04 [13]   Ubuntu 14.04 [3]   ubuntu 16.04 [4]   vim [2]   virtualbox [1]   virtualenv [4]   virtualenvwrapper [3]   VPS [1]   vundle [1]   webpack [1]   yaml [1]