|
| 1 | +!SLIDE |
| 2 | +# Chapter 3 |
| 3 | +## Geospatial |
| 4 | + |
| 5 | +!SLIDE center |
| 6 | +# Not your typical index |
| 7 | + |
| 8 | +#### [http://en.wikipedia.org/wiki/K-d\_tree](http://en.wikipedia.org/wiki/K-d_tree) |
| 9 | + |
| 10 | +!SLIDE center |
| 11 | +# PostGIS |
| 12 | +## Geospatial indexing and querying for PostgreSQL |
| 13 | + |
| 14 | +!SLIDE |
| 15 | +# Easy Ubuntu Install |
| 16 | +### Add PPA ppa:ubuntugis/ubuntugis-unstable |
| 17 | +### Install postgresql-8.4-postgis |
| 18 | + |
| 19 | +!SLIDE |
| 20 | +# Setup the language |
| 21 | + @@@ sql |
| 22 | + createdb my_db |
| 23 | + createlang plpgsql my_db |
| 24 | + psql -d my_db -f /usr/share/postgresql/8.4/ |
| 25 | + contrib/postgis-1.5/postgis.sql |
| 26 | + psql -d my_db -f /usr/share/postgresql/8.4/ |
| 27 | + contrib/postgis-1.5/spatial_ref_sys.sql |
| 28 | + psql -d my_db -f /usr/share/postgresql/8.4/ |
| 29 | + contrib/postgis_comments.sql |
| 30 | + |
| 31 | +!SLIDE |
| 32 | +# Setup your database |
| 33 | + @@@ sql |
| 34 | + CREATE sequence points_id_seq; |
| 35 | + CREATE TABLE points ( |
| 36 | + id integer PRIMARY KEY |
| 37 | + DEFAULT NEXTVAL('points_id_seq') |
| 38 | + ); |
| 39 | + SELECT AddGeometryColumn( |
| 40 | + 'points', 'location', 4326, 'POINT', 2 |
| 41 | + ); |
| 42 | + CREATE INDEX points_location_idx |
| 43 | + ON points USING GIST ( location ); |
| 44 | + |
| 45 | +!SLIDE |
| 46 | +# Create a point |
| 47 | + @@@ sql |
| 48 | + INSERT INTO points(location) VALUES ( |
| 49 | + ST_GeomFromText( |
| 50 | + 'POINT(-76.615657 39.327052)' |
| 51 | + ) |
| 52 | + ); |
| 53 | + |
| 54 | +!SLIDE |
| 55 | +# Find points in a radius |
| 56 | + @@@ sql |
| 57 | + SELECT * FROM points |
| 58 | + WHERE ST_Distance( |
| 59 | + location, |
| 60 | + ST_GeomFromText('POINT(-76 39)') |
| 61 | + ) < 1; |
| 62 | + |
| 63 | +!SLIDE |
| 64 | +# In Rails |
| 65 | +## GeoRuby |
| 66 | +### [http://georuby.rubyforge.org/](http://georuby.rubyforge.org/) |
| 67 | +## Spatial Adapter |
| 68 | +### [http://github.com/fragility/spatial\_adapter](http://github.com/fragility/spatial_adapter) |
| 69 | + |
| 70 | +!SLIDE |
| 71 | +# Will it blend? |
| 72 | + |
| 73 | +!SLIDE |
| 74 | +# 8,000,000 points |
| 75 | + |
| 76 | +!SLIDE |
| 77 | +# 5 years of data |
| 78 | + |
| 79 | +!SLIDE |
| 80 | +# Single EC2 Large @ 400rpm |
| 81 | + |
| 82 | +!SLIDE |
| 83 | +# Query: "What happened on my block last week?" |
| 84 | + |
| 85 | +!SLIDE |
| 86 | +# Avg 23ms response time |
| 87 | +## Database: 2.0ms |
| 88 | +## ActiveRecord: 6.8ms |
| 89 | +## Controller action + JSON: 14ms |
| 90 | + |
| 91 | +!SLIDE center |
| 92 | +# Remember compound indices from chapter 1? |
| 93 | +## Compound index on space and time |
| 94 | + |
| 95 | +#### [http://en.wikipedia.org/wiki/Spacetime](http://en.wikipedia.org/wiki/Spacetime) |
| 96 | + |
| 97 | +!SLIDE |
| 98 | +# There's more |
| 99 | +### Lines and polygons |
| 100 | +### Intersection operations |
| 101 | +### Partial and full containment |
| 102 | +### Distance calculation |
| 103 | +### Area computation |
| 104 | + |
| 105 | +!SLIDE |
| 106 | +# Can't touch this |
| 107 | +### MongoDB: flat earth model, only distance calculation |
| 108 | +### MySQL: containment via rectangles, no compound indexing |
| 109 | +### SQL Server: pretty good ... just icky |
| 110 | +### Sphinx + Solr: additional layer and pretty immature |
0 commit comments