The Scoop

  • Home
  • Projects
  • About The Scoop
  • Fixing Journalism
  • Medill Links
  • Departments
    • Apple
    • Asides
    • Broadcast
    • Campaign Finance
    • Car Tools
    • Data
    • DIY
    • django
    • Fed Data
    • FOIA
    • General
    • IRE
    • Journalism
    • Local Data
    • Mapping
    • Miscellany
    • NonGov Data
    • Online
    • Paper Trail
    • Presentations
    • Public Records
    • Python
    • Rails
    • SLA
    • Social Network Analysis
    • Sports
    • State Data
    • Teaching
    • Work
    • XML
  • Subscribe via RSS

The Hidden Appeal of GeoDjango

August 23rd, 2008  |  Published in Mapping, django  |  1 Comment

One of my tasks this summer was to learn a bit more about the GIS branch of Django, which is now in trunk as a contrib app thanks to the hard work of Justin Bronn, Travis Pinney and Co. Although there are many folks in the CAR community who are quite proficient at mapping technologies, I’m not one of them. I’ve taken a few mapping classes at various conferences over the years, but I haven’t really had a project that required me to use something like ArcView.

But lately I’ve been using GeoDjango for a work-related project (nothing to see yet, but fingers crossed) and it has been a real joy. That’s because its developers, like those of Django itself, have done a lot of work to make things seem pretty effortless. Case in point, and perhaps one of the GIS app’s strongest selling points, is the ease with which you can import spatial data into an app and make use of it. It’s called LayerMapping, and it’s relatively hidden-away in the “Extra Features” section of the GeoDjango wiki.

Here’s how it works: say you’ve got a shapefile (one of the most common spatial formats, particularly when it comes to government-created datafiles) and you want to use it with Django. LayerMapping, along with GeoDjango’s DataSource utility, can help you see what your models might need to look like and then, after you’ve created them, just one dictionary mapping the spatial data columns to your model is all that’s needed to get your data into your database (preferably Postgres). Underneath, the open source GDAL library is doing the heavy lifting, but as with most things Django, you don’t feel the pain at all.

And then it gets better, since you can simply use the Django ORM to access your spatial data, as demonstrated by one of the wiki examples:

qs2 = District.objects.filter(poly__contains='POINT(-95.362293 29.756539)')

Seems almost too good to be true, but it is. And it makes the occasional pain of installation well worth it. Considering that it’s now a standard part of django.contrib, there’s not much excuse for folks curious about using GIS data not to give it a try.

Responses

Feed Trackback Address
  1. Paul Reiber says:

    March 13th, 2009 at 11:09 pm (#)

    “relatively hidden-away”?

    THANK YOU… dude, you saved me a lotta digging! Yes, the LayerMapping interface is something that deserves to be called out better in the documentation.

    What you said last summer helped me out last week… that’s cool too, in a different way.

    …hack on!
    -pbr

Leave a Response

Recent Comments

  • Derek on 2010 CAR Conference
  • Michal Migurski on 2010 CAR Conference
  • Walt Matchim on Installing Instiki on Windows
  • Tyrone on Outsourcing Database Development, or the Caspio Issue
  • Danny Sanchez on Lightning Talks at NICAR

Recent Posts

  • 2010 CAR Conference
  • A Gentle Introduction to Google App Engine
  • Lightning Talks at NICAR
  • Fumblerooski and Raw SQL in Django
  • Using Geocoders with GeoDjango


©2010 The Scoop
Powered by WordPress using the Gridline Lite theme by Graph Paper Press.