david wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • loosely coupled to geodjango...

34
Introduction to GeoDjango David Wilson

Upload: trandiep

Post on 10-Nov-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Introduction to GeoDjango

David Wilson

Page 2: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

An Outline:• Who am I? • What is GeoDjango?• A Tour of GeoDjango• Example: Colorado Geology

Page 3: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Who Am I?

Page 4: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Who Am I?

● Full time Java developer● Love Python and the web● Degree in Geophysics● Some GIS background, actively working to improve knowledge● Travel, weight lifting, cycling, and skiing

Page 5: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

What is GeoDjango?

Page 6: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

GeoDjango = spatial toolbox

Page 7: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Spatial?

Page 8: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Not Spatial

Page 9: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Spatial!

Page 10: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

A Tour of GeoDjango

Page 11: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Tour: Backends

Page 12: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Tour: Backends

Use this one!

Page 13: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Tour: Models

from django.contrib.gis.db import models

Page 14: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Tour: Models

Page 15: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Tour: Model Fields

● GeometryField● PointField● LineStringField● PolygonField● MultiPointField● MultiLineStringField● MultiPolygonField● GeometryCollectionField

Page 16: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Tour: GeoManager

● Overrides model manager● Enables spatial queries ● Gotcha: required on models with no spatial fields that need to query related models spatially

Page 17: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Tour: GeoQuerySet

● Many spatial queries, e.g.● contains● crosses● overlaps● intersects● Distance and area queries

● Gotcha: query availability varies based on backend

Page 18: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Tour: GeoQuerySet

Use this one!

Page 19: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Tour: GEOS API

• Geometry Engine – Open Source• Loosely coupled to GeoDjango• Allows for simple creation, manipulation, and transformation of geometries

Page 20: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Tour: GDAL API

● Geospatial Data Abstraction Library● Reads spatial data:

● Shapefiles● KML● And many, many more!

● Easy to abstract data sources

Page 21: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Tour: GeoIP

• Ctypes wrapper for MaxMind GeoIP• Requires appropriate local dataset• Allows server-side location• Generally not as accurate as HTML5 location API

Page 22: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Tour: GeoAdmin

Page 23: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Example: Colorado Geology

Page 24: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Example: Objectives

• Find Colorado geology data• Import data• Query data (find rocks near you!)• Make a pretty map

Page 25: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Example: Finding Data

Page 26: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Example: Importing Data

Page 27: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Example: Importing Data

Page 28: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Example: View

Page 29: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Example: JavaScript

Page 30: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Example: More JavaScript

Page 31: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Example: Demo

Page 32: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Conclusions

Page 33: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Conclusions

• Spatial toolbox• Use the parts you need• Built into the same Django you already own!

• Will need to understand GIS basics

• I hope to clean up this demo app and make a full tutorial

Page 34: David Wilsondavidwilson.me/files/introduction_to_geodjango.pdf · • Loosely coupled to GeoDjango • Allows for simple creation, manipulation, and transformation of geometries

Resources

Docs: https://docs.djangoproject.com/en/dev/ref/contrib/gis/

Vagrant image: https://github.com/david-wilson/vagrant-geodjango-base

USGS Colorado Geology Data:http://mrdata.usgs.gov/geology/state/state.php?state=CO

LeafletJS:http://leafletjs.com/

Contact Me:[email protected], @dwilson86, http://davidwilson.me