Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 42ebe7a

Browse files
author
Nick Gauthier
committed
added chapter 3
1 parent e9e0cc4 commit 42ebe7a

File tree

5 files changed

+112
-1
lines changed

5 files changed

+112
-1
lines changed

chapter-2/01-fks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363
!SLIDE
6464
# Foreigner Gem
65-
### [http://github.com/matthuhiggins/foreigner](http://github.com/matthuhiggins/foreigner])
65+
### [http://github.com/matthuhiggins/foreigner](http://github.com/matthuhiggins/foreigner)
6666
@@@ ruby
6767

6868
gem 'matthuhiggins-foreigner',

chapter-3/01-geo.md

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
!SLIDE
2+
# Chapter 3
3+
## Geospatial
4+
5+
!SLIDE center
6+
# Not your typical index
7+
![K-D Tree](kdtree.png)
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+
![Spacetime](spacetime.png)
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

chapter-3/kdtree.png

38.2 KB
Loading

chapter-3/spacetime.png

39.1 KB
Loading

showoff.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
{"section":"intro"},
55
{"section":"chapter-1"},
66
{"section":"chapter-2"},
7+
{"section":"chapter-3"},
78
{"section":"conclusion"}
89
]
910
}

0 commit comments

Comments
 (0)