sabman (owner)

Revisions

gist: 223461 Download_button fork
public
Description:
set up an AR schema for PostGIS outside of Rails
Public Clone URL: git://gist.github.com/223461.git
Embed All Files: show embed
setup_geo_schema.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
system('sudo gem install GeoRuby')
system('git clone git://github.com/fragility/spatial_adapter.git')
 
$:.unshift(File.join(File.dirname(__FILE__), 'spatial_adapter', 'lib'))
 
require "rubygems"
require "active_record"
 
ActiveRecord::Base.establish_connection(
  :adapter => "postgresql",
  :host => "localhost",
  :database => "veitnam_development",
  :username => "sabman",
  :password => ""
)
 
# These should be added AFTER the AR connection is established otherwise you will get
# "uninitialized constant ActiveRecord::..." error
require "post_gis_adapter"
require "geo_ruby"
 
class Poi < ActiveRecord::Base
end
 
# create a postgis database
system('createdb -T template_postgis vietnam_development')
 
# convert shapefile to sql
system('shp2pgsql -s 4326 -g geom pois.shp pois > pois.sql')
 
# change encoding to correct format - get script from https://gist.github.com/e658eb1df6f085d68352
system('convert_encoding.rb -f latin1 pois.sql')
 
# load the data in postgresql
system('psql -f pois.sql -d vietnam_development')