jonathan: thuban/Thuban/UI baserenderer.py, 1.17, 1.18 renderer.py, 1.57, 1.58
cvs@intevation.de
cvs at intevation.de
Fri Feb 18 15:54:19 CET 2005
Author: jonathan
Update of /thubanrepository/thuban/Thuban/UI
In directory doto:/tmp/cvs-serv11859/Thuban/UI
Modified Files:
baserenderer.py renderer.py
Log Message:
Refactored baserenderer.py and renderer.py to remove baserenderer.py's
dependencies on wxPython. Added a new method projected_raster_layer()
that returns a raster layer image in projected space. This must be
implemented in classes derived from BaseRenderer. This also eliminates
the dependency on gdal in baserenderer.py.
Index: baserenderer.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/UI/baserenderer.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -d -r1.17 -r1.18
--- baserenderer.py 16 Feb 2005 21:14:47 -0000 1.17
+++ baserenderer.py 18 Feb 2005 14:54:17 -0000 1.18
@@ -30,8 +30,6 @@
import Thuban.Model.resource
-if Thuban.Model.resource.has_gdal_support():
- from gdalwarp import ProjectRasterFile
#
@@ -192,8 +190,7 @@
if isinstance(layer, Layer):
for i in self.draw_shape_layer_incrementally(layer):
yield True
- elif isinstance(layer, RasterLayer) \
- and Thuban.Model.resource.has_gdal_support():
+ elif isinstance(layer, RasterLayer):
self.draw_raster_layer(layer)
yield True
else:
@@ -443,10 +440,10 @@
def draw_raster_layer(self, layer):
"""Draw the raster layer
- This implementation does the projection and scaling of the data
- as required by the layer's and map's projections and the scale
- and offset of the renderer and then hands the transformed data
- to self.draw_raster_data() which has to be implemented in
+ This implementation uses self.projected_raster_layer() to project
+ and scale the data as required by the layer's and map's projections
+ and the scale and offset of the renderer and then hands the transformed
+ data to self.draw_raster_data() which has to be implemented in
derived classes.
"""
offx, offy = self.offset
@@ -483,24 +480,47 @@
width = int(min(width, round(fmax[0] - fmin[0] + 1)))
height = int(min(height, round(fmax[1] - fmin[1] + 1)))
- try:
- options = 0
- options = options | layer.MaskType()
-
- project_params = (layer.GetImageFilename(), in_proj, out_proj,
- (xmin, ymin, xmax, ymax), "", (width, height),
- options)
+ options = 0
+ options = options | layer.MaskType()
- data = (width, height, apply(ProjectRasterFile, project_params))
+ img_data = self.projected_raster_layer(layer, in_proj, out_proj,
+ (xmin,ymin,xmax,ymax), [0,0], (width, height), options)
- except (MemoryError, IOError, AttributeError, ValueError):
- # Why does this catch AttributeError and ValueError?
- # FIXME: The exception should be communicated to the user
- # better.
- traceback.print_exc()
- else:
+ if img_data is not None:
+ data = (width, height, img_data)
self.draw_raster_data(fmin[0]+offx, offy-fmax[1], data, "RAW")
data = None
+
+ def projected_raster_layer(self, layer, srcProj, dstProj, extents,
+ resolution, dimensions, options):
+ """Return the projected raster image associated with the layer.
+
+ The returned value will be a tuple of the form
+
+ (image_data, mask_data, alpha_data)
+
+ suitable for the data parameter to draw_raster_data.
+
+ The return value may be None if raster projections are not supported.
+
+ srcProj -- a string describing the source projection
+ dstProj -- a string describing the destination projection
+ extents -- a tuple of the region to project in map coordinates
+ resolution -- (currently not used, defaults to [0,0])
+ dimensions -- a tuple (width, height) for the output image
+ options -- bit-wise options to pass to the renderer
+
+ the currently supported values for options are
+
+ OPTS_MASK = 1 -- generate a mask
+ OPTS_ALPHA = 2 -- generate an alpha channel
+ OPTS_INVERT_MASK = 4 -- invert the values in the mask
+ (if generated)
+
+ This method has to be implemented by derived classes.
+ """
+
+ raise NotImplementedError
def draw_raster_data(self, x, y, data, format="BMP"):
"""Draw the raster image in data onto the DC with the top
Index: renderer.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/UI/renderer.py,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -d -r1.57 -r1.58
--- renderer.py 16 Feb 2005 21:14:47 -0000 1.57
+++ renderer.py 18 Feb 2005 14:54:17 -0000 1.58
@@ -45,6 +45,9 @@
from Thuban.version import versions
+if Thuban.Model.resource.has_gdal_support():
+ from gdalwarp import ProjectRasterFile
+
# Map the strings used for the format parameter of the draw_raster_data
# method to the appropriate wxWindows constants
@@ -107,6 +110,30 @@
def label_font(self):
return wxFont(int(round(self.resolution * 10)), wxSWISS, wxNORMAL,
wxNORMAL)
+
+ def projected_raster_layer(self, layer, srcProj, dstProj, extents,
+ resolution, dimensions, options):
+
+ ret = None
+
+ if Thuban.Model.resource.has_gdal_support():
+
+ if versions['wxPython-tuple'] < (2,5,3):
+ options = options | 4 # INVERT_MASK_BITS
+ options = options & ~2 # ALPHA_MASK not supported
+
+ try:
+ ret = ProjectRasterFile(layer.GetImageFilename(),
+ srcProj, dstProj,
+ extents, resolution, dimensions,
+ options)
+ except (MemoryError, IOError, AttributeError, ValueError):
+ # Why does this catch AttributeError and ValueError?
+ # FIXME: The exception should be communicated to the user
+ # better.
+ traceback.print_exc()
+
+ return ret
def draw_raster_data(self, x,y, data, format = 'BMP'):
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)