23 |
import dbflib |
import dbflib |
24 |
|
|
25 |
from Thuban.Model.session import Session |
from Thuban.Model.session import Session |
26 |
from Thuban.Model.layer import Layer, SHAPETYPE_POLYGON, SHAPETYPE_ARC, \ |
from Thuban.Model.layer import BaseLayer, Layer, RasterLayer, \ |
27 |
SHAPETYPE_POINT |
SHAPETYPE_POLYGON, SHAPETYPE_ARC, SHAPETYPE_POINT |
28 |
from Thuban.Model.messages import LAYER_LEGEND_CHANGED, \ |
from Thuban.Model.messages import LAYER_LEGEND_CHANGED, \ |
29 |
LAYER_VISIBILITY_CHANGED |
LAYER_VISIBILITY_CHANGED |
30 |
from Thuban.Model.color import Color |
from Thuban.Model.color import Color |
31 |
from Thuban.Model.table import FIELDTYPE_DOUBLE |
from Thuban.Model.table import FIELDTYPE_DOUBLE |
32 |
|
from Thuban.Model.proj import Projection |
33 |
|
|
34 |
class TestLayer(unittest.TestCase, support.FileTestMixin, |
class TestLayer(unittest.TestCase, support.FileTestMixin, |
35 |
support.FloatComparisonMixin): |
support.FloatComparisonMixin): |
48 |
def tearDown(self): |
def tearDown(self): |
49 |
self.session = None |
self.session = None |
50 |
|
|
51 |
|
def build_path(self, filename): |
52 |
|
return os.path.join("..", "Data", "iceland", filename) |
53 |
|
|
54 |
def open_shapefile(self, filename): |
def open_shapefile(self, filename): |
55 |
"""Open and return a shapestore for filename in the iceland data set""" |
"""Open and return a shapestore for filename in the iceland data set""" |
56 |
return self.session.OpenShapefile(os.path.join("..", "Data", "iceland", |
return self.session.OpenShapefile(self.build_path(filename)) |
57 |
filename)) |
|
58 |
|
def test_base_layer(self): |
59 |
|
layer = BaseLayer("Test BaseLayer") |
60 |
|
self.assertEquals(layer.Title(), "Test BaseLayer") |
61 |
|
self.failUnless(layer.Visible()) |
62 |
|
|
63 |
|
# toggle visibility |
64 |
|
layer.SetVisible(False) |
65 |
|
self.failIf(layer.Visible()) |
66 |
|
|
67 |
|
layer.SetVisible(True) |
68 |
|
self.failUnless(layer.Visible()) |
69 |
|
|
70 |
|
self.failIf(layer.HasClassification()) |
71 |
|
self.assertEquals(layer.GetProjection(), None) |
72 |
|
|
73 |
|
# set/get projection |
74 |
|
proj = Projection(["proj=utm", "zone=26"]) |
75 |
|
|
76 |
|
layer.SetProjection(proj) |
77 |
|
self.failUnless(layer.GetProjection() is proj) |
78 |
|
|
79 |
|
# __init__ with other arguments |
80 |
|
layer = BaseLayer("Test BaseLayer", False, proj) |
81 |
|
self.failIf(layer.Visible()) |
82 |
|
self.failUnless(layer.GetProjection() is proj) |
83 |
|
|
84 |
def test_arc_layer(self): |
def test_arc_layer(self): |
85 |
"""Test Layer with arc shapes""" |
"""Test Layer with arc shapes""" |
86 |
layer = Layer("Test Layer", self.open_shapefile("roads-line.shp")) |
layer = Layer("Test Layer", self.open_shapefile("roads-line.shp")) |
|
self.assertEquals(layer.Title(), "Test Layer") |
|
87 |
self.assertEquals(layer.ShapeType(), SHAPETYPE_ARC) |
self.assertEquals(layer.ShapeType(), SHAPETYPE_ARC) |
88 |
self.assertEquals(layer.NumShapes(), 839) |
self.assertEquals(layer.NumShapes(), 839) |
89 |
shape = layer.Shape(32) |
shape = layer.Shape(32) |
119 |
def test_polygon_layer(self): |
def test_polygon_layer(self): |
120 |
"""Test Layer with polygon shapes""" |
"""Test Layer with polygon shapes""" |
121 |
layer = Layer("Test Layer", self.open_shapefile("political.shp")) |
layer = Layer("Test Layer", self.open_shapefile("political.shp")) |
|
self.assertEquals(layer.Title(), "Test Layer") |
|
122 |
self.assertEquals(layer.ShapeType(), SHAPETYPE_POLYGON) |
self.assertEquals(layer.ShapeType(), SHAPETYPE_POLYGON) |
123 |
self.assertEquals(layer.NumShapes(), 156) |
self.assertEquals(layer.NumShapes(), 156) |
124 |
shape = layer.Shape(4) |
shape = layer.Shape(4) |
138 |
"""Test Layer with point shapes""" |
"""Test Layer with point shapes""" |
139 |
layer = Layer("Test Layer", |
layer = Layer("Test Layer", |
140 |
self.open_shapefile("cultural_landmark-point.shp")) |
self.open_shapefile("cultural_landmark-point.shp")) |
|
self.assertEquals(layer.Title(), "Test Layer") |
|
141 |
self.assertEquals(layer.ShapeType(), SHAPETYPE_POINT) |
self.assertEquals(layer.ShapeType(), SHAPETYPE_POINT) |
142 |
self.assertEquals(layer.NumShapes(), 34) |
self.assertEquals(layer.NumShapes(), 34) |
143 |
shape = layer.Shape(0) |
shape = layer.Shape(0) |
177 |
self.assertEquals(layer.GetFieldType("non existing"), None) |
self.assertEquals(layer.GetFieldType("non existing"), None) |
178 |
layer.Destroy() |
layer.Destroy() |
179 |
|
|
180 |
|
def test_raster_layer(self): |
181 |
|
filename = self.build_path("island.tif") |
182 |
|
layer = RasterLayer("Test RasterLayer", filename) |
183 |
|
self.assertEquals(layer.GetImageFilename(), filename) |
184 |
|
self.assertFloatSeqEqual(layer.BoundingBox(), |
185 |
|
[-24.5500000, 63.2833330, |
186 |
|
-13.4916670, 66.5666670]) |
187 |
|
self.assertFloatSeqEqual(layer.LatLongBoundingBox(), |
188 |
|
[-24.5500000, 63.2833330, |
189 |
|
-13.4916670, 66.5666670]) |
190 |
|
|
191 |
|
|
192 |
class TestLayerLegend(unittest.TestCase, support.SubscriberMixin): |
class TestLayerLegend(unittest.TestCase, support.SubscriberMixin): |
193 |
|
|