class ChangesetImport
Attributes
changeset_api[R]
changeset_ids[R]
fail_log[R]
success_log[R]
Public Class Methods
new(limit=nil)
click to toggle source
# File import_scripts/osm_api/import_changesets.rb, line 7 def initialize(limit=nil) @changeset_api = OSMAPI.new("http://api.openstreetmap.org/api/0.6/changeset/") # #Open Log files # @success_log = LogFile.new("logs/changesets","successful") # @fail_log = LogFile.new("logs/changesets","failed") @limit = limit end
Public Instance Methods
add_indexes()
click to toggle source
# File import_scripts/osm_api/import_changesets.rb, line 57 def add_indexes DatabaseConnection.database['changesets'].ensure_index( id: 1 ) DatabaseConnection.database['changesets'].ensure_index( user: 1 ) DatabaseConnection.database['changesets'].ensure_index( geometry: "2dsphere") end
convert_osm_api_to_domain_object_hash(osm_api_hash)
click to toggle source
# File import_scripts/osm_api/import_changesets.rb, line 63 def convert_osm_api_to_domain_object_hash(osm_api_hash) data = osm_api_hash[:osm][:changeset] data[:created_at] = Time.parse data[:created_at] data[:closed_at] = Time.parse data[:closed_at] if data[:tag].is_a? Array data[:tags] = data[:tag].collect{|h| {h[:k]=>h[:v]}} elsif data[:tag].nil? data[:tags] = [] return data else data[:tags] = [ { data[:tag][:k] => data[:tag][:v] }] end data.delete :tag #Only have data[:tag], and it's an ARRAY! Look for a key of comment comment_index = data[:tags].index{|h| h.has_key? "comment" } unless comment_index.nil? data[:comment] = data[:tags].delete_at(comment_index)["comment"] else data[:comment] = "" end return data end
distinct_changeset_ids()
click to toggle source
# File import_scripts/osm_api/import_changesets.rb, line 17 def distinct_changeset_ids @changeset_ids ||= get_distinct_changeset_ids end
get_distinct_changeset_ids()
click to toggle source
# File import_scripts/osm_api/import_changesets.rb, line 22 def get_distinct_changeset_ids changesets = [] changesets = DatabaseConnection.database["nodes"].distinct("changeset") changesets += DatabaseConnection.database["ways"].distinct("changeset") changesets += DatabaseConnection.database["relations"].distinct("changeset") if @limit.nil? return changesets.uniq! else return changesets.uniq!.first(@limit) end end
import_changeset_objects()
click to toggle source
# File import_scripts/osm_api/import_changesets.rb, line 34 def import_changeset_objects distinct_changeset_ids.each_with_index do |changeset_id, index| begin this_changeset = changeset_api.hit_api(changeset_id) if this_changeset changeset_obj = Changeset.new convert_osm_api_to_domain_object_hash this_changeset changeset_obj.save! end if (index%10).zero? print '.' elsif (index%101).zero? print index end rescue => e puts "Error on Changeset: #{changeset_id}, continuing" puts $! end end end