Skip to content

Instantly share code, notes, and snippets.

@rlisowski
Last active October 18, 2017 05:38
Show Gist options
  • Select an option

  • Save rlisowski/dd209c9fd03438dc67fdf59eeeaeb917 to your computer and use it in GitHub Desktop.

Select an option

Save rlisowski/dd209c9fd03438dc67fdf59eeeaeb917 to your computer and use it in GitHub Desktop.
MapFilters seeds data for PostgreSQL
require Rails.root.join('lib/shapefile_importer')
# PostgreSQL data preparation
Shapefile.delete_all
ActiveRecord::Base.connection.execute("TRUNCATE #{Shapefile.table_name} RESTART IDENTITY")
ShapefilesImporter.new(shapefile_path: Rails.root.join('db/shapefiles/postal_district.shp')).call
Location.delete_all
ActiveRecord::Base.connection.execute("TRUNCATE #{Location.table_name} RESTART IDENTITY")
# create some locations inside and around Bromley, London
(51.272..51.449).step(0.002).each do |lat|
(0.008..0.180).step(0.002).each do |lng|
Location.create!(coordinates: "POINT(#{lng.round(3)} #{lat.round(3)})")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment