nhueffme: thuban/Extensions/ogr/test test_OGRShapestore.py, 1.5, 1.6
cvs@intevation.de
cvs at intevation.de
Fri Mar 4 16:08:01 CET 2005
Author: nhueffme
Update of /thubanrepository/thuban/Extensions/ogr/test
In directory doto:/tmp/cvs-serv30928/Extensions/ogr/test
Modified Files:
test_OGRShapestore.py
Log Message:
Latest changes on OGR extension.
Added another menu item to open OGR datasource, handling of geometry collections
possible.
Index: test_OGRShapestore.py
===================================================================
RCS file: /thubanrepository/thuban/Extensions/ogr/test/test_OGRShapestore.py,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- test_OGRShapestore.py 8 Feb 2005 09:52:56 -0000 1.5
+++ test_OGRShapestore.py 4 Mar 2005 15:07:59 -0000 1.6
@@ -35,7 +35,7 @@
support.initthuban()
from Extensions.ogr.ogrshapes import OGRShapeStore, OGRShape, \
- SHAPETYPE_ARC
+ SHAPETYPE_POINT, SHAPETYPE_ARC, SHAPETYPE_POLYGON
from Thuban.Model.data import RAW_PYTHON
from Thuban.Model.table import FIELDTYPE_INT
from Thuban.Model.session import Session
@@ -45,75 +45,136 @@
if ogr is None:
raise support.SkipTest("Can't run ogr tests because ogr couldn't be imported.")
-class TestOGRShapeStore(unittest.TestCase, support.FloatComparisonMixin):
+class TestOGRShapeStore_shp(unittest.TestCase, support.FloatComparisonMixin):
def setUp(self):
- """Initialize self.session and open shapefile, if ogr could be
+ """Initialize self.session and open shapefile, if ogr could be
imported.
"""
skip_if_no_ogr()
- self.filename = os.path.join("..", "Data", "iceland","roads-line.shp")
- self.store = OGRShapeStore(self.filename, "roads-line")
+ self.session = Session("TestSession")
+ self.filename_arc = os.path.join("..", "Data", "iceland",
+ "roads-line.shp")
+ self.store_arc = OGRShapeStore(self.session, self.filename_arc,
+ "roads-line")
+
+ self.filename_point = os.path.join("..", "Data", "iceland",
+ "cultural_landmark-point.shp")
+ self.store_point = OGRShapeStore(self.session, self.filename_point,
+ "cultural_landmark-point")
+
+ self.filename_poly = os.path.join("..", "Data", "iceland",
+ "political.shp")
+ self.store_poly = OGRShapeStore(self.session, self.filename_poly,
+ "political")
def tearDown(self):
"""Call self.session.Destroy() and reset self.session to None"""
- self.store = None
+ self.session = None
+ self.store_arc = None
+ self.store_point = None
+ self.store_poly = None
def test_shape_type(self):
"""Test OGRShapeStore.ShapeType() with arc shapes"""
- self.assertEquals(self.store.ShapeType(), SHAPETYPE_ARC)
+ self.assertEquals(self.store_arc.ShapeType(), SHAPETYPE_ARC)
+ self.assertEquals(self.store_point.ShapeType(), SHAPETYPE_POINT)
+ self.assertEquals(self.store_poly.ShapeType(), SHAPETYPE_POLYGON)
def test_raw_format(self):
"""Test OGRShapeStore.RawShapeFormat() with ogr file"""
- self.assertEquals(self.store.RawShapeFormat(), RAW_PYTHON)
+ self.assertEquals(self.store_arc.RawShapeFormat(), RAW_PYTHON)
+ self.assertEquals(self.store_point.RawShapeFormat(), RAW_PYTHON)
+ self.assertEquals(self.store_poly.RawShapeFormat(), RAW_PYTHON)
def test_boundingbox(self):
"""Test OGRShapeStore.BoundingBox() with arc shapes"""
- self.assertFloatSeqEqual(self.store.BoundingBox(),
+ self.assertFloatSeqEqual(self.store_arc.BoundingBox(),
[-24.450359344482422, 63.426830291748047,
-13.55668830871582, 66.520111083984375])
+ self.assertFloatSeqEqual(self.store_point.BoundingBox(),
+ [-23.806047439575195, 63.405960083007812,
+ -15.12291431427002, 66.36572265625])
+ self.assertFloatSeqEqual(self.store_poly.BoundingBox(),
+ [-24.546524047851562, 63.286754608154297,
+ -13.495815277099609, 66.563774108886719])
def test_num_shapes(self):
"""Test OGRShapeStore.NumShapes() with arc shapes"""
- self.assertEquals(self.store.NumShapes(), 839)
+ self.assertEquals(self.store_arc.NumShapes(), 839)
+ self.assertEquals(self.store_point.NumShapes(), 34)
+ self.assertEquals(self.store_poly.NumShapes(), 156)
def test_shapes_in_region(self):
"""Test OGRShapeStore.ShapesInRegion() with arc shapes"""
- shapes = self.store.ShapesInRegion((-22.78, 63.96, -22.72, 64.0))
- self.assertEquals([s.ShapeID() for s in shapes], [769, 771])
+ shapes_arc = self.store_arc.ShapesInRegion((-22.78, 63.96,
+ -22.72, 64.0))
+ self.assertEquals([s.ShapeID() for s in shapes_arc], [769, 771])
+
+ shapes_point = self.store_point.ShapesInRegion((-23.0, 63.0,
+ -22.0, 64.0))
+ self.assertEquals([s.ShapeID() for s in shapes_point], [29, 31])
+
+ shapes_poly = self.store_poly.ShapesInRegion((-23.0, 63.0, -22.0, 64.0))
+ self.assertEquals([s.ShapeID() for s in shapes_poly], [144])
def test_all_shapes(self):
"""Test OGRShapeStore.AllShapes()"""
- self.assertEquals([s.ShapeID() for s in self.store.AllShapes()],
- range(self.store.NumShapes()))
+ self.assertEquals([s.ShapeID() for s in self.store_arc.AllShapes()],
+ range(self.store_arc.NumShapes()))
+ self.assertEquals([s.ShapeID() for s in self.store_point.AllShapes()],
+ range(self.store_point.NumShapes()))
+ self.assertEquals([s.ShapeID() for s in self.store_poly.AllShapes()],
+ range(self.store_poly.NumShapes()))
def test_shape_Points(self):
"""Test OGRShapeStore.Shape() with arc shapes"""
- self.assertPointListEquals(self.store.Shape(32).Points(),
+ self.assertPointListEquals(self.store_arc.Shape(32).Points(),
[[(-15.08217430114746, 66.2773818969726),
(-15.02635002136230, 66.2733917236328)]])
+ self.assertPointListEquals(self.store_point.Shape(13).Points(),
+ [[(-15.364621162414551, 65.6103515625)]])
+ self.assertPointListEquals(self.store_poly.Shape(20).Points(),
+ [[(-22.233562469482422, 64.4395751953125),
+ (-22.244234085083008, 64.441192626953125),
+ (-22.233894348144531, 64.446701049804688),
+ (-22.226711273193359, 64.44439697265625),
+ (-22.23356246948242, 64.4395751953125)]])
def test_shape_shapeid(self):
"""Test OGRShapeStore.Shape(i).ShapeID()"""
- self.assertEquals(self.store.Shape(5).ShapeID(), 5)
+ self.assertEquals(self.store_arc.Shape(5).ShapeID(), 5)
+ self.assertEquals(self.store_point.Shape(13).ShapeID(), 13)
+ self.assertEquals(self.store_point.Shape(20).ShapeID(), 20)
def test_shape_compute_bbox(self):
"""Test bbox of one shape"""
- self.assertFloatSeqEqual(self.store.Shape(32).compute_bbox(),
+ self.assertFloatSeqEqual(self.store_arc.Shape(32).compute_bbox(),
(-15.08217430114746, 66.2733917236328,
-15.02635002136230, 66.2773818969726))
+ self.assertFloatSeqEqual(self.store_point.Shape(13).compute_bbox(),
+ (-15.364621162414551, 65.6103515625,
+ -15.364621162414551, 65.6103515625))
+ self.assertFloatSeqEqual(self.store_poly.Shape(20).compute_bbox(),
+ (-22.244234085083008, 64.4395751953125,
+ -22.226711273193359, 64.446701049804688))
class TestOGRTable(unittest.TestCase, support.FloatComparisonMixin):
def setUp(self):
"""Initialize"""
+ self.session = Session("TestSession")
self.filename = os.path.join("..","Data", "iceland","roads-line.shp")
- self.store = OGRShapeStore(self.filename, "roads-line")
- self.table = self.store.Table()
+ self.store_arc = OGRShapeStore(self.session, self.filename,
+ "roads-line")
+ self.table = self.store_arc.Table()
def tearDown(self):
"""Call self.session.Destroy() and reset self.session to None"""
+ self.session = None
+ self.store_arc = None
+ self.table = None
def test_Dependencies(self):
"""Test dependencies, which is always ()"""
More information about the Thuban-devel
mailing list
This site is hosted by Intevation GmbH (Datenschutzerklärung und Impressum | Privacy Policy and Imprint)