Skip to content

Instantly share code, notes, and snippets.

@szimek
Created June 20, 2010 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save szimek/446016 to your computer and use it in GitHub Desktop.
Save szimek/446016 to your computer and use it in GitHub Desktop.
How to setup PostGIS with Rails
class CreateLocations < ActiveRecord::Migration
def self.up
create_table :locations do |t|
t.datetime :time
t.point :geom, :null => false, :srid => 4326, :with_z => true
t.float :speed
end
end
def self.down
drop_table :locations
end
end
http://www.lincolnritter.com/blog/2007/12/04/installing-postgresql-postgis-and-more-on-os-x-leopard/
Connect to the template database
$ psql template1
Execute the following commands:
template1=# create database template_postgis with template = template1;
template1=# UPDATE pg_database SET datistemplate = TRUE where datname = 'template_postgis';
Connect to the new template_postgis database:
template1=# \c template_postgis
Add PostGIS extensions and grant access to everyone to spatial tables:
template_postgis=# CREATE LANGUAGE plpgsql;
template_postgis=# \i /opt/local/share/postgresql84/contrib/postgis-1.5/postgis.sql;
template_postgis=# \i /opt/local/share/postgresql84/contrib/postgis-1.5/spatial_ref_sys.sql;
template_postgis=# GRANT ALL ON geometry_columns TO PUBLIC;
template_postgis=# GRANT ALL ON spatial_ref_sys TO PUBLIC;
Prevent further modifications to the template_postgis database:
template_postgis=# VACUUM FREEZE;
common: &common
adapter: postgresql
host: localhost
port: 5432
username:
password:
encoding: utf8
template: template_postgis
pool: 5
timeout: 5000
development:
<<: *common
database: development
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *common
database: test
production:
<<: *common
database: production
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment