def test_linearring(self): f = geometry.LinearRing([(0, 0), (1, 1), (1, 0), (0, 0)]) coords = f.coords f._set_orientation(False) self.assertEqual(f.coords, coords[::-1]) f._set_orientation(True) self.assertEqual(f.coords, coords)
def test_geometrycollection(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._Geometry() 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]) self.assertEqual([p, ph, p0, p1, r, l], [geom for geom in gc])
def testVertexPositions(self): v = czml.VertexPositions() l = geometry.LineString([(0, 0), (1, 1)]) r = geometry.LinearRing([(0, 0), (1, 1), (1, 0), (0, 0)]) ext = [(0, 0), (0, 2), (2, 2), (2, 0), (0, 0)] int_1 = [(0.5, 0.25), (1.5, 0.25), (1.5, 1.25), (0.5, 1.25), (0.5, 0.25)] int_2 = [(0.5, 1.25), (1, 1.25), (1, 1.75), (0.5, 1.75), (0.5, 1.25)] p = geometry.Polygon(ext, [int_1, int_2]) v.cartesian = l v.cartographicDegrees = r v.cartographicRadians = p self.assertEqual(v.data(), {'cartesian': [0.0, 0.0, 0, 1.0, 1.0, 0], 'cartographicRadians': [0.0, 0.0, 0, 0.0, 2.0, 0, 2.0, 2.0, 0, 2.0, 0.0, 0, 0.0, 0.0, 0], 'cartographicDegrees': [0.0, 0.0, 0, 1.0, 1.0, 0, 1.0, 0.0, 0, 0.0, 0.0, 0]}) v2 = czml.VertexPositions() v2.loads(v.dumps()) self.assertEqual(v.data(), v2.data()) v.cartesian = None v.cartographicDegrees = None v.cartographicRadians = [0.0, 0.0, .0, 1.0, 1.0, 1.0] self.assertEqual(v.data(), {'cartographicRadians': [0.0, 0.0, 0.0, 1.0, 1.0, 1.0]})
def test_linearring(self): r = geometry.LinearRing([(0, 0), (1, 1), (1, 0), (0, 0)]) self.assertEqual(r.coords, ((0, 0), (1, 1), (1, 0), (0, 0))) self.assertEqual(r.bounds, (0.0, 0.0, 1.0, 1.0)) l = geometry.LineString(r) self.assertEqual(l.coords, ((0, 0), (1, 1), (1, 0), (0, 0))) self.assertEqual( r.__geo_interface__, { 'type': 'LinearRing', 'coordinates': ((0.0, 0.0), (1.0, 1.0), (1.0, 0.0), (0.0, 0.0)) }) ext = [(0, 0), (0, 2), (2, 2), (2, 0), (0, 0)] int_1 = [(0.5, 0.25), (1.5, 0.25), (1.5, 1.25), (0.5, 1.25), (0.5, 0.25)] int_2 = [(0.5, 1.25), (1, 1.25), (1, 1.75), (0.5, 1.75), (0.5, 1.25)] p = geometry.Polygon(ext, [int_1, int_2]) self.assertRaises(TypeError, geometry.LinearRing, p) # A LinearRing is self closing r2 = geometry.LinearRing([(0, 0), (1, 1), (1, 0)]) self.assertEqual(r.__geo_interface__, r2.__geo_interface__) r3 = geometry.LinearRing(int_1) r3.coords = [(0, 0), (1, 1), (1, 0)] self.assertEqual(r.__geo_interface__, r3.__geo_interface__)
def setUp(self): self.geometry = geometry._Geometry() self.point = geometry.Point(0, 1) self.linestring = geometry.LineString([[0, 0], [1, 0], [1, 1]]) self.linearring = geometry.LinearRing([[0, 0], [1, 0], [1, 1], [0, 0]]) self.coords_1 = ((0., 0.), (0., 1.), (1., 1.), (1., 0.), (0., 0.)) self.polygon = geometry.Polygon(self.coords_1) self.multipoint = geometry.MultiPoint([[0.0, 0.0], [1.0, 2.0]]) self.multiline = geometry.MultiLineString([[[0.0, 0.0], [1.0, 2.0]]]) self.multipoly = geometry.MultiPolygon([ (((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)), [((0.1, 0.1), (0.1, 0.2), (0.2, 0.2), (0.2, 0.1))]) ]) self.geo_collect = geometry.GeometryCollection( [self.point, self.linestring, self.linearring]) self.feature = geometry.Feature(self.point, {'a': 1, 'b': 2}) self.feature_list = [self.feature, self.feature] self.fc = geometry.FeatureCollection(self.feature_list)
def test_linearring(self): f = geometry.LinearRing([(0, 0), (1, 1), (1, 0), (0, 0)]) s = geometry.as_shape(f) self.assertEqual(f.__geo_interface__, s.__geo_interface__)
def test_polygon(self): p = geometry.Polygon([(0, 0), (1, 1), (1, 0), (0, 0)]) self.assertEqual(p.exterior.coords, ((0.0, 0.0), (1.0, 1.0), (1.0, 0.0), (0.0, 0.0))) self.assertEqual(list(p.interiors), []) self.assertEqual( p.__geo_interface__, { 'type': 'Polygon', 'bbox': (0.0, 0.0, 1.0, 1.0), 'coordinates': (((0.0, 0.0), (1.0, 1.0), (1.0, 0.0), (0.0, 0.0)), ) }) self.assertEqual(p.bounds, (0.0, 0.0, 1.0, 1.0)) r = geometry.LinearRing([(0, 0), (1, 1), (1, 0), (0, 0)]) p1 = geometry.Polygon(r) self.assertEqual(p1.exterior.coords, r.coords) 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)] ph1 = geometry.Polygon(e, [i]) self.assertEqual(ph1.__geo_interface__, geometry.as_shape(ph1).__geo_interface__) self.assertEqual(ph1.exterior.coords, tuple(e)) self.assertEqual(list(ph1.interiors)[0].coords, tuple(i)) self.assertEqual( ph1.__geo_interface__, { 'type': 'Polygon', 'bbox': (0.0, 0.0, 2.0, 2.0), 'coordinates': (((0.0, 0.0), (0.0, 2.0), (2.0, 2.0), (2.0, 0.0), (0.0, 0.0)), ((1.0, 0.0), (0.5, 0.5), (1.0, 1.0), (1.5, 0.5), (1.0, 0.0))) }) ext = [(0, 0), (0, 2), (2, 2), (2, 0), (0, 0)] int_1 = [(0.5, 0.25), (1.5, 0.25), (1.5, 1.25), (0.5, 1.25), (0.5, 0.25)] int_2 = [(0.5, 1.25), (1, 1.25), (1, 1.75), (0.5, 1.75), (0.5, 1.25)] ph2 = geometry.Polygon(ext, [int_1, int_2]) self.assertEqual(ph2.exterior.coords, tuple(ext)) self.assertEqual(list(ph2.interiors)[0].coords, tuple(int_1)) self.assertEqual(list(ph2.interiors)[1].coords, tuple(int_2)) self.assertEqual( ph2.__geo_interface__, { 'type': 'Polygon', 'bbox': (0.0, 0.0, 2.0, 2.0), 'coordinates': (((0.0, 0.0), (0.0, 2.0), (2.0, 2.0), (2.0, 0.0), (0.0, 0.0)), ((0.5, 0.25), (1.5, 0.25), (1.5, 1.25), (0.5, 1.25), (0.5, 0.25)), ((0.5, 1.25), (1.0, 1.25), (1.0, 1.75), (0.5, 1.75), (0.5, 1.25))) }) ph3 = geometry.Polygon(ph2) self.assertEqual(ph2.__geo_interface__, ph3.__geo_interface__) # if a polygon is passed as constructor holes will be ignored # XXX or should holes be added to the polygon? ph4 = geometry.Polygon(ph2, [i]) self.assertEqual(ph2.__geo_interface__, ph4.__geo_interface__) coords = ((0., 0.), (0., 1.), (1., 1.), (1., 0.), (0., 0.)) polygon = geometry.Polygon(coords) ph5 = geometry.Polygon( (((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)), ((0.1, 0.1), (0.1, 0.2), (0.2, 0.2), (0.2, 0.1)))) r1 = geometry.LinearRing([(0, 0), (2, 2), (2, 0), (0, 0)]) r2 = geometry.LinearRing([(0.5, 0.5), (1, 1), (1, 0), (0.5, 0.5)]) p6 = geometry.Polygon(r1, [r2]) pt = geometry.Point(0, 1) self.assertRaises(TypeError, geometry.Polygon, pt) self.assertRaises(TypeError, geometry.Polygon, 0) self.assertRaises(TypeError, geometry.Polygon, pt, [pt])