silke: thuban/Thuban/Model layer.py,1.58,1.59

cvs@intevation.de cvs at intevation.de
Fri Aug 20 18:59:23 CEST 2004


Author: silke

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

Modified Files:
	layer.py 
Log Message:
Fix bug in projection handling of layers

Index: layer.py
===================================================================
RCS file: /thubanrepository/thuban/Thuban/Model/layer.py,v
retrieving revision 1.58
retrieving revision 1.59
diff -u -d -r1.58 -r1.59
--- layer.py	3 Jun 2004 15:17:54 -0000	1.58
+++ layer.py	20 Aug 2004 16:59:21 -0000	1.59
@@ -2,6 +2,7 @@
 # Authors:
 # Bernhard Herzog <bh at intevation.de>
 # Jonathan Coles <jonathan at intevation.de>
+# Silke Reimer <silke at intevation.de>
 #
 # This program is free software under the GPL (>=v2)
 # Read the file COPYING coming with Thuban for details.
@@ -226,7 +227,11 @@
         form (minx, miny, maxx, maxy) in unprojected coordinates.
         """
         if self.projection is not None:
-            bbox = self.projection.ForwardBBox(bbox)
+            # Ensure that region lies within the layer's bounding box
+            # Otherwise projection of the region would lead to incorrect
+            # values.
+            clipbbox = self.ClipBoundingBox(bbox)
+            bbox = self.projection.ForwardBBox(clipbbox)
         return self.store.ShapesInRegion(bbox)
 
     def GetClassificationColumn(self):
@@ -301,6 +306,29 @@
         items.append(self.__classification)
 
         return (_("Layer '%s'") % self.Title(), items)
+
+    def ClipBoundingBox(self, bbox):
+        """ Clip bbox to layer's bounding box.
+
+        Returns that part of bbox that lies within the layers bounding box.
+        If bbox is completely outside of the layers bounding box, bbox is
+        returned.  It is assumed that bbox has sensible values, i.e. bminx
+        < bmaxx and bminy < bmaxy.
+        """
+        bminx, bminy, bmaxx, bmaxy = bbox
+        lminx, lminy, lmaxx, lmaxy = self.LatLongBoundingBox()
+        if bminx > lmaxx or bmaxx < lminx:
+            left, right = bminx, bmaxx
+        else:
+            left = max(lminx, bminx)
+            right = min(lmaxx, bmaxx)
+        if bminy > lmaxy or bmaxy < lminy:
+            bottom, top = bminy, bmaxy
+        else:
+            bottom = max(lminy, bminy)
+            top = min(lmaxy, bmaxy)
+        
+        return (left, bottom, right, top)
 
 
 if resource.has_gdal_support():





More information about the Thuban-devel mailing list

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