class AnalysisWindowImport

Attributes

config[R]
global_config[R]
time_frame[R]

Public Class Methods

new(args = {}) click to toggle source
# File import_scripts/import_analysis_window.rb, line 20
def initialize(args = {})

        begin
                @config = YAML.load_file(args[:config])
                @time_frame = TimeFrame.new(start_date: config['start_date'], end_date: config['end_date'])
        rescue
                raise IOError.new("Error loading the configuration file: #{args[:config]}")
        end

        begin
                @global_config = YAML.load_file('config.yml')
        rescue
                raise IOError.new("Error loading global configuration file")
        end
        connect_to_database
end

Public Instance Methods

changeset_import() click to toggle source
# File import_scripts/import_analysis_window.rb, line 84
def changeset_import
        changeset_import = ChangesetImport.new
        puts "Importing #{changeset_import.distinct_changeset_ids.length} changesets"
        changeset_import.import_changeset_objects
        changeset_import.add_indexes
end
connect_to_database() click to toggle source

Calls the Singleton Database Connection for the specific database

# File import_scripts/import_analysis_window.rb, line 38
def connect_to_database
        #Open Database Connection
        puts "Connecting to: #{config['database']} Mongo Database\n"
        DatabaseConnection.new(database: config['database'], mongo_only: config[:mongo_only], mem_only: config[:mem_only])
end
run_mongo_import() click to toggle source
# File import_scripts/import_analysis_window.rb, line 71
def run_mongo_import
        conn = OSMPBF.new(end_date: time_frame.end_date, memory_only: config['memory_only'])
        conn.open_parser("import_scripts/temp.osm.pbf")
        puts conn.file_stats

        #Import Nodes, Ways, Relations
        conn.parse_to_collection(object_type="nodes", lim=nil)

        conn.parse_to_collection(object_type="ways", lim=nil)

        conn.parse_to_collection(object_type="relations", lim=nil)
end
run_osm_history_splitter() click to toggle source

Runs a system shell script to call the osm-history-splitter

# File import_scripts/import_analysis_window.rb, line 58
def run_osm_history_splitter
        begin
                unless config['soft-cut']
                        system "#{global_config['osm-history-splitter']} --hardcut #{config['pbf_file']} import_scripts/temp.config"
                else
                        system "#{global_config['osm-history-splitter']} --softcut #{config['pbf_file']} import_scripts/temp.config"
                end
        rescue
                raise Error.new("OSM History Splitter Failed")
                puts $!
        end
end
user_import() click to toggle source
# File import_scripts/import_analysis_window.rb, line 91
def user_import
        user_import = UserImport.new
        puts "Importing user data for #{user_import.distinct_uids.length} users"
        user_import.import_user_objects
end
write_configuration_file() click to toggle source
# File import_scripts/import_analysis_window.rb, line 44
def write_configuration_file
        # * the destination path and filename. The file-extension used specifies the generated file format (.osm, .osh, .osm.bz2, .osh.bz2, .osm.pbf, .osh.pbf)
        # * the type of extract (BBOX or POLY)
        # * the extract specification
        # * for BBOX: boundaries of the bbox, eg. -180,-90,180,90 for the whole world
        # * for OSM:  path to an .osm file from which all closed ways are taken as outlines of a MultiPolygon. Relations are not taken into account, so holes are not possible.
        # * for POLY: path to the .poly file

        File.open('import_scripts/temp.config', 'wb') do |file|
                file.write("import_scripts/temp.osm.pbf  BBOX #{config['bbox']}")
        end
end