This file contains hidden or 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
| 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") |
This file contains hidden or 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
| class ShapefileImporter | |
| def call | |
| RGeo::Shapefile::Reader.open(shapefile_path, srid: 4326) do |shapes| | |
| shapes.each do |shape| | |
| Shapefile.create!( area_name: shape.attributes['post_dist'], geometry: shape.geometry) | |
| end | |
| end | |
| end | |
| private |
This file contains hidden or 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
| class Shapefile < ApplicationRecord | |
| end |
This file contains hidden or 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
| class CreateShapefiles < ActiveRecord::Migration[5.1] | |
| def change | |
| enable_extension "postgis" | |
| create_table :shapefiles do |t| | |
| t.string :area_name | |
| t.geometry :geometry, geographic: true | |
| t.timestamps | |
| end |
This file contains hidden or 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
| ogr2ogr -f "ESRI Shapefile" wgs84.shp shapes.shp -s_srs EPSG:27700 -t_srs EPSG:4326 |
This file contains hidden or 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
| rake db:create | |
| rake db:migrate | |
| rails server |
This file contains hidden or 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
| gem 'activerecord-postgis-adapter' | |
| gem 'rgeo-geojson' | |
| gem 'rgeo-shapefile' |
This file contains hidden or 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
| rails new MapFilters -T --database=postgresql |
This file contains hidden or 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
| =Navigating= | |
| visit('/projects') | |
| visit(post_comments_path(post)) | |
| =Clicking links and buttons= | |
| click_link('id-of-link') | |
| click_link('Link Text') | |
| click_button('Save') | |
| click('Link Text') # Click either a link or a button | |
| click('Button Value') |
This file contains hidden or 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
| class Element | |
| include Comparable | |
| attr_accessor :name, :priority | |
| def initialize(name, priority) | |
| @name, @priority = name, priority | |
| end | |
| def <=>(other) |