Exemple #1
0
def test_set_precision_drop_coords():
    # setting precision of 0 will not drop duplicated points in original
    geometry = pygeos.set_precision(
        pygeos.Geometry("LINESTRING (0 0, 0 0, 0 1, 1 1)"), 0)
    assert pygeos.equals(geometry,
                         pygeos.Geometry("LINESTRING (0 0, 0 0, 0 1, 1 1)"))

    # setting precision will remove duplicated points
    geometry = pygeos.set_precision(geometry, 1)
    assert pygeos.equals(geometry,
                         pygeos.Geometry("LINESTRING (0 0, 0 1, 1 1)"))
Exemple #2
0
def test_set_precision():
    initial_geometry = pygeos.Geometry("POINT (0.9 0.9)")
    assert pygeos.get_precision(initial_geometry) == 0

    geometry = pygeos.set_precision(initial_geometry, 0)
    assert pygeos.get_precision(geometry) == 0
    assert pygeos.equals(geometry, initial_geometry)

    geometry = pygeos.set_precision(initial_geometry, 1)
    assert pygeos.get_precision(geometry) == 1
    assert pygeos.equals(geometry, pygeos.Geometry("POINT (1 1)"))
    # original should remain unchanged
    assert pygeos.equals(initial_geometry, pygeos.Geometry("POINT (0.9 0.9)"))
Exemple #3
0
def test_set_operation_prec_array(a, func, grid_size):
    actual = func([a, a], point, grid_size=grid_size)
    assert actual.shape == (2, )
    assert isinstance(actual[0], Geometry)

    # results should match the operation when the precision is previously set
    # to same grid_size
    b = pygeos.set_precision(a, grid_size=grid_size)
    point2 = pygeos.set_precision(point, grid_size=grid_size)
    expected = func([b, b], point2)

    assert pygeos.equals(pygeos.normalize(actual),
                         pygeos.normalize(expected)).all()
Exemple #4
0
def test_set_precision_intersection():
    """Operations should use the most precise presision grid size of the inputs"""

    box1 = pygeos.normalize(pygeos.box(0, 0, 0.9, 0.9))
    box2 = pygeos.normalize(pygeos.box(0.75, 0, 1.75, 0.75))

    assert pygeos.get_precision(pygeos.intersection(box1, box2)) == 0

    # GEOS will use and keep the most precise precision grid size
    box1 = pygeos.set_precision(box1, 0.5)
    box2 = pygeos.set_precision(box2, 1)
    out = pygeos.intersection(box1, box2)
    assert pygeos.get_precision(out) == 0.5
    assert pygeos.equals(out, pygeos.Geometry("LINESTRING (1 1, 1 0)"))
Exemple #5
0
def test_set_precision_preserve_topology():
    # GEOS test case - geometry is valid initially but becomes
    # invalid after rounding
    geometry = pygeos.Geometry(
        "POLYGON((10 10,20 10,16 15,20 20, 10 20, 14 15, 10 10))")

    assert pygeos.equals(
        pygeos.set_precision(geometry, 5, preserve_topology=False),
        pygeos.Geometry(
            "POLYGON ((10 10, 20 10, 15 15, 20 20, 10 20, 15 15, 10 10))"),
    )

    assert pygeos.equals(
        pygeos.set_precision(geometry, 5, preserve_topology=True),
        pygeos.Geometry(
            "MULTIPOLYGON (((10 10, 15 15, 20 10, 10 10)), ((15 15, 10 20, 20 20, 15 15)))"
        ),
    )
Exemple #6
0
def test_get_precision():
    geometries = all_types + (point_z, empty_point, empty_line_string,
                              empty_polygon)
    # default is 0
    actual = pygeos.get_precision(geometries).tolist()
    assert actual == [0] * len(geometries)

    geometry = pygeos.set_precision(geometries, 1)
    actual = pygeos.get_precision(geometry).tolist()
    assert actual == [1] * len(geometries)
Exemple #7
0
def test_set_precision_collapse(geometry, expected):
    """Lines and polygons collapse to empty geometries if vertices are too close"""
    assert pygeos.equals(pygeos.set_precision(geometry, 1), expected)
Exemple #8
0
def test_set_precision_grid_size_nan():
    assert pygeos.set_precision(pygeos.Geometry("POINT (0.9 0.9)"),
                                np.nan) is None
Exemple #9
0
def test_set_precision_none():
    assert pygeos.set_precision(None, 0) is None
Exemple #10
0
def test_set_precision_nan():
    assert np.all(
        np.isnan(
            pygeos.get_coordinates(pygeos.set_precision(line_string_nan, 1))))
Exemple #11
0
def test_set_precision_z():
    geometry = pygeos.set_precision(pygeos.Geometry("POINT Z (0.9 0.9 0.9)"),
                                    1)
    assert pygeos.get_precision(geometry) == 1
    assert pygeos.equals(geometry, pygeos.Geometry("POINT Z (1 1 0.9)"))
Exemple #12
0
def test_set_precision_nan():
    assert np.all(
        np.isnan(pygeos.get_coordinates(pygeos.set_precision(point_nan, 1))))