Exemplo n.º 1
0
def test_from_polygon_without_enough_tolerance():
    poly = load_wkt('POLYGON ((0 0, 0.5 0, 0.5 0.5, 0 0.5, 0 0))')
    with pytest.raises(ValueError) as exc:
        voronoi_diagram(poly, tolerance=0.6)

    assert "Could not create Voronoi Diagram with the specified inputs" in str(exc.value)
    assert "Try running again with default tolerance value." in str(exc.value)
Exemplo n.º 2
0
def test_from_polygon_without_floating_point_coordinates():
    poly = load_wkt('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')
    with pytest.raises(ValueError) as exc:
        voronoi_diagram(poly, tolerance=0.1)

    assert "Could not create Voronoi Diagram with the specified inputs" in str(exc.value)
    assert "Try running again with default tolerance value." in str(exc.value)
Exemplo n.º 3
0
def test_from_multipoint_with_tolerace_without_floating_point_coordinates():
    """This multipoint will not work with a tolerance value."""
    mp = load_wkt('MULTIPOINT (0 0, 1 0, 1 2, 0 1)')
    with pytest.raises(ValueError) as exc:
        voronoi_diagram(mp, tolerance=0.1)

    assert "Could not create Voronoi Diagram with the specified inputs" in str(exc.value)
    assert "Try running again with default tolerance value." in str(exc.value)
Exemplo n.º 4
0
def test_from_multipoint_without_floating_point_coordinates():
    """A Multipoint with the same "shape" as the above Polygon raises the same error..."""
    mp = load_wkt('MULTIPOINT (0 0, 1 0, 1 1, 0 1)')

    with pytest.raises(ValueError) as exc:
        voronoi_diagram(mp, tolerance=0.1)

    assert "Could not create Voronoi Diagram with the specified inputs" in str(exc.value)
    assert "Try running again with default tolerance value." in str(exc.value)
Exemplo n.º 5
0
def test_smaller_envelope():
    mp = MultiPoint(points=[(0.5, 0.5), (1.0, 1.0)])
    poly = load_wkt('POLYGON ((0 0, 0.5 0, 0.5 0.5, 0 0.5, 0 0))')

    regions = voronoi_diagram(mp, envelope=poly)

    assert len(regions.geoms) == 2
    assert sum(r.area for r in regions.geoms) > poly.area
Exemplo n.º 6
0
def test_larger_envelope():
    """When the envelope we specify is larger than the
    area of the input feature, the created regions should
    expand to fill that area."""
    mp = MultiPoint(points=[(0.5, 0.5), (1.0, 1.0)])
    poly = load_wkt('POLYGON ((0 0, 2 0, 2 2, 0 2, 0 0))')

    regions = voronoi_diagram(mp, envelope=poly)

    assert len(regions.geoms) == 2
    assert sum(r.area for r in regions.geoms) == poly.area
Exemplo n.º 7
0
def test_from_polygon_with_enough_tolerance():
    poly = load_wkt('POLYGON ((0 0, 0.5 0, 0.5 0.5, 0 0.5, 0 0))')
    regions = voronoi_diagram(poly, tolerance=1.0)

    assert len(regions.geoms) == 2
Exemplo n.º 8
0
def test_from_polygon():
    poly = load_wkt('POLYGON ((0 0, 1 0, 1 1, 0 1, 0 0))')
    regions = voronoi_diagram(poly)

    assert len(regions.geoms) == 4
Exemplo n.º 9
0
def test_edges():
    mp = MultiPoint(points=[(0.5, 0.5), (1.0, 1.0)])
    regions = voronoi_diagram(mp, edges=True)

    assert len(regions.geoms) == 1
    assert all(r.type == 'LineString' for r in regions.geoms)
Exemplo n.º 10
0
def test_two_regions():
    mp = MultiPoint(points=[(0.5, 0.5), (1.0, 1.0)])
    regions = voronoi_diagram(mp)

    assert len(regions.geoms) == 2
Exemplo n.º 11
0
def test_from_multipoint_without_tolerace_without_floating_point_coordinates():
    """But it's fine without it."""
    mp = load_wkt('MULTIPOINT (0 0, 1 0, 1 2, 0 1)')
    regions = voronoi_diagram(mp)
    assert len(regions.geoms) == 4
Exemplo n.º 12
0
def test_no_regions():
    mp = MultiPoint(points=[(0.5, 0.5)])
    with np.errstate(invalid="ignore"):
        regions = voronoi_diagram(mp)

    assert len(regions.geoms) == 0
Exemplo n.º 13
0
def test_no_regions():
    mp = MultiPoint(points=[(0.5, 0.5)])
    regions = voronoi_diagram(mp)

    assert len(regions) == 0
Exemplo n.º 14
0
from shapely.geometry import MultiPoint
from shapely.ops import voronoi_diagram

from matplotlib import pyplot
from descartes.patch import PolygonPatch
from figures import SIZE, BLUE, GRAY, set_limits

points = MultiPoint([(0, 0), (1, 1), (0, 2), (2, 2), (3, 1), (1, 0)])
regions = voronoi_diagram(points)

fig = pyplot.figure(1, figsize=SIZE, dpi=90)
fig.set_frameon(True)
ax = fig.add_subplot(111)

for region in regions:
    patch = PolygonPatch(region, facecolor=BLUE, edgecolor=BLUE, alpha=0.5, zorder=2)
    ax.add_patch(patch)

for point in points:
    pyplot.plot(point.x, point.y, 'o', color=GRAY)

set_limits(ax, -1, 4, -1, 3)

pyplot.show()