Skip to content

Instantly share code, notes, and snippets.

@antico5
Last active May 22, 2018 13:51
Show Gist options
  • Save antico5/1b578565a3d65d0e989c14dbaff8aba6 to your computer and use it in GitHub Desktop.
Save antico5/1b578565a3d65d0e989c14dbaff8aba6 to your computer and use it in GitHub Desktop.
Install postgis

gem 'activerecord-postgis-adapter'

bundle install

# database.yml
development:
  adapter: postgis
  encoding: unicode
  postgis_extension: postgis      # default is postgis
  postgis_schema: public          # default is public
  schema_search_path: public,postgis
  pool: 5
  database: my_app_development    # your database name
  username: my_app_user           # the username your app will use to connect
  password: my_app_password       # the user's password
  su_username: my_global_user     # a superuser for the database
  su_password: my_global_pasword  # the superuser's password

sudo apt-get install postgresql-9.5-postgis-scripts sudo apt-get install postgresql-9.5-postgis-2.2

rake db:gis:setup

Add a point attribute to table

class AddLatlongToLocations < ActiveRecord::Migration[5.0]
  def change
    add_column :locations, :latlong, :st_point
  end
end

Make a point instance in code

l.latlong = "POINT(3 4)"

l.latlong = RGeo::Cartesian::Factory.new.point(2,2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment