kopia lustrzana https://github.com/hholzgra/ocitysmap
Merge branch 'master' of git://pollindd.local/
commit
1e2c85aad7
|
|
@ -25,7 +25,7 @@ def main():
|
|||
action='append')
|
||||
parser.add_option('-t', '--title', dest='output_title', metavar='TITLE',
|
||||
help='Specify the title displayed in the output files',
|
||||
default="City's Map")
|
||||
default=None)
|
||||
parser.add_option('-c', '--city', dest='city_name', metavar='CITY_NAME',
|
||||
help='Specify the name of te city to map')
|
||||
parser.add_option('-C', '--config', dest='config_file', metavar='FILE',
|
||||
|
|
@ -44,6 +44,24 @@ def main():
|
|||
parser.print_help()
|
||||
return 1
|
||||
|
||||
# Make sure either -b or -c is given
|
||||
if not options.city_name and not options.bbox:
|
||||
parser.error("One of --city or --bounding-box is mandatory")
|
||||
|
||||
if options.city_name and options.bbox:
|
||||
parser.error("--city or --bounding-box are exclusive")
|
||||
|
||||
# Determine title
|
||||
if options.no_frame:
|
||||
title = None
|
||||
elif options.output_title is not None:
|
||||
title = options.output_title
|
||||
elif options.city_name is not None:
|
||||
title = options.city_name
|
||||
else:
|
||||
title = "City's Map"
|
||||
|
||||
# Parse zoom factor
|
||||
try:
|
||||
options.zoom_factor = int(options.zoom_factor)
|
||||
except ValueError:
|
||||
|
|
@ -51,18 +69,9 @@ def main():
|
|||
if options.zoom_factor < 0 or options.zoom_factor > 18:
|
||||
parser.error("Invalid zoom factor: %s" % options.zoom_factor)
|
||||
|
||||
if options.no_frame:
|
||||
options.output_title = None
|
||||
|
||||
if not options.output_format:
|
||||
options.output_format = ['svg']
|
||||
|
||||
if not options.city_name and not options.bbox:
|
||||
parser.error("One of --city or --bounding-box is mandatory")
|
||||
|
||||
if options.city_name and options.bbox:
|
||||
parser.error("--city or --bounding-box are exclusive")
|
||||
|
||||
# Parse bounding box arguments
|
||||
boundingbox = None
|
||||
if options.bbox:
|
||||
|
|
@ -82,12 +91,12 @@ def main():
|
|||
except KeyboardInterrupt:
|
||||
sys.stderr.write(' Aborting.\n')
|
||||
|
||||
_map = renderer.render_into_files(options.output_title,
|
||||
_map = renderer.render_into_files(title,
|
||||
options.output_prefix,
|
||||
options.output_format,
|
||||
"zoom:%d" % options.zoom_factor)
|
||||
|
||||
renderer.render_index("City's Map", options.output_prefix,
|
||||
renderer.render_index(title, options.output_prefix,
|
||||
options.output_format,
|
||||
_map.width, _map.height)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,5 +7,5 @@ dbname=testdb
|
|||
[mapnik]
|
||||
map=/home/gutard/mapnik-osm/osm.xml
|
||||
|
||||
[maposmatic]
|
||||
[ocitysmap]
|
||||
copyright_logo=/home/decot/downloads/git/ocitysmap/Openstreetmap_logo.png
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ def enclose_in_frame(renderer, insurf_w, insurf_h,
|
|||
|
||||
|
||||
def add_logo(ctx, paperwidth, paperheight, logo_path,
|
||||
copyright_notice = u'© 2009 MapOSMatic authors. '
|
||||
copyright_notice = u'© 2009 MapOSMatic/ocitysmap authors. '
|
||||
u'Map data © 2009 OpenStreetMap.org '
|
||||
u'and contributors (CC-BY-SA)'):
|
||||
|
||||
|
|
@ -83,8 +83,9 @@ def add_logo(ctx, paperwidth, paperheight, logo_path,
|
|||
png = None
|
||||
if logo_path:
|
||||
try:
|
||||
f = open(logo_path, 'r')
|
||||
f = open(logo_path, 'rb')
|
||||
png = cairo.ImageSurface.create_from_png(f)
|
||||
l.debug('Using copyright logo: %s' % logo_path)
|
||||
f.close()
|
||||
except Exception, ex:
|
||||
l.warning('Cannot open logo file: %s' % ex)
|
||||
|
|
|
|||
|
|
@ -330,12 +330,8 @@ class MapCanvas:
|
|||
surface.flush()
|
||||
|
||||
# png rendering with cairo...
|
||||
if file_type in ('png', 'png24', 'png8'):
|
||||
out_file = open(output_filename, 'wb')
|
||||
try:
|
||||
surface.write_to_png(out_file)
|
||||
finally:
|
||||
out_file.close()
|
||||
if file_type in ('png', 'png24'):
|
||||
surface.write_to_png(output_filename)
|
||||
|
||||
surface.finish()
|
||||
|
||||
|
|
|
|||
|
|
@ -446,60 +446,52 @@ class OCitySMap:
|
|||
return sl
|
||||
|
||||
|
||||
def _render_one_prefix(self, title, output_prefix, format,
|
||||
def _render_one_prefix(self, title, output_prefix, file_type,
|
||||
paperwidth, paperheight):
|
||||
format = format.lower()
|
||||
file_type = file_type.lower()
|
||||
frame_width = int(max(paperheight / 20., 30))
|
||||
|
||||
outfile = "%s_index.%s" % (output_prefix, format)
|
||||
l.debug("rendering " + outfile + "...")
|
||||
output_filename = "%s_index.%s" % (output_prefix, file_type)
|
||||
l.debug("rendering " + output_filename + "...")
|
||||
|
||||
generator = IndexPageGenerator(self.streets)
|
||||
if format == 'png' or format == 'png24':
|
||||
surface = cairo.ImageSurface(cairo.FORMAT_RGB24,
|
||||
paperwidth + frame_width*2,
|
||||
paperheight + frame_width*2)
|
||||
enclose_in_frame(lambda ctx: generator.render(ctx, paperwidth,
|
||||
paperheight),
|
||||
paperwidth, paperheight,
|
||||
title, surface,
|
||||
paperwidth + frame_width*2,
|
||||
paperheight + frame_width*2, frame_width)
|
||||
surface.write_to_png(outfile)
|
||||
surface.finish()
|
||||
elif format == 'svg':
|
||||
surface = cairo.SVGSurface(outfile, paperwidth + frame_width*2,
|
||||
paperheight + frame_width*2)
|
||||
enclose_in_frame(lambda ctx: generator.render(ctx, paperwidth,
|
||||
paperheight),
|
||||
paperwidth, paperheight,
|
||||
title, surface,
|
||||
paperwidth + frame_width*2,
|
||||
paperheight + frame_width*2, frame_width)
|
||||
surface.finish()
|
||||
elif format == 'pdf':
|
||||
surface = cairo.PDFSurface(outfile, paperwidth + frame_width*2,
|
||||
paperheight + frame_width*2)
|
||||
enclose_in_frame(lambda ctx: generator.render(ctx, paperwidth,
|
||||
paperheight),
|
||||
paperwidth, paperheight,
|
||||
title, surface,
|
||||
paperwidth + frame_width*2,
|
||||
paperheight + frame_width*2,
|
||||
frame_width)
|
||||
surface.finish()
|
||||
elif format == 'ps':
|
||||
surface = cairo.PSSurface(outfile, paperwidth + frame_width*2,
|
||||
paperheight + frame_width*2)
|
||||
enclose_in_frame(lambda ctx: generator.render(ctx, paperwidth,
|
||||
paperheight),
|
||||
paperwidth, paperheight,
|
||||
title, surface,
|
||||
paperwidth + frame_width*2,
|
||||
paperheight + frame_width*2, frame_width)
|
||||
surface.finish()
|
||||
|
||||
if file_type in ('png', 'png24'):
|
||||
cairo_factory = \
|
||||
lambda w,h: cairo.ImageSurface(cairo.FORMAT_RGB24, w, h)
|
||||
|
||||
elif file_type == 'svg':
|
||||
cairo_factory = lambda w,h: cairo.SVGSurface(output_filename, w, h)
|
||||
|
||||
elif file_type == 'pdf':
|
||||
cairo_factory = lambda w,h: cairo.PDFSurface(output_filename, w, h)
|
||||
|
||||
elif file_type == 'ps':
|
||||
cairo_factory = lambda w,h: cairo.PSSurface(output_filename, w, h)
|
||||
|
||||
else:
|
||||
raise ValueError
|
||||
raise ValueError('Unsupported output format: %s' % file_type)
|
||||
|
||||
if title is not None:
|
||||
surface = cairo_factory(paperwidth + frame_width*2,
|
||||
paperheight + frame_width*2)
|
||||
enclose_in_frame(lambda ctx: generator.render(ctx, paperwidth,
|
||||
paperheight),
|
||||
paperwidth, paperheight,
|
||||
title, surface,
|
||||
paperwidth + frame_width*2,
|
||||
paperheight + frame_width*2, frame_width)
|
||||
else:
|
||||
surface = cairo_factory(paperwidth, paperheight)
|
||||
ctx = cairo.Context(surface)
|
||||
generator.render(ctx, paperwidth, paperheight)
|
||||
|
||||
surface.flush()
|
||||
|
||||
if file_type in ('png', 'png24'):
|
||||
surface.write_to_png(output_filename)
|
||||
|
||||
surface.finish()
|
||||
|
||||
def render_index(self, title, output_prefix, output_format,
|
||||
paperwidth, paperheight):
|
||||
|
|
@ -632,7 +624,7 @@ class OCitySMap:
|
|||
|
||||
# Determine parameters
|
||||
try:
|
||||
copyright_logo = self.parser.get('maposmatic', 'copyright_logo')
|
||||
copyright_logo = self.parser.get('ocitysmap', 'copyright_logo')
|
||||
except Exception:
|
||||
copyright_logo = None
|
||||
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue