require "quad_tile/quad_tile_so"
rescue MissingSourceFile
def self.tile_for_point(lat, lon)
- x = ((lon + 180) * 65535 / 360).round
- y = ((lat + 90) * 65535 / 180).round
+ x = ((lon.to_f + 180) * 65535 / 360).round
+ y = ((lat.to_f + 90) * 65535 / 180).round
return tile_for_xy(x, y)
end
return t
end
+
+ def self.iterate_tiles_for_area(minlat, minlon, maxlat, maxlon)
+ tiles = tiles_for_area(minlat, minlon, maxlat, maxlon)
+ first = last = nil
+
+ tiles.sort.each do |tile|
+ if last.nil?
+ first = last = tile
+ elsif tile == last + 1
+ last = tile
+ else
+ yield first, last
+
+ first = last = tile
+ end
+ end
+
+ yield first, last unless last.nil?
+ end
end
- def self.sql_for_area(minlat, minlon, maxlat, maxlon)
+ def self.sql_for_area(minlat, minlon, maxlat, maxlon, prefix)
sql = Array.new
single = Array.new
if first == last
single.push(first)
else
- sql.push("tile BETWEEN #{first} AND #{last}")
+ sql.push("#{prefix}tile BETWEEN #{first} AND #{last}")
end
end
- sql.push("tile IN (#{single.join(',')})") if single.size > 0
+ sql.push("#{prefix}tile IN (#{single.join(',')})") if single.size > 0
return "( " + sql.join(" OR ") + " )"
end
- def self.iterate_tiles_for_area(minlat, minlon, maxlat, maxlon)
- tiles = tiles_for_area(minlat, minlon, maxlat, maxlon)
- first = last = nil
-
- tiles.sort.each do |tile|
- if last.nil?
- first = last = tile
- elsif tile == last + 1
- last = tile
- else
- yield first, last
-
- first = last = tile
- end
- end
-
- yield first, last unless last.nil?
- end
-
private_class_method :tile_for_xy, :iterate_tiles_for_area
end