zondag 24 oktober 2010

Postgres and PostGIS setup for Rails 3

In ubuntu, add as source: ppa:ubuntugis/ubuntugis-unstable In terminal:

~$ sudo apt-get install postgresql-8.4-postgis ~$ sudo su postgres postgres@your-desktop:/home/username$ createuser username (your linux username) Shall the new role be a superuser? (y/n) y postgres@your-desktop:/home/username$ exit

Now it is time to create the databases

make sure your database.yaml file looks like this:

development: adapter: postgresql database: project_development username: username

(etc for test and production)

In the Gemfile, you should have the following gems enabled:

gem “pg” gem “nofxx-georuby” gem “spatial_adapter”

after bundle install, you should be able to run rake db:create

Now we need to add the PostGIS stuff to the database

sudo su postgres createlang plpgsql project_development psql -d project_development -f /usr/share/postgresql/8.4/contrib/postgis-1.5/postgis.sql psql -d project_development -f /usr/share/postgresql/8.4/contrib/postgis-1.5/spatial_ref_sys.sql psql -d project_development -f /usr/share/postgresql/8.4/contrib/postgis_comments.sql

And now we can use spatial columns in our database and migrations!

add_column :assets, :location, :point, :srid => -1 add_column :assets, :ground_space, :line_string, :srid => -1

add_index :assets, :location, :spatial => true add_index :assets, :ground_space, :spatial => true

Enjoy!

Posted via email from posterous of Matthijs Groen

Geen opmerkingen: