shapetest.py
import os, sys
import unittest
from testing import mapscript, MapTestCase
from testing import MapPrimitivesTestCase, ShapeObjTestCase
from testing import MapscriptTestCase
00043 class ShapePointTestCase(ShapeObjTestCase):
"""Test point type shapeObj in stand-alone mode"""
00046 def setUp(self):
"""The test fixture is a shape of one point"""
self.points = (mapscript.pointObj(0.0, 1.0),)
self.lines = (mapscript.lineObj(),)
self.addPointToLine(self.lines[0], self.points[0])
self.shape = mapscript.shapeObj(mapscript.MS_SHAPE_POINT)
self.addLineToShape(self.shape, self.lines[0])
00054 def testCreateShape(self):
"""the number of lines is correct"""
assert self.shape.numlines == 1
00058 def testShapeClone(self):
"""test shape can be copied"""
s = self.shape.clone()
self.assertShapesEqual(self.shape, s)
00063 class InlineFeatureTestCase(MapTestCase):
"""tests for issue http://mapserver.gis.umn.edu/bugs/show_bug.cgi?id=562"""
00066 def testAddPointFeature(self):
"""adding a point to an inline feature works correctly"""
inline_layer = self.map.getLayerByName('INLINE')
assert inline_layer.connectiontype == mapscript.MS_INLINE
p = mapscript.pointObj(0.2, 51.5)
l = mapscript.lineObj()
self.addPointToLine(l, p)
shape = mapscript.shapeObj(inline_layer.type)
shape.classindex = 0
self.addLineToShape(shape, l)
inline_layer.addFeature(shape)
msimg = self.map.draw()
filename = 'testAddPointFeature.png'
msimg.save(filename)
00081 def testGetShape(self):
"""returning the shape from an inline feature works"""
inline_layer = self.map.getLayerByName('INLINE')
inline_layer.open()
s = inline_layer.getFeature(0)
l = self.getLineFromShape(s, 0)
p = self.getPointFromLine(l, 0)
self.assertAlmostEqual(p.x, -0.2)
self.assertAlmostEqual(p.y, 51.5)
00091 def testGetNumFeatures(self):
"""the number of features in the inline layer is correct"""
inline_layer = self.map.getLayerByName('INLINE')
assert inline_layer.getNumFeatures() == 1
class ShapeValuesTestCase(unittest.TestCase):
def testNullValue(self):
so = mapscript.shapeObj(mapscript.MS_SHAPE_POINT)
assert so.numvalues == 0
assert so.getValue(0) == None
def testSetValue(self):
so = mapscript.shapeObj(mapscript.MS_SHAPE_POINT)
so.initValues(4)
so.setValue(0, 'Foo');
assert so.numvalues == 4
assert so.getValue(0) == 'Foo'
assert so.getValue(1) == ''
class ShapeWKTTestCase(unittest.TestCase):
point_xy = (-105.5000000000000000, 40.0000000000000000)
point_wkt = 'POINT (-105.5000000000000000 40.0000000000000000)'
def testSetPointWKT(self):
so = mapscript.shapeObj.fromWKT(self.point_wkt)
self.assert_(so.numlines == 1, so.numlines)
self.assert_(so.get(0).numpoints == 1, so.get(0).numpoints)
po = so.get(0).get(0)
self.assertAlmostEqual(po.x, self.point_xy[0])
self.assertAlmostEqual(po.y, self.point_xy[1])
def testGetPointWKT(self):
po = mapscript.pointObj(self.point_xy[0], self.point_xy[1])
lo = mapscript.lineObj()
lo.add(po)
so = mapscript.shapeObj(mapscript.MS_SHAPE_POINT)
so.add(lo)
wkt = so.toWKT()
self.assert_(wkt == self.point_wkt, wkt)
if __name__ == '__main__':
unittest.main()