예제 #1
0
    def test_polygon_parse(self):
        """
        This test exercises the parsing logic our POLYGON WKT object
        @since 1.2
        @jira_ticket PYTHON-641
        @test_category dse geometric
        @expected_result We should be able to form POLYGON objects from properly formatted WKT strings
        """

        example_poly_string = 'POLYGON ((10.1 10.0, 110.0 10.0, 110.0 110.0, 10.0 110.0, 10.0 10.0), (20.0 20.0, 20.0 30.0, 30.0 30.0, 30.0 20.0, 20.0 20.0), (40.0 20.0, 40.0 30.0, 50.0 30.0, 50.0 20.0, 40.0 20.0))'
        poly_obj = Polygon.from_wkt(example_poly_string)
        expected_ex_coords = ((10.1, 10.0), (110.0, 10.0), (110.0, 110.0),
                              (10.0, 110.0), (10.0, 10.0))
        expected_in_coords_1 = ((20.0, 20.0), (20.0, 30.0), (30.0, 30.0),
                                (30.0, 20.0), (20.0, 20.0))
        expected_in_coords_2 = ((40.0, 20.0), (40.0, 30.0), (50.0, 30.0),
                                (50.0, 20.0), (40.0, 20.0))
        self.assertEqual(poly_obj.exterior.coords, expected_ex_coords)
        self.assertEqual(len(poly_obj.interiors), 2)
        self.assertEqual(poly_obj.interiors[0].coords, expected_in_coords_1)
        self.assertEqual(poly_obj.interiors[1].coords, expected_in_coords_2)

        # Test with very long polygon
        long_poly_string = self._construct_polygon_string(10000)
        long_poly_obj = Polygon.from_wkt(long_poly_string)
        self.assertEqual(len(long_poly_obj.exterior.coords), 10000)
        #for expected, recieved in zip(self._construct_line_string_expected_cords(10000), long_poly_obj.exterior.coords):
        #    self.assertEqual(expected, recieved)
        self.assertEqual(long_poly_obj.exterior.coords,
                         self._construct_line_string_expected_cords(10000))

        # Test bad polygon strings
        bps = "POLYGONE ((30 10, 40 40, 20 40, 10 20, 30 10))"
        with self.assertRaises(ValueError):
            bpo = Polygon.from_wkt(bps)
        bps = "POLYGON (30 10, 40 40, 20 40, 10 20, 30 10)"
        with self.assertRaises(ValueError):
            bpo = Polygon.from_wkt(bps)

        # Polygons get truncated automatically
        ps = "POLYGON ((30 10, 40 40, 20, 10 20, 30))"
        po = Polygon.from_wkt(ps)
        expected_ex_coords = ((30.0, 10.0), (40.0, 40.0), (20.0, ),
                              (10.0, 20.0), (30.0, ))
        self.assertEqual(po.exterior.coords, expected_ex_coords)

        # Test Polygon with NAN
        ps = "POLYGON ((NAN NAN, NAN NAN, NAN NAN, NAN, NAN))"
        po = Polygon.from_wkt(ps)
        for cords in po.exterior.coords:
            for cord in cords:
                self.assertTrue(math.isnan(cord))
예제 #2
0
    def test_polygon_parse(self):
        """
        This test exercises the parsing logic our POLYGON WKT object
        @since 1.2
        @jira_ticket PYTHON-641
        @test_category dse geometric
        @expected_result We should be able to form POLYGON objects from properly formatted WKT strings
        """

        example_poly_string = 'POLYGON ((10.1 10.0, 110.0 10.0, 110.0 110.0, 10.0 110.0, 10.0 10.0), (20.0 20.0, 20.0 30.0, 30.0 30.0, 30.0 20.0, 20.0 20.0), (40.0 20.0, 40.0 30.0, 50.0 30.0, 50.0 20.0, 40.0 20.0))'
        poly_obj = Polygon.from_wkt(example_poly_string)
        expected_ex_coords = ((10.1, 10.0), (110.0, 10.0), (110.0, 110.0), (10.0, 110.0), (10.0, 10.0))
        expected_in_coords_1 = ((20.0, 20.0), (20.0, 30.0), (30.0, 30.0), (30.0, 20.0), (20.0, 20.0))
        expected_in_coords_2 = ((40.0, 20.0), (40.0, 30.0), (50.0, 30.0), (50.0, 20.0), (40.0, 20.0))
        self.assertEqual(poly_obj.exterior.coords, expected_ex_coords)
        self.assertEqual(len(poly_obj.interiors), 2)
        self.assertEqual(poly_obj.interiors[0].coords, expected_in_coords_1)
        self.assertEqual(poly_obj.interiors[1].coords, expected_in_coords_2)

        # Test with very long polygon
        long_poly_string = self._construct_polygon_string(10000)
        long_poly_obj = Polygon.from_wkt(long_poly_string)
        self.assertEqual(len(long_poly_obj.exterior.coords), 10000)
        #for expected, recieved in zip(self._construct_line_string_expected_cords(10000), long_poly_obj.exterior.coords):
        #    self.assertEqual(expected, recieved)
        self.assertEqual(long_poly_obj.exterior.coords, self._construct_line_string_expected_cords(10000))

        # Test bad polygon strings
        bps = "POLYGONE ((30 10, 40 40, 20 40, 10 20, 30 10))"
        with self.assertRaises(ValueError):
            bpo = Polygon.from_wkt(bps)
        bps = "POLYGON (30 10, 40 40, 20 40, 10 20, 30 10)"
        with self.assertRaises(ValueError):
            bpo = Polygon.from_wkt(bps)

        # Polygons get truncated automatically
        ps = "POLYGON ((30 10, 40 40, 20, 10 20, 30))"
        po = Polygon.from_wkt(ps)
        expected_ex_coords = ((30.0, 10.0), (40.0, 40.0), (20.0,), (10.0, 20.0), (30.0,))
        self.assertEqual(po.exterior.coords, expected_ex_coords)

        # Test Polygon with NAN
        ps = "POLYGON ((NAN NAN, NAN NAN, NAN NAN, NAN, NAN))"
        po = Polygon.from_wkt(ps)
        for cords in po.exterior.coords:
            for cord in cords:
                self.assertTrue(math.isnan(cord))
예제 #3
0
 def objectify(cls, v, _):
     return Polygon.from_wkt(v)
예제 #4
0
 def deserialize(cls, value):
     return Polygon.from_wkt(value)