Beispiel #1
0
 def test_multipolygons(self):
     "Testing MultiPolygon objects."
     OGRGeometry('POINT(0 0)')
     for mp in self.geometries.multipolygons:
         mpoly = OGRGeometry(mp.wkt)
         self.assertEqual(6, mpoly.geom_type)
         self.assertEqual('MULTIPOLYGON', mpoly.geom_name)
         if mp.valid:
             self.assertEqual(mp.n_p, mpoly.point_count)
             self.assertEqual(mp.num_geom, len(mpoly))
             with self.assertRaises(OGRIndexError):
                 mpoly.__getitem__(len(mpoly))
             for p in mpoly:
                 self.assertEqual('POLYGON', p.geom_name)
                 self.assertEqual(3, p.geom_type)
         self.assertEqual(mpoly.wkt, OGRGeometry(mp.wkt).wkt)
Beispiel #2
0
 def test_multipolygons(self):
     "Testing MultiPolygon objects."
     OGRGeometry('POINT(0 0)')
     for mp in self.geometries.multipolygons:
         mpoly = OGRGeometry(mp.wkt)
         self.assertEqual(6, mpoly.geom_type)
         self.assertEqual('MULTIPOLYGON', mpoly.geom_name)
         if mp.valid:
             self.assertEqual(mp.n_p, mpoly.point_count)
             self.assertEqual(mp.num_geom, len(mpoly))
             with self.assertRaises(OGRIndexError):
                 mpoly.__getitem__(len(mpoly))
             for p in mpoly:
                 self.assertEqual('POLYGON', p.geom_name)
                 self.assertEqual(3, p.geom_type)
         self.assertEqual(mpoly.wkt, OGRGeometry(mp.wkt).wkt)
Beispiel #3
0
 def test_multipolygons(self):
     "Testing MultiPolygon objects."
     OGRGeometry('POINT(0 0)')
     for mp in self.geometries.multipolygons:
         mpoly = OGRGeometry(mp.wkt)
         self.assertEqual(6, mpoly.geom_type)
         self.assertEqual('MULTIPOLYGON', mpoly.geom_name)
         if mp.valid:
             self.assertEqual(mp.n_p, mpoly.point_count)
             self.assertEqual(mp.num_geom, len(mpoly))
             msg = 'Index out of range when accessing geometry in a collection: %s.'
             with self.assertRaisesMessage(IndexError, msg % len(mpoly)):
                 mpoly.__getitem__(len(mpoly))
             for p in mpoly:
                 self.assertEqual('POLYGON', p.geom_name)
                 self.assertEqual(3, p.geom_type)
         self.assertEqual(mpoly.wkt, OGRGeometry(mp.wkt).wkt)
Beispiel #4
0
 def test_multilinestring(self):
     "Testing MultiLineString objects."
     prev = OGRGeometry('POINT(0 0)')
     for mls in self.geometries.multilinestrings:
         mlinestr = OGRGeometry(mls.wkt)
         self.assertEqual(5, mlinestr.geom_type)
         self.assertEqual('MULTILINESTRING', mlinestr.geom_name)
         self.assertEqual(mls.n_p, mlinestr.point_count)
         self.assertEqual(mls.coords, mlinestr.tuple)
         self.assertEqual(mlinestr, OGRGeometry(mls.wkt))
         self.assertNotEqual(mlinestr, prev)
         prev = mlinestr
         for ls in mlinestr:
             self.assertEqual(2, ls.geom_type)
             self.assertEqual('LINESTRING', ls.geom_name)
         with self.assertRaises(OGRIndexError):
             mlinestr.__getitem__(len(mlinestr))
Beispiel #5
0
 def test_multilinestring(self):
     "Testing MultiLineString objects."
     prev = OGRGeometry('POINT(0 0)')
     for mls in self.geometries.multilinestrings:
         mlinestr = OGRGeometry(mls.wkt)
         self.assertEqual(5, mlinestr.geom_type)
         self.assertEqual('MULTILINESTRING', mlinestr.geom_name)
         self.assertEqual(mls.n_p, mlinestr.point_count)
         self.assertEqual(mls.coords, mlinestr.tuple)
         self.assertEqual(mlinestr, OGRGeometry(mls.wkt))
         self.assertNotEqual(mlinestr, prev)
         prev = mlinestr
         for ls in mlinestr:
             self.assertEqual(2, ls.geom_type)
             self.assertEqual('LINESTRING', ls.geom_name)
         with self.assertRaises(OGRIndexError):
             mlinestr.__getitem__(len(mlinestr))
