Exemplo n.º 1
0
 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])
Exemplo n.º 2
0
 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])
Exemplo n.º 3
0
 def test_point(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._Geometry()
     self.assertRaises(TypeError, geometry.Point, f)
Exemplo n.º 4
0
 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.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0), (0.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)
Exemplo n.º 5
0
 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)
Exemplo n.º 6
0
 def test_point(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._Geometry()
     self.assertRaises(TypeError, geometry.Point, f)
Exemplo n.º 7
0
 def test_notimplemented(self):
     f = geometry._Geometry()
     self.assertRaises(NotImplementedError, geometry.as_shape, f)
Exemplo n.º 8
0
 def test_Geometry(self):
     f = geometry._Geometry()
     self.assertRaises(NotImplementedError, lambda: f.bounds)
     self.assertRaises(NotImplementedError, f.to_wkt)
Exemplo n.º 9
0
 def test_Geometry(self):
     f = geometry._Geometry()
     self.assertRaises(NotImplementedError, lambda: f.bounds)
     self.assertRaises(NotImplementedError, f.to_wkt)
Exemplo n.º 10
0
 def test_notimplemented(self):
     f = geometry._Geometry()
     self.assertRaises(NotImplementedError, geometry.as_shape, f)