jonathan: thuban/Thuban/Model layer.py, 1.60, 1.61 load.py, 1.52, 1.53 save.py, 1.41, 1.42

cvs@intevation.de cvs at intevation.de
Thu Jan 27 15:19:43 CET 2005


Author: jonathan

Update of /thubanrepository/thuban/Thuban/Model
In directory doto:/tmp/cvs-serv16876/Thuban/Model

Modified Files:
	layer.py load.py save.py 
Log Message:
Add a new dialog box for raster layers. The dialog box allows
the user to toggle a mask that is generated by ProjectRasterFile
and is used to only draw the real parts of the projected image.


Index: layer.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/Model/layer.py,v
retrieving revision 1.60
retrieving revision 1.61
diff -u -d -r1.60 -r1.61
--- layer.py	20 Sep 2004 08:13:00 -0000	1.60
+++ layer.py	27 Jan 2005 14:19:41 -0000	1.61
@@ -25,6 +25,7 @@
 
 import resource
 
+from color import Color
 
 shapetype_names = {SHAPETYPE_POINT: "Point",
                    SHAPETYPE_ARC: "Arc",
@@ -71,6 +72,9 @@
         self.projection = projection
         self.changed(LAYER_PROJECTION_CHANGED, self)
 
+    def Type(self):
+        return "Unknown"
+
 class Layer(BaseLayer):
 
     """Represent the information of one geodata file (currently a shapefile)
@@ -171,6 +175,9 @@
             bbox = self.projection.InverseBBox(bbox)
         return bbox
 
+    def Type(self):
+        return self.ShapeType();
+
     def ShapesBoundingBox(self, shapes):
         """Return a bounding box in lat/long coordinates for the given
         list of shape ids.
@@ -360,6 +367,10 @@
 
         self.bbox = -1
 
+        self.use_mask = False
+
+        self.image_info = None
+
         if resource.has_gdal_support():
             #
             # temporarily open the file so that GDAL can test if it's valid.
@@ -369,6 +380,24 @@
             if dataset is None:
                 raise IOError()
 
+            #
+            # while we have the file, extract some basic information 
+            # that we can display later
+            #
+            self.image_info = {}
+
+            self.image_info["nBands"] = dataset.RasterCount
+            self.image_info["Size"] = (dataset.RasterXSize, dataset.RasterYSize)
+            self.image_info["Driver"] = dataset.GetDriver().ShortName
+
+            # store some information about the individual bands
+            # [min_value, max_value]
+            a = self.image_info["BandData"] = []
+
+            for i in range(1, dataset.RasterCount+1):
+                band = dataset.GetRasterBand(i)
+                a.append(band.ComputeRasterMinMax())
+
         self.UnsetModified()
 
     def BoundingBox(self):
@@ -423,8 +452,27 @@
 
         return bbox
 
+    def Type(self):
+        return "Image"
+
     def GetImageFilename(self):
         return self.filename
+
+    def UseMask(self):
+        """Return True if the mask should be used when rendering the layer."""
+        return self.use_mask
+
+    def SetUseMask(self, use):
+        """Set whether to use a mask when render the image.
+
+        If the state changes, a LAYER_CHANGED message is sent.
+        """
+        if use != self.use_mask: 
+            self.use_mask = use
+            self.changed(LAYER_CHANGED, self)
+
+    def ImageInfo(self):
+        return self.image_info
 
     def TreeInfo(self):
         items = []

Index: load.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/Model/load.py,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- load.py	13 Dec 2004 17:51:11 -0000	1.52
+++ load.py	27 Jan 2005 14:19:41 -0000	1.53
@@ -508,8 +508,11 @@
         filename = os.path.join(self.GetDirectory(), filename)
         filename = self.encode(filename)
         visible  = self.encode(attrs.get((None, 'visible'), "true")) != "false"
+        useMask = self.encode(attrs.get((None, 'use_mask'), "false")) != "false"
 
         self.aLayer = layer_class(title, filename, visible = visible)
+
+        self.aLayer.SetUseMask(useMask)
 
     def end_rasterlayer(self, name, qname):
         self.aMap.AddLayer(self.aLayer)

Index: save.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/Model/save.py,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -d -r1.41 -r1.42
--- save.py	7 Oct 2004 14:24:24 -0000	1.41
+++ save.py	27 Jan 2005 14:19:41 -0000	1.42
@@ -90,6 +90,9 @@
             processed[id(container)] = 1
     return result
 
+def bool2str(b):
+    if b: return "true"
+    else: return "false"
 
 class SessionSaver(XMLWriter):
 
@@ -284,7 +287,7 @@
             attrs = {}
 
         attrs["title"]   = layer.title
-        attrs["visible"] = ("false", "true")[int(layer.Visible())]
+        attrs["visible"] = bool2str(layer.Visible())
 
         if isinstance(layer, Layer):
             attrs["shapestore"]   = self.get_id(layer.ShapeStore())
@@ -300,6 +303,9 @@
             self.close_element("layer")
         elif isinstance(layer, RasterLayer):
             attrs["filename"] = self.prepare_filename(layer.filename)
+            if layer.UseMask():
+                attrs["use_mask"] = "true"
+
             self.open_element("rasterlayer", attrs)
             self.write_projection(layer.GetProjection())
             self.close_element("rasterlayer")





More information about the Thuban-devel mailing list

This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)