Example #1
0
 def test_repr(self):
     P = Polygon(p1, metadata={'name': 'a name'})
     print 'ppoints:', P.dtype, P.shape
     for p in P:
         print type(p), p
     print repr(P)
     assert repr(P) \
         == """Polygon( [[1.0, 2.0],
Example #2
0
def test_basemap_square3(dump):
    p1 = Polygon([[0, 45], [1, 45], [1, 46], [0, 46]], metadata=('name'
                 , 'land', '1'))

    poly_set = PolygonSet()
    poly_set.append(p1)

    gmap = map_canvas.MapCanvas((300, 100), land_polygons=poly_set)
    gmap.draw_background()
    gmap.save_background(os.path.join(dump, 'background_square3.png'))
    assert True
Example #3
0
 def test_size_zero(self):
     P = Polygon((), )
     assert len(P) == 0
Example #4
0
 def test_bounding_box(self):
     P = Polygon(p1)
     print P.bounding_box
     assert P.bounding_box == np.array([[1., 2.], [7., 8.]], dtype=np.float)
Example #5
0
 def test_data_view(self):
     P1 = Polygon([(1, 2), (3, 4), (5, 6)])
     P2 = Polygon(P1, copy=False)
     P2[1] = (9, 10)
     assert tuple(P1[1]) == (9.0, 10.0)
Example #6
0
 def test_data_copy(self):
     P1 = Polygon([(1, 2), (3, 4), (5, 6)])
     P2 = Polygon(P1, copy=True)
     P2[1] = (9, 10)
     assert tuple(P1[1]) == (3.0, 4.0)
Example #7
0
 def test_copy(self):
     m = {'name': 'a polygon', 'type': 'polyline'}
     P1 = Polygon([(1, 2), (3, 4), (5, 6)], metadata=m)
     P2 = Polygon(P1)
     assert P2.metadata['name'] == 'a polygon'
Example #8
0
 def test_metadata(self):
     m = {'name': 'a polygon', 'type': 'polyline'}
     P = Polygon([(1, 2), (3, 4), (5, 6)], metadata=m)
     assert P.metadata['name'] == 'a polygon'
Example #9
0
 def test_slice(self):
     P = Polygon([(1, 2), (3, 4), (5, 6)])
     print P[:2]
     assert P[:2] == Polygon([(1, 2), (3, 4)])
Example #10
0
 def test_index2(self):
     P = Polygon([(1, 2), (3, 4), (5, 6)])
     assert np.array_equal(P[2], np.array((5, 6), dtype=np.float))
Example #11
0
 def test_index(self):
     P = Polygon([(1, 2), (3, 4), (5, 6)])
     assert P[1, 0] == 3.0 and P[1, 1] == 4.0
Example #12
0
    def test_list(self):

        # all this needs to do is not raise an error

        Polygon([(1, 2), (3, 4), (5, 6)])
Example #13
0
 def test_str(self):
     P = Polygon(p1, metadata={'name': 'a name'})
     print P
     assert str(P) \
         == "Polygon with 4 points.\nmetadata: {'name': 'a name'}"
Example #14
0
    def test_init(self):

        # all this needs to do is not raise an error

        Polygon(p1)
Example #15
0
import numpy as np

from gnome.utilities.geometry.polygons import Polygon, PolygonSet

from gnome.utilities.file_tools.haz_files import ReadBNA

## some test polygons:
points1 = (
    (0, 0),
    (0, 95),  # these two very close together
    (5, 100),
    (100, 100),  # these two a bit further apart, but still very close
    (105, 10),
    (100, 0))
poly1 = Polygon(points1, metadata={'name': 'poly1'})

points2 = (
    (150, 80),
    (150, 100),
    (160, 100),
    (160, 80),
    (150, 80),  # first and last the same!
)

poly2 = Polygon(points2, metadata={'name': 'poly2'})

# this one  needs to get scaled up...
points3 = (
    (0.0, 0.0),
    (0.1, 0.3),