Pluggable Maps

By • Hacks/Hackers in Los Angeles

Slides

Show the extracted slide text

Slide 1

a @LATdatadesk joint

Slide 2

The Data Desk is a team of reporters and web developers in #DTLA.

Slide 3

We make maps.

Slide 8

We do other things, too.

Slide 14

We build things with Django, which is in Python.

Slide 15

Django can play with some great GIS tools. (Thanks, @jbronn!)

Slide 16

from django.contrib.gis.db import models
class UnemploymentRate(models.Model):
fips_code = models.CharField(max_length=5)
county = models.CharField(max_length=150)
rate = models.FloatField()
polygon = models.MultiPolygonField()
objects = models.GeoManager()
def __unicode__(self):
return self.county

GeoDjango is great because it makes adding GIS data a snap.

Slide 17

Unemployment

Election results

Census demographics

But what happens when you reuse the same maps?

Slide 18

from django.contrib.gis.db import models
class UnemploymentRate(models.Model):
fips_code = models.CharField(max_length=5)
county = models.CharField(max_length=150)
rate = models.FloatField()
polygon = models.MultiPolygonField()
objects = models.GeoManager()
def __unicode__(self):
return self.county

If you use the model we looked at before...

Slide 19

from django.contrib.gis.db import models
class ElectionResult(models.Model):
fips_code = models.CharField(max_length=5)
county = models.CharField(max_length=150)
red_percent = models.FloatField()
blue_percent = models.FloatField()
polygon = models.MultiPolygonField()
objects = models.GeoManager()
def __unicode__(self):
return self.county

...you can end up with...

Slide 20

from django.contrib.gis.db import models
class Income(models.Model):
fips_code = models.CharField(max_length=5)
county = models.CharField(max_length=150)
median_income = models.FloatField()
polygon = models.MultiPolygonField()
objects = models.GeoManager()
def __unicode__(self):
return self.county

...nearly identical models scattered all over the place.

Slide 21

THIS IS BAD
(Or, at least has problems)

You are repeating yourself.
Three loaders. Three columns. Three islands.

The data can't talk to each other.
How do you mash up the datasets?

Your next app doesn't get any easier.
Get ready to repeat yourself again.

Slide 22

@ubernostrum preaches The Fourfold Path of Reusable Apps
1. Do one thing, and do it well.
2. Don't be afraid of multiple apps.
3. Write for flexibility.
4. Build to distribute.

Slide 23

from django.contrib.gis.db import models
class County(models.Model):
fips_code = models.CharField(max_length=5)
name = models.CharField(max_length=150)
polygon = models.MultiPolygonField()
objects = models.GeoManager()
def __unicode__(self):
return self.name

So if we make a separate app, with just the GIS data...

Slide 24

from django.contrib.gis.db import models
from us_counties.models import County
class UnemploymentRate(models.Model):
rate = models.FloatField()
county = models.OneToOneField(County)
def __unicode__(self):
return self.county

...and then just have each of our data apps link to it...

Slide 25

from django.contrib.gis.db import models
from us_counties.models import County
class ElectionResult(models.Model):
red_percent = models.FloatField()
blue_percent = models.FloatField()
county = models.OneToOneField(County)
def __unicode__(self):
return self.county

...then all of a sudden...

Slide 26

from django.contrib.gis.db import models
from us_counties.models import County
class Income(models.Model):
median_income = models.FloatField()
county = models.OneToOneField(County)
def __unicode__(self):
return self.county

....everything gets a bit simpler.

Slide 27

THIS IS GOOD
(Or, at least I think so)

One map to rule them all.
Load the data once and you're set forever.

Your data are interconnected.
You can easily mash up different data sets.

The next app is easier.
All you need is a foreign key link.

Your GIS data can be packaged on pip.
Wait...are you serious...that would mean...

Slide 28

$ pip install latimes-pluggablemaps-uscounties

Slide 29

http://lat.ms/pluggable

Slide 30

FOLLOW US ON TWITTER

@LATdatadesk
@LATmappingLA
@schwanksta
@palewire

Slide 31

Come work with us. Find this man.
or email him at daniel.gaines@latimes.com

Downloads

Slides PDF · Extracted slide text