This repository was archived by the owner on Aug 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpdf_test.rb
More file actions
45 lines (35 loc) · 1.22 KB
/
pdf_test.rb
File metadata and controls
45 lines (35 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '.', '../mapcss_ruby/lib'))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '.', 'lib'))
require "OSM"
require "OSM/StreamParser"
require "OSM/Database"
require "style_parser"
require "prawn"
require "pdf_renderer"
# ----- Read stylesheet
ruleset=StyleParser::RuleSet.new(12,20)
ruleset.parse_from_file('opencyclemap.css')
# ----- Read OSM data
# (typing 'export OSMLIB_XML_PARSER=Expat' beforehand may speed things up)
puts "Reading file"
db = OSM::Database.new
parser = OSM::StreamParser.new(:filename => 'charlbury.osm', :db => db)
parser.parse
puts "Creating dictionary"
dictionary = StyleParser::Dictionary.instance
dictionary.populate(db)
# ----- Create a MapSpec
spec=PDFRenderer::MapSpec.new
spec.set_pagesize(PDFRenderer::MapSpec::A4, :margin=>10)
spec.minlon=-1.50; spec.minlat=51.86
spec.maxlon=-1.47; spec.maxlat=51.89
spec.minscale=12; spec.maxscale=18; spec.scale=15
spec.minlayer=-5; spec.maxlayer=5
spec.init_projection
# ----- Output the map
puts "Drawing map"
start=Time.now
Prawn::Document.generate('map.pdf', :page_size=>'A4') do |pdf|
spec.draw(pdf,ruleset,db)
end
puts "map.pdf generated in #{Time.now-start} seconds"