[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Maposmatic-dev] [PATCH] Move street index creation into single page ren
From: |
David MENTRE |
Subject: |
[Maposmatic-dev] [PATCH] Move street index creation into single page renderer |
Date: |
Sat, 31 Mar 2012 19:52:56 +0200 |
Signed-off-by: David MENTRE <address@hidden>
---
ocitysmap2/__init__.py | 27 +++++-------------------
ocitysmap2/layoutlib/multi_page_renderer.py | 4 +-
ocitysmap2/layoutlib/single_page_renderers.py | 24 ++++++++++++++++++++-
3 files changed, 30 insertions(+), 25 deletions(-)
diff --git a/ocitysmap2/__init__.py b/ocitysmap2/__init__.py
index 2df4adb..8ab8460 100644
--- a/ocitysmap2/__init__.py
+++ b/ocitysmap2/__init__.py
@@ -444,15 +444,6 @@ SELECT ST_AsText(ST_LongestLine(
assert config.bounding_box is not None
assert config.polygon_wkt is not None
- # Prepare the index
- try:
- street_index = StreetIndex(self._db,
- config.polygon_wkt,
- config.i18n)
- except IndexEmptyError:
- LOG.warning("Designated area leads to an empty index")
- street_index = None
-
osm_date = self.get_osm_database_last_update()
# Create a temporary directory for all our shape files
@@ -467,21 +458,18 @@ SELECT ST_AsText(ST_LongestLine(
for output_format in output_formats:
output_filename = '%s.%s' % (file_prefix, output_format)
try:
- self._render_one(config, tmpdir, renderer_cls,
street_index,
- output_format, output_filename, osm_date)
+ self._render_one(config, tmpdir, renderer_cls,
+ output_format, output_filename, osm_date,
+ file_prefix)
except IndexDoesNotFitError:
LOG.exception("The actual font metrics probably don't "
"match those pre-computed by the renderer's"
"constructor. Backtrace follows...")
-
- # Also dump the CSV street index
- if street_index:
- street_index.write_to_csv(config.title, '%s.csv' % file_prefix)
finally:
self._cleanup_tempdir(tmpdir)
- def _render_one(self, config, tmpdir, renderer_cls, street_index,
- output_format, output_filename, osm_date):
+ def _render_one(self, config, tmpdir, renderer_cls,
+ output_format, output_filename, osm_date, file_prefix):
LOG.info('Rendering to %s format...' % output_format.upper())
@@ -527,10 +515,7 @@ SELECT ST_AsText(ST_LongestLine(
raise ValueError, \
'Unsupported output format: %s!' % output_format.upper()
- renderer = renderer_cls(self._db, config, tmpdir, dpi, street_index)
- # Update the street_index to reflect the grid's actual position
- if renderer.grid and street_index:
- street_index.apply_grid(renderer.grid)
+ renderer = renderer_cls(self._db, config, tmpdir, dpi, file_prefix)
surface = factory(renderer.paper_width_pt, renderer.paper_height_pt)
diff --git a/ocitysmap2/layoutlib/multi_page_renderer.py
b/ocitysmap2/layoutlib/multi_page_renderer.py
index 1acab3b..ee87d62 100644
--- a/ocitysmap2/layoutlib/multi_page_renderer.py
+++ b/ocitysmap2/layoutlib/multi_page_renderer.py
@@ -66,8 +66,8 @@ class MultiPageRenderer(Renderer):
description = 'A multi-page layout.'
multipages = True
- def __init__(self, db, rc, tmpdir, dpi, street_index):
- Renderer.__init__(self, db, rc, tmpdir, dpi, street_index)
+ def __init__(self, db, rc, tmpdir, dpi, file_prefix):
+ Renderer.__init__(self, db, rc, tmpdir, dpi, None)
self._grid_legend_margin_pt = \
min(Renderer.GRID_LEGEND_MARGIN_RATIO * self.paper_width_pt,
diff --git a/ocitysmap2/layoutlib/single_page_renderers.py
b/ocitysmap2/layoutlib/single_page_renderers.py
index 0ac066c..e76c98e 100644
--- a/ocitysmap2/layoutlib/single_page_renderers.py
+++ b/ocitysmap2/layoutlib/single_page_renderers.py
@@ -40,6 +40,9 @@ from ocitysmap2.indexlib.renderer import StreetIndexRenderer
import logging
+from indexlib.indexer import StreetIndex
+from indexlib.commons import IndexDoesNotFitError, IndexEmptyError
+
LOG = logging.getLogger('ocitysmap')
@@ -55,8 +58,8 @@ class SinglePageRenderer(Renderer):
MAX_INDEX_OCCUPATION_RATIO = 1/3.
- def __init__(self, db, rc, tmpdir, dpi,
- street_index = None, index_position = 'side'):
+ def __init__(self, db, rc, tmpdir, dpi, file_prefix,
+ index_position = 'side'):
"""
Create the renderer.
@@ -67,6 +70,19 @@ class SinglePageRenderer(Renderer):
index_position (str): None or 'side' (index on side),
'bottom' (index at bottom).
"""
+ # Prepare the index
+ try:
+ street_index = StreetIndex(db,
+ rc.polygon_wkt,
+ rc.i18n)
+ except IndexEmptyError:
+ LOG.warning("Designated area leads to an empty index")
+ street_index = None
+
+ # Dump the CSV street index
+ if street_index:
+ street_index.write_to_csv(rc.title, '%s.csv' % file_prefix)
+
Renderer.__init__(self, db, rc, tmpdir, dpi, street_index)
self._grid_legend_margin_pt = \
@@ -137,6 +153,10 @@ class SinglePageRenderer(Renderer):
# Prepare the grid
self.grid = self._create_grid(self._map_canvas)
+ # Update the street_index to reflect the grid's actual position
+ if self.grid and street_index:
+ street_index.apply_grid(self.grid)
+
# Commit the internal rendering stack of the map
self._map_canvas.render()
--
1.7.5.4
- [Maposmatic-dev] [PATCH] Move street index creation into single page renderer,
David MENTRE <=