1 |
# Copyright (c) 2002, 2003 by Intevation GmbH |
# Copyright (c) 2002, 2003, 2004, 2005 by Intevation GmbH |
2 |
# Authors: |
# Authors: |
3 |
# Bernhard Herzog <[email protected]> |
# Bernhard Herzog <[email protected]> |
4 |
# |
# |
33 |
from Thuban.Model.data import DerivedShapeStore |
from Thuban.Model.data import DerivedShapeStore |
34 |
from Thuban.Model.classification import Classification, ClassGroupSingleton, \ |
from Thuban.Model.classification import Classification, ClassGroupSingleton, \ |
35 |
ClassGroupRange |
ClassGroupRange |
36 |
|
from Thuban.Model.color import Color |
37 |
|
|
38 |
import Thuban.Model.resource |
import Thuban.Model.resource |
39 |
|
|
172 |
# values |
# values |
173 |
table = MemoryTable([("FOO", FIELDTYPE_STRING)], [("bla",)]) |
table = MemoryTable([("FOO", FIELDTYPE_STRING)], [("bla",)]) |
174 |
store = mockgeo.SimpleShapeStore(SHAPETYPE_ARC, |
store = mockgeo.SimpleShapeStore(SHAPETYPE_ARC, |
175 |
[[[(9884848.1401601825, 5607709.9111020016), |
[[[(9884828.7209840547, 5607720.9774499247), |
176 |
(11298371.027199602, 9287809.2948032897)]]], |
(11298336.04640449, 9287823.2044059951)]]], |
177 |
table) |
table) |
178 |
layer = self.layer = Layer("Test Layer", store) |
layer = self.layer = Layer("Test Layer", store) |
179 |
|
|
180 |
proj = Projection(["proj=lcc", "lon_0=0", "lat_1=20n", "lat_2=60n"]) |
proj = Projection(["proj=lcc", "lon_0=0", "lat_1=20n", "lat_2=60n", |
181 |
|
"ellps=clrk66"]) |
182 |
layer.SetProjection(proj) |
layer.SetProjection(proj) |
183 |
|
|
184 |
self.assertFloatSeqEqual(layer.BoundingBox(), |
self.assertFloatSeqEqual(layer.BoundingBox(), |
185 |
(9884848.1401601825, 5607709.9111020016, |
(9884828.7209840547, 5607720.9774499247, |
186 |
11298371.027199602, 9287809.2948032897)) |
11298336.04640449, 9287823.2044059951)) |
187 |
self.assertFloatSeqEqual(layer.LatLongBoundingBox(), |
self.assertFloatSeqEqual(layer.LatLongBoundingBox(), |
188 |
(90.0, -8.899852, 120, 11.16092)) |
(90.0, -8.90043373, 120, 11.1616263)) |
189 |
shapes = layer.ShapesInRegion((100, -10, 150, +10)) |
shapes = layer.ShapesInRegion((100, -10, 150, +10)) |
190 |
self.assertEquals([s.ShapeID() for s in shapes], [0]) |
self.assertEquals([s.ShapeID() for s in shapes], [0]) |
191 |
self.assertFloatSeqEqual(layer.ShapesBoundingBox([0]), |
self.assertFloatSeqEqual(layer.ShapesBoundingBox([0]), |
192 |
(90.0, -8.899852, 120, 11.16092)) |
(90.0, -8.90043373, 120, 11.1616263)) |
193 |
|
|
194 |
|
# Test a very large bounding box in the query. Naive inverse |
195 |
|
# projection will create infs instead of proper coordinate |
196 |
|
# values and a different result (an empty list instead of [0]) |
197 |
|
shapes = layer.ShapesInRegion((-180, -170, 200, +120)) |
198 |
|
self.assertEquals([s.ShapeID() for s in shapes],[0]) |
199 |
|
|
200 |
def test_empty_layer(self): |
def test_empty_layer(self): |
201 |
"""Test Layer with empty shape file""" |
"""Test Layer with empty shape file""" |
232 |
layer = RasterLayer("Test RasterLayer", filename) |
layer = RasterLayer("Test RasterLayer", filename) |
233 |
self.failIf(layer.HasClassification()) |
self.failIf(layer.HasClassification()) |
234 |
self.failIf(layer.HasShapes()) |
self.failIf(layer.HasShapes()) |
235 |
|
self.assertEquals(layer.MaskType(), layer.MASK_BIT) |
236 |
self.assertEquals(layer.GetImageFilename(), os.path.abspath(filename)) |
self.assertEquals(layer.GetImageFilename(), os.path.abspath(filename)) |
237 |
self.assertFloatSeqEqual(layer.BoundingBox(), |
self.assertFloatSeqEqual(layer.BoundingBox(), |
238 |
[-24.5500000, 63.2833330, |
[-24.5500000, 63.2833330, |
241 |
[-24.5500000, 63.2833330, |
[-24.5500000, 63.2833330, |
242 |
-13.4916670, 66.5666670]) |
-13.4916670, 66.5666670]) |
243 |
|
|
244 |
|
info = layer.ImageInfo() |
245 |
|
self.failIf(info is None) |
246 |
|
self.failUnless(info.has_key("nBands")) |
247 |
|
self.failUnless(info.has_key("Size")) |
248 |
|
self.failUnless(info.has_key("Driver")) |
249 |
|
self.failUnless(info.has_key("BandData")) |
250 |
|
|
251 |
|
self.assertEquals(info["nBands"], 1) |
252 |
|
self.assertEquals(info["Size"], (5002, 394)) |
253 |
|
self.assertEquals(info["Driver"], "GTiff") |
254 |
|
self.assertEquals(info["BandData"], [(0.0, 140.0)]) |
255 |
|
|
256 |
def test_derived_store(self): |
def test_derived_store(self): |
257 |
"""Test layer with derived store""" |
"""Test layer with derived store""" |
258 |
layer = self.layer = Layer("Test Layer", |
layer = self.layer = Layer("Test Layer", |
375 |
""" |
""" |
376 |
self.clear_messages() |
self.clear_messages() |
377 |
self.session = Session("Test session for %s" % self.__class__) |
self.session = Session("Test session for %s" % self.__class__) |
378 |
filename = os.path.join("..", "Data", "iceland", "political.shp") |
self.filename = os.path.join("..", "Data", "iceland", "political.shp") |
379 |
self.layer = Layer("Test Layer", |
self.layer = Layer("Test Layer", |
380 |
self.session.OpenShapefile(filename)) |
self.session.OpenShapefile(self.filename)) |
381 |
self.layer.Subscribe(LAYER_LEGEND_CHANGED, self.subscribe_with_params, |
self.layer.Subscribe(LAYER_LEGEND_CHANGED, self.subscribe_with_params, |
382 |
LAYER_LEGEND_CHANGED) |
LAYER_LEGEND_CHANGED) |
383 |
self.layer.Subscribe(LAYER_VISIBILITY_CHANGED, |
self.layer.Subscribe(LAYER_VISIBILITY_CHANGED, |
395 |
self.session = None |
self.session = None |
396 |
self.clear_messages() |
self.clear_messages() |
397 |
|
|
398 |
|
def build_path(self, filename): |
399 |
|
return os.path.join("..", "Data", "iceland", filename) |
400 |
|
|
401 |
def test_sanity(self): |
def test_sanity(self): |
402 |
"""TestLayerModification Sanity Checks""" |
"""TestLayerModification Sanity Checks""" |
403 |
# test default settings |
# test default settings |
439 |
self.failUnless(self.layer.WasModified()) |
self.failUnless(self.layer.WasModified()) |
440 |
|
|
441 |
|
|
442 |
# |
def test_tree_info(self): |
443 |
# the tree info now contains Color objects which are difficult to test |
"""Test Layer.TreeInfo""" |
444 |
# |
self.assertEquals(self.layer.TreeInfo(), |
445 |
# def test_tree_info(self): |
("Layer 'Test Layer'", |
446 |
# """Test Layer.TreeInfo""" |
['Filename: %s' % os.path.abspath(self.filename), |
447 |
# self.assertEquals(self.layer.TreeInfo(), |
'Shown', |
448 |
# ("Layer 'Test Layer'", |
'Shapes: 156', |
449 |
# ['Shown', |
'Extent (lat-lon): (-24.5465, 63.2868, -13.4958, 66.5638)', |
450 |
# 'Shapes: 156', |
'Shapetype: Polygon', |
451 |
# ('Extent (lat-lon):' |
self.layer.GetClassification()])) |
452 |
# ' (-24.5465, 63.2868, -13.4958, 66.5638)'), |
|
453 |
# 'Shapetype: Polygon', |
def test_raster_layer(self): |
454 |
# 'Fill: None', |
if not Thuban.Model.resource.has_gdal_support(): |
455 |
# 'Outline: (0.000, 0.000, 0.000)'])) |
raise support.SkipTest("No gdal support") |
456 |
|
|
457 |
|
|
458 |
|
filename = self.build_path("island.tif") |
459 |
|
layer = RasterLayer("Test RasterLayer", filename) |
460 |
|
|
461 |
|
layer.Subscribe(LAYER_CHANGED, self.subscribe_with_params, |
462 |
|
LAYER_CHANGED) |
463 |
|
|
464 |
|
self.assertEquals(layer.MaskType(), layer.MASK_BIT) |
465 |
|
|
466 |
|
layer.SetMaskType(layer.MASK_NONE) |
467 |
|
self.failIf(layer.MaskType() != layer.MASK_NONE) |
468 |
|
self.check_messages([(layer, LAYER_CHANGED)]) |
469 |
|
self.clear_messages() |
470 |
|
|
471 |
|
layer.SetMaskType(layer.MASK_NONE) |
472 |
|
self.failIf(layer.MaskType() != layer.MASK_NONE) |
473 |
|
self.check_messages([]) |
474 |
|
self.clear_messages() |
475 |
|
|
476 |
|
layer.SetMaskType(layer.MASK_BIT) |
477 |
|
self.failIf(layer.MaskType() != layer.MASK_BIT) |
478 |
|
self.check_messages([(layer, LAYER_CHANGED)]) |
479 |
|
self.clear_messages() |
480 |
|
|
481 |
|
layer.SetMaskType(layer.MASK_BIT) |
482 |
|
self.failIf(layer.MaskType() != layer.MASK_BIT) |
483 |
|
self.check_messages([]) |
484 |
|
self.clear_messages() |
485 |
|
|
486 |
|
layer.SetMaskType(layer.MASK_ALPHA) |
487 |
|
self.failIf(layer.MaskType() != layer.MASK_ALPHA) |
488 |
|
|
489 |
|
layer.SetOpacity(0) |
490 |
|
self.assertEquals(layer.Opacity(), 0) |
491 |
|
layer.SetOpacity(0.5) |
492 |
|
self.assertEquals(layer.Opacity(), 0.5) |
493 |
|
|
494 |
|
self.clear_messages() |
495 |
|
layer.SetOpacity(1) |
496 |
|
self.assertEquals(layer.Opacity(), 1) |
497 |
|
self.check_messages([(layer, LAYER_CHANGED)]) |
498 |
|
self.clear_messages() |
499 |
|
|
500 |
|
self.assertRaises(ValueError, layer.SetOpacity, -0.1) |
501 |
|
self.assertRaises(ValueError, layer.SetOpacity, 1.1) |
502 |
|
|
503 |
|
layer.SetMaskType(layer.MASK_NONE) |
504 |
|
self.clear_messages() |
505 |
|
self.assertEquals(layer.Opacity(), 1) |
506 |
|
self.check_messages([]) |
507 |
|
self.clear_messages() |
508 |
|
|
509 |
|
self.assertRaises(ValueError, layer.SetMaskType, -1) |
510 |
|
self.assertRaises(ValueError, layer.SetMaskType, 4) |
511 |
|
|
512 |
|
|
513 |
if __name__ == "__main__": |
if __name__ == "__main__": |