/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/UI/renderer.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/UI/renderer.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 909 by frank, Fri May 16 16:23:12 2003 UTC revision 965 by jonathan, Wed May 21 17:24:22 2003 UTC
# Line 9  Line 9 
9    
10  __version__ = "$Revision$"  __version__ = "$Revision$"
11    
12    import cStringIO
13    
14  from Thuban import _  from Thuban import _
15    
16  from wxPython.wx import wxMemoryDC, wxEmptyBitmap, \  from wxPython.wx import wxMemoryDC, wxEmptyBitmap, \
17      wxPoint, wxRect, wxPen, wxBrush, wxFont, \      wxPoint, wxRect, wxPen, wxBrush, wxFont, \
18      wxTRANSPARENT_PEN, wxTRANSPARENT_BRUSH, \      wxTRANSPARENT_PEN, wxTRANSPARENT_BRUSH, \
19      wxBLACK_PEN, wxRED_PEN, wxBLACK, wxSOLID, wxCROSS_HATCH, wxSWISS, wxNORMAL      wxBLACK_PEN, wxRED_PEN, wxBLACK, \
20        wxSOLID, wxCROSS_HATCH, wxSWISS, wxNORMAL, \
21        wxBitmap, wxImageFromBitmap, wxBitmapFromImage, \
22        wxImageFromStream, wxBITMAP_TYPE_BMP
23    
24  from wxproj import draw_polygon_shape, draw_polygon_init  from wxproj import draw_polygon_shape, draw_polygon_init
25    from gdalwarp import ProjectRasterFile
26    
27  from Thuban.UI.common import Color2wxColour  from Thuban.UI.common import Color2wxColour
28  from Thuban.UI.classifier import ClassDataPreviewer  from Thuban.UI.classifier import ClassDataPreviewer
29  from Thuban.UI.scalebar import ScaleBar  from Thuban.UI.scalebar import ScaleBar
30    
31  from Thuban.Model.layer import SHAPETYPE_POLYGON, SHAPETYPE_ARC, \  from Thuban.Model.layer import Layer, RasterLayer, \
32       SHAPETYPE_POINT       SHAPETYPE_POLYGON, SHAPETYPE_ARC, SHAPETYPE_POINT
33  from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \  from Thuban.Model.label import ALIGN_CENTER, ALIGN_TOP, ALIGN_BOTTOM, \
34       ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE       ALIGN_LEFT, ALIGN_RIGHT, ALIGN_BASELINE
35    
# Line 64  class MapRenderer: Line 70  class MapRenderer:
70    
71      def render_map(self, map):      def render_map(self, map):
72          self.map = map          self.map = map
73            seenRaster = True
74    
75            if self.scale == 0:
76                return
77    
78            #
79            # This is only a good optimization if there is only one
80            # raster layer and the image covers the entire window (as
81            # it currently does).
82            #
83            for layer in map.Layers():
84                if isinstance(layer, RasterLayer):
85                    seenRaster = False
86                    break
87    
88          for layer in map.Layers():          for layer in map.Layers():
89              # if honor_visibility is true, only draw visible layers,              # if honor_visibility is true, only draw visible layers,
90              # otherwise draw all layers              # otherwise draw all layers
91              if not self.honor_visibility or layer.Visible():              if not self.honor_visibility or layer.Visible():
92                  self.draw_shape_layer(layer)                  if isinstance(layer, Layer) and seenRaster:
93                        self.draw_shape_layer(layer)
94                    elif isinstance(layer, RasterLayer):
95                        self.draw_raster_layer(layer)
96                        seenRaster = True
97    
98          self.draw_label_layer(map.LabelLayer())          self.draw_label_layer(map.LabelLayer())
99    
100      def draw_shape_layer(self, layer):      def draw_shape_layer(self, layer):
# Line 149  class MapRenderer: Line 175  class MapRenderer:
175    
176              draw_func(i)              draw_func(i)
177    
178        def draw_raster_layer(self, layer):
179            data = None
180            offx, offy = self.offset
181            width, height = self.dc.GetSizeTuple()
182    
183            inProj = ""
184            proj = layer.GetProjection()
185            if proj is not None:
186                for p in proj.GetAllParameters():
187                    inProj += "+" + p + " "
188    
189            outProj = ""
190            proj = self.map.GetProjection()
191            if proj is not None:
192                for p in proj.GetAllParameters():
193                    outProj += "+" + p + " "
194    
195            xmin = (0 - offx) / self.scale
196            ymin = (offy - height) / self.scale
197            xmax = (width - offx) / self.scale
198            ymax = (offy - 0) / self.scale
199    
200            try:
201                data = ProjectRasterFile(
202                    layer.GetImageFilename(),
203                    inProj,
204                    outProj,
205                    str(xmin), str(ymin), str(xmax), str(ymax),
206                    "", str(width), str(height));
207            except IOError, (strerr):
208                print strerr
209            except (AttributeError, ValueError):
210                pass
211            else:
212                if data is not None:
213                    stream = cStringIO.StringIO(data)
214                    image = wxImageFromStream(stream, wxBITMAP_TYPE_BMP)
215                    bitmap = wxBitmapFromImage(image)
216                    self.dc.BeginDrawing()
217                    self.dc.DrawBitmap(bitmap, 0, 0)
218                    self.dc.EndDrawing()
219    
220      def layer_ids(self, layer):      def layer_ids(self, layer):
221          """Return the shape ids of the given layer that have to be drawn.          """Return the shape ids of the given layer that have to be drawn.
222    

Legend:
Removed from v.909  
changed lines
  Added in v.965

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26