Skip to content

Instantly share code, notes, and snippets.

@swindsor
Created August 6, 2009 01:16
Show Gist options
  • Save swindsor/163078 to your computer and use it in GitHub Desktop.
Save swindsor/163078 to your computer and use it in GitHub Desktop.
require 'benchmark'
namespace "tax" do
desc "Import Tax Jurisdictions"
task :import_jurisdictions => :environment do
tms = Benchmark.measure do
abcs = ActiveRecord::Base.configurations
case abcs[RAILS_ENV]["adapter"]
when "postgresql"
username = abcs[RAILS_ENV]["username"]
database = abcs[RAILS_ENV]["database"]
e = "shp2pgsql -s 2286 -g geom -d #{RAILS_ROOT}/data/tax/Cities.shp tax_jurisdictions | psql -U #{username} #{database}"
puts e
puts `#{e}`
# migrate to our SRID
ActiveRecord::Base.connection.execute("ALTER TABLE tax_jurisdictions DROP CONSTRAINT enforce_srid_geom")
ActiveRecord::Base.connection.execute("UPDATE tax_jurisdictions set geom = transform(geom, #{SRID})")
ActiveRecord::Base.connection.execute("ALTER TABLE tax_jurisdictions ADD CONSTRAINT enforce_srid_geom check (srid(geom) = #{SRID})")
end
end
puts "Import Tax Jurisdictions took: #{tms.to_s}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment