Пример #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])
Пример #2
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)
Пример #3
0
 def test_multipoint(self):
     p0 = geometry.Point(0, 0)
     p1 = geometry.Point(1, 1)
     p2 = geometry.Point(2, 2)
     p3 = geometry.Point(3, 3)
     mp = geometry.MultiPoint(p0)
     self.assertEqual(len(mp.geoms), 1)
     self.assertEqual(mp.geoms[0].x, 0)
     mp1 = geometry.MultiPoint([p0, p1, p2])
     self.assertEqual(len(mp1.geoms), 3)
     self.assertEqual(len(mp1), 3)
     self.assertEqual(mp1.geoms[0].x, 0)
     self.assertEqual(mp1.geoms[1].x, 1)
     self.assertEqual(mp1.geoms[2].x, 2)
     self.assertEqual(mp1.bounds, (0.0, 0.0, 2.0, 2.0))
     l1 = geometry.LineString([p0, p1, p2])
     mp2 = geometry.MultiPoint(l1)
     self.assertEqual(len(mp2.geoms), 3)
     self.assertEqual(mp2.geoms[2].x, 2)
     mp3 = geometry.MultiPoint([l1, p3])
     self.assertEqual(mp3.geoms[3].x, 3)
     self.assertRaises(TypeError, geometry.MultiPoint, [mp1, mp3])
     mp4 = geometry.MultiPoint([p0, p1, p0, p1, p2])
     self.assertEqual(len(mp4.geoms), 5)
     mp4.unique()
     self.assertEqual(len(mp4.geoms), 3)
     mp5 = geometry.MultiPoint([[0.0, 0.0], [1.0, 2.0]])
     self.assertEqual(len(mp5.geoms), 2)
     p = 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))))
     mp6 = geometry.MultiPoint(p)
     self.assertEqual(mp6.bounds, (0.0, 0.0, 1.0, 1.0))
     self.assertRaises(TypeError, geometry.MultiPoint, [0, 0])
     self.assertRaises(
         TypeError,
         geometry.MultiPoint,
         0,
     )
     self.assertEqual(
         mp1.__geo_interface__, {
             'type': 'MultiPoint',
             'bbox': (0.0, 0.0, 2.0, 2.0),
             'coordinates': ((0.0, 0.0), (1.0, 1.0), (2.0, 2.0))
         })
Пример #4
0
 def test_multipoint(self):
     f = geometry.MultiPoint([[0.0, 0.0], [1.0, 2.0]])
     s = geometry.as_shape(f)
     self.assertEqual(f.__geo_interface__, s.__geo_interface__)