This repository was archived by the owner on Jul 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathrun_mapbook.py
More file actions
executable file
·95 lines (73 loc) · 3.93 KB
/
run_mapbook.py
File metadata and controls
executable file
·95 lines (73 loc) · 3.93 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# encoding: utf-8
'''
This file is part of mapbook.
mapbook is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
mapbook is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Mapbook. If not, see <http://www.gnu.org/licenses/>.
Copyright 2012 Paul Norman
'''
from mapbook import *
import math
import argparse
def create_example(opts):
# Build a list of pages to skip
skippedmaps = []
if opts.skip:
for options in opts.skip:
for numbers in options.split(','):
skippedmaps.append(int(numbers))
sheet = Sheet(opts.pagewidth, opts.pageheight, 15.)
mapwidth = opts.width/opts.columns
rows = int(math.ceil(opts.height/(mapwidth*sheet.ratio)))
bbox = Bbox(opts.startx, opts.starty, mapwidth, sheet.ratio, '4%')
myarea = Area(Pagelist(rows, opts.columns, 1, skippedmaps, right=False), bbox, sheet, dpi=opts.dpi)
attribtext = 'Copyright OpenStreetMap contributors, CC BY-SA\nSee www.openstreetmap.org for more information\n\nmapbook software Copyright 2012 Paul Norman, licensed under the GPL v3\nwww.openmapbook.org'
appearance = Appearance( mapfile=opts.mapfile,
sidetext=TextSettings((1., 1., 1.), 'PT Sans Bold', .4, (0., 0., 0.)),
overviewtext=TextSettings((.25, .25, .25), 'PT Sans', 3.0, (.5, .5, .5)),
header=TextSettings((0., 0., 0.), 'PT Sans Bold', .6, (0., 0., 0.)),
title=Text((0., 0., 0.), 'PT Sans', 48, (0., 0., 0.),opts.title),
attribution=Text((0., 0., 0.),'PT Sans', 12, (0., 0., 0.), attribtext))
mybook = Book(opts.outputfile,myarea,appearance)
mybook.create_title()
mybook.create_preface()
mybook.create_maps()
mybook.create_attribution()
mybook._surface.finish()
if __name__ == "__main__":
class LineArgumentParser(argparse.ArgumentParser):
def convert_arg_line_to_args(self, arg_line):
if arg_line:
if arg_line.strip()[0] == '#':
return
for arg in ('--' + arg_line).split():
if not arg.strip():
continrue
yield arg
parser = LineArgumentParser(description='Create a mapbook',fromfile_prefix_chars='@')
# Location-based options
parser.add_argument('--startx', type=float, help='West coordinate to map in mercator km',required=True)
parser.add_argument('--starty', type=float, help='South coordinate to map in mercator km',required=True)
parser.add_argument('--width', type=float, help='Width in mercator km of the overall map',required=True)
parser.add_argument('--height', type=float, help='Target height in mercator km of the overall map',required=True)
parser.add_argument('--columns',type=int,help='Number of columns of maps', default=4)
# Page layout options
parser.add_argument('--pagewidth', type=float, help='Page width in points. Should be <= physical page width. Default is 8.5x11 portrait.',default=612.)
parser.add_argument('--pageheight', type=float, help='Page height in points. Should be <= physical page height. Default is 8.5x11 portrait.',default=792)
parser.add_argument('--title', help='Title of the map',default='A mapbook map')
# File options
parser.add_argument('--mapfile',help='Mapnik XML file',default='osm.xml')
parser.add_argument('--outputfile',help='Name of PDF file to create',default='map.pdf')
# Grid options
parser.add_argument('--skip',action='append',help='Comma-seperated list of map numbers to skip. May be specified multiple times', default='')
# Page options
parser.add_argument('--dpi',type=float,help='DPI of mapnik image', default=300.)
opts=parser.parse_args()
create_example(opts)