X-Git-Url: https://git.openstreetmap.org./chef.git/blobdiff_plain/ff044920428608b2c04507ad52d6ab52c9d6555f..fb1f1d56e8d8a6a86b79c71546e6c114fec2640c:/cookbooks/tile/files/default/ruby/expire.rb diff --git a/cookbooks/tile/files/default/ruby/expire.rb b/cookbooks/tile/files/default/ruby/expire.rb index 8bd448a88..7757386c5 100755 --- a/cookbooks/tile/files/default/ruby/expire.rb +++ b/cookbooks/tile/files/default/ruby/expire.rb @@ -15,42 +15,42 @@ module Expire "+nadgrids=@null", "+no_defs +over"]) # width/height of the spherical mercator projection - SIZE=40075016.6855784 + SIZE = 40075016.6855784 # the size of the meta tile blocks METATILE = 8 # the directory root for meta tiles HASH_ROOT = "/tiles/default/" # node cache file - NODE_CACHE_FILE="/store/database/nodes" + NODE_CACHE_FILE = "/store/database/nodes" # turns a spherical mercator coord into a tile coord - def Expire.tile_from_merc(point, zoom) + def self.tile_from_merc(point, zoom) # renormalise into unit space [0,1] point.x = 0.5 + point.x / SIZE point.y = 0.5 - point.y / SIZE # transform into tile space - point.x = point.x * 2 ** zoom - point.y = point.y * 2 ** zoom + point.x = point.x * 2**zoom + point.y = point.y * 2**zoom # chop of the fractional parts [point.x.to_int, point.y.to_int, zoom] end # turns a latlon -> tile x,y given a zoom level - def Expire.tile_from_latlon(latlon, zoom) + def self.tile_from_latlon(latlon, zoom) # first convert to spherical mercator point = PROJ.forward(latlon) tile_from_merc(point, zoom) end # this must match the definition of xyz_to_meta in mod_tile - def Expire.xyz_to_meta(x, y, z) + def self.xyz_to_meta(x, y, z) # mask off the final few bits x &= ~(METATILE - 1) y &= ~(METATILE - 1) # generate the path - hash_path = (0..4).collect { |i| - (((x >> 4*i) & 0xf) << 4) | ((y >> 4*i) & 0xf) - }.reverse.join('/') + hash_path = (0..4).collect do |i| + (((x >> 4 * i) & 0xf) << 4) | ((y >> 4 * i) & 0xf) + end.reverse.join('/') z.to_s + '/' + hash_path + ".meta" end @@ -58,12 +58,12 @@ module Expire EXPIRY_TIME = Time.parse("2000-01-01 00:00:00") # expire the meta tile by setting the modified time back - def Expire.expire_meta(meta) + def self.expire_meta(meta) puts "Expiring #{meta}" File.utime(EXPIRY_TIME, EXPIRY_TIME, meta) end - def Expire.expire(change_file, min_zoom, max_zoom, tile_dirs) + def self.expire(change_file, min_zoom, max_zoom, tile_dirs) do_expire(change_file, min_zoom, max_zoom) do |set| new_set = Set.new meta_set = Set.new @@ -93,12 +93,12 @@ module Expire end end - def Expire.do_expire(change_file, min_zoom, max_zoom, &_) + def self.do_expire(change_file, min_zoom, max_zoom, &_) # read in the osm change file doc = XML::Document.file(change_file) # hash map to contain all the nodes - nodes = Hash.new + nodes = {} # we put all the nodes into the hash, as it doesn't matter whether the node was # added, deleted or modified - the tile will need updating anyway. @@ -126,13 +126,14 @@ module Expire node_cache = NodeCache.new(NODE_CACHE_FILE) doc.find('//way/nd').each do |node| node_id = node['ref'].to_i - unless nodes.include? node_id - # this is a node referenced but not added, modified or deleted, so it should - # still be in the node cache. - if entry = node_cache[node_id] - point = Proj4::Point.new(entry.lon, entry.lat) - nodes[node_id] = tile_from_merc(point, max_zoom) - end + + next if nodes.include? node_id + + # this is a node referenced but not added, modified or deleted, so it should + # still be in the node cache. + if entry = node_cache[node_id] + point = Proj4::Point.new(entry.lon, entry.lat) + nodes[node_id] = tile_from_merc(point, max_zoom) end end @@ -176,7 +177,7 @@ module Expire if id <= @max_id offset = 16 + id * 8 - lon, lat = @cache[offset .. offset+7].unpack("ll") + lon, lat = @cache[offset..offset + 7].unpack("ll") if lon != -2147483648 && lat != -2147483648 node = Node.new(lon, lat)