Beispiel #6
0
 def test_multipolygons(self):
     "Testing MultiPolygon objects."
     OGRGeometry('POINT(0 0)')
     for mp in self.geometries.multipolygons:
         mpoly = OGRGeometry(mp.wkt)
         self.assertEqual(6, mpoly.geom_type)
         self.assertEqual('MULTIPOLYGON', mpoly.geom_name)
         if mp.valid:
             self.assertEqual(mp.n_p, mpoly.point_count)
             self.assertEqual(mp.num_geom, len(mpoly))
             msg = 'Index out of range when accessing geometry in a collection: %s.'
             with self.assertRaisesMessage(IndexError, msg % len(mpoly)):
                 mpoly.__getitem__(len(mpoly))
             for p in mpoly:
                 self.assertEqual('POLYGON', p.geom_name)
                 self.assertEqual(3, p.geom_type)
         self.assertEqual(mpoly.wkt, OGRGeometry(mp.wkt).wkt)
Beispiel #7
0
 def test_multilinestring(self):
     "Testing MultiLineString objects."
     prev = OGRGeometry('POINT(0 0)')
     for mls in self.geometries.multilinestrings:
         mlinestr = OGRGeometry(mls.wkt)
         self.assertEqual(5, mlinestr.geom_type)
         self.assertEqual('MULTILINESTRING', mlinestr.geom_name)
         self.assertEqual(mls.n_p, mlinestr.point_count)
         self.assertEqual(mls.coords, mlinestr.tuple)
         self.assertEqual(mlinestr, OGRGeometry(mls.wkt))
         self.assertNotEqual(mlinestr, prev)
         prev = mlinestr
         for ls in mlinestr:
             self.assertEqual(2, ls.geom_type)
             self.assertEqual('LINESTRING', ls.geom_name)
         msg = 'Index out of range when accessing geometry in a collection: %s.'
         with self.assertRaisesMessage(IndexError, msg % len(mlinestr)):
             mlinestr.__getitem__(len(mlinestr))
Beispiel #8
0
 def test_multilinestring(self):
     "Testing MultiLineString objects."
     prev = OGRGeometry('POINT(0 0)')
     for mls in self.geometries.multilinestrings:
         mlinestr = OGRGeometry(mls.wkt)
         self.assertEqual(5, mlinestr.geom_type)
         self.assertEqual('MULTILINESTRING', mlinestr.geom_name)
         self.assertEqual(mls.n_p, mlinestr.point_count)
         self.assertEqual(mls.coords, mlinestr.tuple)
         self.assertEqual(mlinestr, OGRGeometry(mls.wkt))
         self.assertNotEqual(mlinestr, prev)
         prev = mlinestr
         for ls in mlinestr:
             self.assertEqual(2, ls.geom_type)
             self.assertEqual('LINESTRING', ls.geom_name)
         msg = 'Index out of range when accessing geometry in a collection: %s.'
         with self.assertRaisesMessage(IndexError, msg % len(mlinestr)):
             mlinestr.__getitem__(len(mlinestr))
Beispiel #9
0
    def test_linestring(self):
        "Testing LineString objects."
        prev = OGRGeometry('POINT(0 0)')
        for ls in self.geometries.linestrings:
            linestr = OGRGeometry(ls.wkt)
            self.assertEqual(2, linestr.geom_type)
            self.assertEqual('LINESTRING', linestr.geom_name)
            self.assertEqual(ls.n_p, linestr.point_count)
            self.assertEqual(ls.coords, linestr.tuple)
            self.assertEqual(linestr, OGRGeometry(ls.wkt))
            self.assertNotEqual(linestr, prev)
            with self.assertRaises(OGRIndexError):
                linestr.__getitem__(len(linestr))
            prev = linestr

            # Testing the x, y properties.
            x = [tmpx for tmpx, tmpy in ls.coords]
            y = [tmpy for tmpx, tmpy in ls.coords]
            self.assertEqual(x, linestr.x)
            self.assertEqual(y, linestr.y)
Beispiel #10
0
    def test_linestring(self):
        "Testing LineString objects."
        prev = OGRGeometry('POINT(0 0)')
        for ls in self.geometries.linestrings:
            linestr = OGRGeometry(ls.wkt)
            self.assertEqual(2, linestr.geom_type)
            self.assertEqual('LINESTRING', linestr.geom_name)
            self.assertEqual(ls.n_p, linestr.point_count)
            self.assertEqual(ls.coords, linestr.tuple)
            self.assertEqual(linestr, OGRGeometry(ls.wkt))
            self.assertNotEqual(linestr, prev)
            with self.assertRaises(OGRIndexError):
                linestr.__getitem__(len(linestr))
            prev = linestr

            # Testing the x, y properties.
            x = [tmpx for tmpx, tmpy in ls.coords]
            y = [tmpy for tmpx, tmpy in ls.coords]
            self.assertEqual(x, linestr.x)
            self.assertEqual(y, linestr.y)
