/[thuban]/branches/WIP-pyshapelib-bramz/Thuban/Model/map.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/Thuban/Model/map.py

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

revision 6 by bh, Tue Aug 28 15:41:52 2001 UTC revision 245 by bh, Mon Jul 29 13:37:55 2002 UTC
# Line 1  Line 1 
1  # Copyright (c) 2001 by Intevation GmbH  # Copyright (c) 2001, 2002 by Intevation GmbH
2  # Authors:  # Authors:
3  # Bernhard Herzog <[email protected]>  # Bernhard Herzog <[email protected]>
4  #  #
# Line 46  class Map(TitledObject, Modifiable): Line 46  class Map(TitledObject, Modifiable):
46    
47      def Destroy(self):      def Destroy(self):
48          for layer in self.layers:          for layer in self.layers:
49                self.unsubscribe_layer_channels(layer)
50              layer.Destroy()              layer.Destroy()
51            self.label_layer.Unsubscribe(CHANGED, self.forward, LAYERS_CHANGED)
52          Modifiable.Destroy(self)          Modifiable.Destroy(self)
53    
54      def AddLayer(self, layer):      def AddLayer(self, layer):
55          self.layers.append(layer)          self.layers.append(layer)
56          for channel in self.forwarded_channels:          self.subscribe_layer_channels(layer)
             layer.Subscribe(channel, self.forward, channel)  
57          self.changed(LAYERS_CHANGED, self)          self.changed(LAYERS_CHANGED, self)
58    
59      def RemoveLayer(self, layer):      def RemoveLayer(self, layer):
60          for channel in self.forwarded_channels:          self.unsubscribe_layer_channels(layer)
             layer.Unsubscribe(channel, self.forward, channel)  
61          self.layers.remove(layer)          self.layers.remove(layer)
62          self.changed(LAYERS_CHANGED, self)          self.changed(LAYERS_CHANGED, self)
63          layer.Destroy()          layer.Destroy()
64    
65        def subscribe_layer_channels(self, layer):
66            """Subscribe to some of layer's channels."""
67            for channel in self.forwarded_channels:
68                layer.Subscribe(channel, self.forward, channel)
69    
70        def unsubscribe_layer_channels(self, layer):
71            """Unsubscribe to some of layer's channels."""
72            for channel in self.forwarded_channels:
73                layer.Unsubscribe(channel, self.forward, channel)
74    
75      def LabelLayer(self):      def LabelLayer(self):
76          """Return the Map's label layer"""          """Return the Map's label layer"""
77          return self.label_layer          return self.label_layer
# Line 87  class Map(TitledObject, Modifiable): Line 97  class Map(TitledObject, Modifiable):
97          self.changed(LAYERS_CHANGED, self)          self.changed(LAYERS_CHANGED, self)
98    
99      def BoundingBox(self):      def BoundingBox(self):
100            """Return the bounding box of the map in projected coordinates.
101    
102            Return None if there are no layers or no layer contains any shapes.
103            """
104          if not self.layers:          if not self.layers:
105              return None              return None
106          llx = []          llx = []
# Line 96  class Map(TitledObject, Modifiable): Line 110  class Map(TitledObject, Modifiable):
110          for layer in self.layers:          for layer in self.layers:
111              if layer is self.label_layer:              if layer is self.label_layer:
112                  continue                  continue
113              left, bottom, right, top = layer.LatLongBoundingBox()              # the layer's bbox may be None if it doesn't have any layers
114              llx.append(left)              bbox = layer.LatLongBoundingBox()
115              lly.append(bottom)              if bbox is not None:
116              urx.append(right)                  left, bottom, right, top = bbox
117              ury.append(top)                  llx.append(left)
118          return (min(llx), min(lly), max(urx), max(ury))                  lly.append(bottom)
119                    urx.append(right)
120                    ury.append(top)
121    
122            # check whether there were any empty layers.
123            if llx:
124                return (min(llx), min(lly), max(urx), max(ury))
125            else:
126                return None
127    
128      def ProjectedBoundingBox(self):      def ProjectedBoundingBox(self):
129          # This simply returns the rectangle given by the projected          # This simply returns the rectangle given by the projected
# Line 138  class Map(TitledObject, Modifiable): Line 160  class Map(TitledObject, Modifiable):
160              layer.UnsetModified()              layer.UnsetModified()
161          self.label_layer.UnsetModified()          self.label_layer.UnsetModified()
162    
163        def TreeInfo(self):
164            items = []
165            if self.BoundingBox() != None:
166                items.append("Extent (lat-lon): (%g, %g, %g, %g)"
167                             % self.BoundingBox())
168                if self.projection and len(self.projection.params) > 0:
169                    items.append("Extent (projected): (%g, %g, %g, %g)"
170                                 % self.ProjectedBoundingBox())
171                    items.append(("Projection",
172                                  [str(param)
173                                   for param in self.projection.params]))
174    
175            layers = self.layers[:]
176            layers.reverse()
177            items.extend(layers)
178    
179            return ("Map: %s" % self.title, items)
180    

Legend:
Removed from v.6  
changed lines
  Added in v.245

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26