def testGeometryCollection(self): self.assertRaises(TypeError, geometry.GeometryCollection) self.assertRaises(TypeError, geometry.GeometryCollection, None) p = geometry.Polygon([(0, 0), (1, 1), (1, 0), (0, 0)]) e = [(0, 0), (0, 2), (2, 2), (2, 0), (0, 0)] i = [(1, 0), (0.5, 0.5), (1, 1), (1.5, 0.5), (1, 0)] ph = geometry.Polygon(e, [i]) p0 = geometry.Point(0, 0) p1 = geometry.Point(-1, -1) r = geometry.LinearRing([(0, 0), (1, 1), (1, 0), (0, 0)]) l = geometry.LineString([(0, 0), (1, 1)]) gc = geometry.GeometryCollection([p, ph, p0, p1, r, l]) self.assertEqual(len(list(gc.geoms)), 6) self.assertEqual(len(gc), 6) self.assertEqual(gc.bounds, (-1.0, -1.0, 2.0, 2.0)) self.assertEqual(gc.__geo_interface__, geometry.as_shape(gc).__geo_interface__) self.assertEqual( gc.__geo_interface__, geometry.as_shape(gc.__geo_interface__).__geo_interface__) f = geometry._Feature() gc1 = geometry.GeometryCollection( [p.__geo_interface__, ph, p0, p1, r, l.__geo_interface__]) self.assertEqual(gc.__geo_interface__, gc1.__geo_interface__) self.assertRaises(NotImplementedError, geometry.GeometryCollection, [p, f]) mp1 = geometry.MultiPoint([p0, p1]) self.assertRaises(ValueError, geometry.GeometryCollection, [p, mp1])
def testGeometryCollection(self): self.assertRaises(TypeError,geometry.GeometryCollection) self.assertRaises(TypeError,geometry.GeometryCollection, None) p = geometry.Polygon([(0, 0), (1, 1), (1, 0), (0, 0)]) e = [(0, 0), (0, 2), (2, 2), (2, 0), (0, 0)] i = [(1, 0), (0.5, 0.5), (1, 1), (1.5, 0.5), (1, 0)] ph = geometry.Polygon(e, [i]) p0 = geometry.Point(0, 0) p1 = geometry.Point(-1, -1) r = geometry.LinearRing([(0, 0), (1, 1), (1, 0), (0, 0)]) l = geometry.LineString([(0, 0), (1, 1)]) gc = geometry.GeometryCollection([p,ph,p0,p1,r,l]) self.assertEqual(len(list(gc.geoms)),6) self.assertEqual(len(gc), 6) self.assertEqual(gc.bounds, (-1.0, -1.0, 2.0, 2.0)) self.assertEqual(gc.__geo_interface__, geometry.as_shape(gc).__geo_interface__) self.assertEqual(gc.__geo_interface__, geometry.as_shape(gc.__geo_interface__).__geo_interface__) f = geometry._Feature() gc1 = geometry.GeometryCollection([p.__geo_interface__,ph,p0,p1,r,l.__geo_interface__]) self.assertEqual(gc.__geo_interface__,gc1.__geo_interface__) self.assertRaises(NotImplementedError, geometry.GeometryCollection, [p,f]) mp1 = geometry.MultiPoint([p0, p1]) self.assertRaises(ValueError, geometry.GeometryCollection, [p,mp1])
def testPoint(self): self.assertRaises(ValueError, geometry.Point) p = geometry.Point(0, 1) self.assertEqual(p.bounds, (0.0, 1.0, 0.0, 1.0)) self.assertEqual(p.x, 0.0) self.assertEqual(p.y, 1.0) self.assertEqual(p.__geo_interface__, { 'type': 'Point', 'coordinates': (0.0, 1.0) }) self.assertRaises(ValueError, lambda: p.z) self.assertEqual(p.coords[0], (0.0, 1.0)) p1 = geometry.Point(0, 1, 2) self.assertEqual(p1.x, 0.0) self.assertEqual(p1.y, 1.0) self.assertEqual(p1.z, 2.0) self.assertEqual(p1.coords[0], (0.0, 1.0, 2.0)) self.assertEqual(p1.__geo_interface__, { 'type': 'Point', 'coordinates': (0.0, 1.0, 2.0) }) p2 = geometry.Point([0, 1]) self.assertEqual(p2.x, 0.0) self.assertEqual(p2.y, 1.0) p3 = geometry.Point([0, 1, 2]) self.assertEqual(p3.x, 0.0) self.assertEqual(p3.y, 1.0) self.assertEqual(p3.z, 2.0) p4 = geometry.Point(p) self.assertEqual(p4.x, 0.0) self.assertEqual(p4.y, 1.0) p5 = geometry.Point(p1) self.assertEqual(p5.x, 0.0) self.assertEqual(p5.y, 1.0) self.assertEqual(p5.z, 2.0) self.assertRaises(TypeError, geometry.Point, '1.0, 2.0') self.assertRaises(ValueError, geometry.Point, '1.0', 'a') self.assertRaises(TypeError, geometry.Point, (0, 1, 2, 3, 4)) #you may also pass string values as internally they get converted #into floats, but this is not recommended p6 = geometry.Point('0', '1') self.assertEqual(p.__geo_interface__, p6.__geo_interface__) p6.coords = [0, 1, 2] self.assertEqual(p3.coords, p6.coords) self.assertRaises(TypeError, setattr, p6, 'coords', 0) self.assertRaises(TypeError, setattr, p6, 'coords', [0]) f = geometry._Feature() self.assertRaises(TypeError, geometry.Point, f)
def testPoint(self): self.assertRaises(ValueError, geometry.Point) p = geometry.Point(0, 1) self.assertEqual(p.bounds, (0.0, 1.0, 0.0, 1.0)) self.assertEqual(p.x, 0.0) self.assertEqual(p.y, 1.0) self.assertEqual(p.__geo_interface__, {'type': 'Point', 'coordinates': (0.0, 1.0)}) self.assertRaises(ValueError, lambda: p.z) self.assertEqual(p.coords[0], (0.0, 1.0)) p1 = geometry.Point(0, 1, 2) self.assertEqual(p1.x, 0.0) self.assertEqual(p1.y, 1.0) self.assertEqual(p1.z, 2.0) self.assertEqual(p1.coords[0], (0.0, 1.0, 2.0)) self.assertEqual(p1.__geo_interface__, {'type': 'Point', 'coordinates': (0.0, 1.0, 2.0)}) p2 = geometry.Point([0, 1]) self.assertEqual(p2.x, 0.0) self.assertEqual(p2.y, 1.0) p3 = geometry.Point([0, 1, 2]) self.assertEqual(p3.x, 0.0) self.assertEqual(p3.y, 1.0) self.assertEqual(p3.z, 2.0) p4 = geometry.Point(p) self.assertEqual(p4.x, 0.0) self.assertEqual(p4.y, 1.0) p5 = geometry.Point(p1) self.assertEqual(p5.x, 0.0) self.assertEqual(p5.y, 1.0) self.assertEqual(p5.z, 2.0) self.assertRaises(TypeError, geometry.Point, '1.0, 2.0') self.assertRaises(ValueError, geometry.Point, '1.0', 'a') self.assertRaises(TypeError, geometry.Point, (0,1,2,3,4)) #you may also pass string values as internally they get converted #into floats, but this is not recommended p6 = geometry.Point('0', '1') self.assertEqual(p.__geo_interface__,p6.__geo_interface__) p6.coords = [0,1,2] self.assertEqual(p3.coords, p6.coords) self.assertRaises(TypeError, setattr, p6, 'coords', 0) self.assertRaises(TypeError, setattr, p6, 'coords', [0]) f = geometry._Feature() self.assertRaises(TypeError, geometry.Point, f)
def test_notimplemented(self): f = geometry._Feature() self.assertRaises(NotImplementedError, geometry.as_shape, f)
def test_Feature(self): f = geometry._Feature() self.assertRaises(NotImplementedError, lambda: f.bounds) self.assertRaises(NotImplementedError, f.to_wkt)
def test_Feature(self): f = geometry._Feature() self.assertRaises(NotImplementedError, lambda: f.bounds) self.assertRaises(NotImplementedError, f.to_wkt)
def test_notimplemented(self): f = geometry._Feature() self.assertRaises(NotImplementedError, geometry.as_shape, f)