Beispiel #11
0
    def test_linestring(self):
        "Testing LineString objects."
        prev = OGRGeometry("POINT(0 0)")
        for ls in self.geometries.linestrings:
            linestr = OGRGeometry(ls.wkt)
            self.assertEqual(2, linestr.geom_type)
            self.assertEqual("LINESTRING", linestr.geom_name)
            self.assertEqual(ls.n_p, linestr.point_count)
            self.assertEqual(ls.coords, linestr.tuple)
            self.assertEqual(linestr, OGRGeometry(ls.wkt))
            self.assertNotEqual(linestr, prev)
            msg = "Index out of range when accessing points of a line string: %s."
            with self.assertRaisesMessage(IndexError, msg % len(linestr)):
                linestr.__getitem__(len(linestr))
            prev = linestr

            # Testing the x, y properties.
            x = [tmpx for tmpx, tmpy in ls.coords]
            y = [tmpy for tmpx, tmpy in ls.coords]
            self.assertEqual(x, linestr.x)
            self.assertEqual(y, linestr.y)
Beispiel #12
0
    def test_polygons(self):
        "Testing Polygon objects."

        # Testing `from_bbox` class method
        bbox = (-180, -90, 180, 90)
        p = OGRGeometry.from_bbox(bbox)
        self.assertEqual(bbox, p.extent)

        prev = OGRGeometry('POINT(0 0)')
        for p in self.geometries.polygons:
            poly = OGRGeometry(p.wkt)
            self.assertEqual(3, poly.geom_type)
            self.assertEqual('POLYGON', poly.geom_name)
            self.assertEqual(p.n_p, poly.point_count)
            self.assertEqual(p.n_i + 1, len(poly))
            msg = 'Index out of range when accessing rings of a polygon: %s.'
            with self.assertRaisesMessage(IndexError, msg % len(poly)):
                poly.__getitem__(len(poly))

            # Testing area & centroid.
            self.assertAlmostEqual(p.area, poly.area, 9)
            x, y = poly.centroid.tuple
            self.assertAlmostEqual(p.centroid[0], x, 9)
            self.assertAlmostEqual(p.centroid[1], y, 9)

            # Testing equivalence
            self.assertEqual(poly, OGRGeometry(p.wkt))
            self.assertNotEqual(poly, prev)

            if p.ext_ring_cs:
                ring = poly[0]
                self.assertEqual(p.ext_ring_cs, ring.tuple)
                self.assertEqual(p.ext_ring_cs, poly[0].tuple)
                self.assertEqual(len(p.ext_ring_cs), ring.point_count)

            for r in poly:
                self.assertEqual('LINEARRING', r.geom_name)
Beispiel #13
0
    def test_polygons(self):
        "Testing Polygon objects."

        # Testing `from_bbox` class method
        bbox = (-180, -90, 180, 90)
        p = OGRGeometry.from_bbox(bbox)
        self.assertEqual(bbox, p.extent)

        prev = OGRGeometry('POINT(0 0)')
        for p in self.geometries.polygons:
            poly = OGRGeometry(p.wkt)
            self.assertEqual(3, poly.geom_type)
            self.assertEqual('POLYGON', poly.geom_name)
            self.assertEqual(p.n_p, poly.point_count)
            self.assertEqual(p.n_i + 1, len(poly))
            msg = 'Index out of range when accessing rings of a polygon: %s.'
            with self.assertRaisesMessage(IndexError, msg % len(poly)):
                poly.__getitem__(len(poly))

            # Testing area & centroid.
            self.assertAlmostEqual(p.area, poly.area, 9)
            x, y = poly.centroid.tuple
            self.assertAlmostEqual(p.centroid[0], x, 9)
            self.assertAlmostEqual(p.centroid[1], y, 9)

            # Testing equivalence
            self.assertEqual(poly, OGRGeometry(p.wkt))
            self.assertNotEqual(poly, prev)

            if p.ext_ring_cs:
                ring = poly[0]
                self.assertEqual(p.ext_ring_cs, ring.tuple)
                self.assertEqual(p.ext_ring_cs, poly[0].tuple)
                self.assertEqual(len(p.ext_ring_cs), ring.point_count)

            for r in poly:
                self.assertEqual('LINEARRING', r.geom_name)