Created
November 1, 2009 10:23
-
-
Save sabman/223461 to your computer and use it in GitHub Desktop.
set up an AR schema for PostGIS outside of Rails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment