maposmatic-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Maposmatic-dev] [PATCH 10/22] renderers: pass the db connection to the


From: Thomas Petazzoni
Subject: [Maposmatic-dev] [PATCH 10/22] renderers: pass the db connection to the Renderer class constructor
Date: Fri, 30 Mar 2012 13:00:27 +0200

For the multi-page renderer, we need a reference to the GIS database
connection in order to build custom indexes for each page of the
map. Therefore, we modify the Renderer constructor so that it takes as
argument a reference to the database connection.

Signed-off-by: Thomas Petazzoni <address@hidden>
---
 ocitysmap2/__init__.py                        |    2 +-
 ocitysmap2/layoutlib/abstract_renderer.py     |    3 ++-
 ocitysmap2/layoutlib/single_page_renderers.py |   18 ++++++++----------
 3 files changed, 11 insertions(+), 12 deletions(-)

diff --git a/ocitysmap2/__init__.py b/ocitysmap2/__init__.py
index 054d4bf..ceba182 100644
--- a/ocitysmap2/__init__.py
+++ b/ocitysmap2/__init__.py
@@ -520,7 +520,7 @@ SELECT ST_AsText(ST_LongestLine(
             raise ValueError, \
                 'Unsupported output format: %s!' % output_format.upper()
 
-        renderer = renderer_cls(config, tmpdir, dpi, street_index)
+        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:
diff --git a/ocitysmap2/layoutlib/abstract_renderer.py 
b/ocitysmap2/layoutlib/abstract_renderer.py
index f2bc858..713bf58 100644
--- a/ocitysmap2/layoutlib/abstract_renderer.py
+++ b/ocitysmap2/layoutlib/abstract_renderer.py
@@ -58,7 +58,7 @@ class Renderer:
     # on the rendered map of a kilometer
     DEFAULT_KM_IN_MM = 100
 
-    def __init__(self, rc, tmpdir, street_index):
+    def __init__(self, db, rc, tmpdir, street_index):
         """
         Create the renderer.
 
@@ -68,6 +68,7 @@ class Renderer:
            street_index (StreetIndex): None or the street index object.
         """
         # Note: street_index may be None
+        self.db           = db
         self.rc           = rc
         self.tmpdir       = tmpdir
         self.grid         = None # The implementation is in charge of it
diff --git a/ocitysmap2/layoutlib/single_page_renderers.py 
b/ocitysmap2/layoutlib/single_page_renderers.py
index 1cbdc83..e5137c8 100644
--- a/ocitysmap2/layoutlib/single_page_renderers.py
+++ b/ocitysmap2/layoutlib/single_page_renderers.py
@@ -55,7 +55,7 @@ class SinglePageRenderer(Renderer):
 
     MAX_INDEX_OCCUPATION_RATIO = 1/3.
 
-    def __init__(self, rc, tmpdir, dpi,
+    def __init__(self, db, rc, tmpdir, dpi,
                  street_index = None, index_position = 'side'):
         """
         Create the renderer.
@@ -67,7 +67,7 @@ class SinglePageRenderer(Renderer):
            index_position (str): None or 'side' (index on side),
               'bottom' (index at bottom).
         """
-        Renderer.__init__(self, rc, tmpdir, street_index)
+        Renderer.__init__(self, db, rc, tmpdir, street_index)
 
         self._grid_legend_margin_pt = \
             min(Renderer.GRID_LEGEND_MARGIN_RATIO * self.paper_width_pt,
@@ -489,7 +489,7 @@ class SinglePageRendererNoIndex(SinglePageRenderer):
     name = 'plain'
     description = 'Full-page layout without index.'
 
-    def __init__(self, rc, tmpdir, dpi, street_index):
+    def __init__(self, db, rc, tmpdir, dpi, street_index):
         """
         Create the renderer.
 
@@ -498,7 +498,7 @@ class SinglePageRendererNoIndex(SinglePageRenderer):
            tmpdir (os.path): Path to a temp dir that can hold temp files.
            street_index (StreetIndex): None or the street index object.
         """
-        SinglePageRenderer.__init__(self, rc, tmpdir, dpi, None, None)
+        SinglePageRenderer.__init__(self, db, rc, tmpdir, dpi, None, None)
 
 
     @staticmethod
@@ -527,7 +527,7 @@ class SinglePageRendererIndexOnSide(SinglePageRenderer):
     name = 'single_page_index_side'
     description = 'Full-page layout with the index on the side.'
 
-    def __init__(self, rc, tmpdir, dpi, street_index):
+    def __init__(self, db, rc, tmpdir, dpi, street_index):
         """
         Create the renderer.
 
@@ -536,8 +536,7 @@ class SinglePageRendererIndexOnSide(SinglePageRenderer):
            tmpdir (os.path): Path to a temp dir that can hold temp files.
            street_index (StreetIndex): None or the street index object.
         """
-        SinglePageRenderer.__init__(self, rc, tmpdir, dpi, street_index, 
'side')
-
+        SinglePageRenderer.__init__(self, db, rc, tmpdir, dpi, street_index, 
'side')
 
     @staticmethod
     def get_compatible_paper_sizes(bounding_box, zoom_level,
@@ -565,7 +564,7 @@ class SinglePageRendererIndexBottom(SinglePageRenderer):
     name = 'single_page_index_bottom'
     description = 'Full-page layout with the index at the bottom.'
 
-    def __init__(self, rc, tmpdir, dpi, street_index):
+    def __init__(self, db, rc, tmpdir, dpi, street_index):
         """
         Create the renderer.
 
@@ -574,8 +573,7 @@ class SinglePageRendererIndexBottom(SinglePageRenderer):
            tmpdir (os.path): Path to a temp dir that can hold temp files.
            street_index (StreetIndex): None or the street index object.
         """
-        SinglePageRenderer.__init__(self, rc, tmpdir, dpi, street_index, 
'bottom')
-
+        SinglePageRenderer.__init__(self, db, rc, tmpdir, dpi, street_index, 
'bottom')
 
     @staticmethod
     def get_compatible_paper_sizes(bounding_box, zoom_level,
-- 
1.7.4.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]