Exemplo n.º 1
0
def test_simplification_equal_window():
    line = [(30, 10), (10, 30), (40, 40), (50, 30)]
    simplified_line = simplify(line, 5, 3)
    assert len(simplified_line) == 3
    assert simplified_line[0] == (30, 10)
    assert simplified_line[1] == (10, 30)
    assert simplified_line[2] == (50, 30)
Exemplo n.º 2
0
def test_simplification_complex_line():
    line = [(10, 30), (15, 10), (20, 15), (25, 30), (30, 60), (35, 10), (40, 40)]
    simplified_line = simplify(line, 5, 3)
    assert len(simplified_line) == 5
    assert simplified_line[0] == (10, 30)
    assert simplified_line[1] == (15, 10)
    assert simplified_line[2] == (25, 30)
    assert simplified_line[3] == (30, 60)
    assert simplified_line[4] == (40, 40)
Exemplo n.º 3
0
def simplify():
    parser = argparse.ArgumentParser(
        description="Line simplification tool. Accepts WKT ListString on stdin\n"
        " and returns simplified WKT LineString on stdout")
    parser.add_argument("tolerance",
                        type=float,
                        help="Simplification tolerance.")
    parser.add_argument("window", type=int, help="Simplification window")
    parser.add_argument("--render",
                        action="store_true",
                        help="Render line images during processing")
    args = parser.parse_args()

    print("Type a correct WKT LineString or type Q/q to quit")
    while True:
        line = input("--> ")
        if line.upper().startswith("Q"):
            break

        try:
            line_string = wkt.loads(line)
            line_coords = []
            for p in line_string.coords:
                line_coords.append(p)
            simplified_line = psimpl.simplify(line_coords, args.tolerance,
                                              args.window)
            simplified_line_string = LineString(simplified_line)
            print(simplified_line_string.wkt)
            if args.render:
                plt.xlim(line_string.bounds[0], line_string.bounds[2])
                plt.ylim(line_string.bounds[1], line_string.bounds[3])
                fig, axs = plt.subplots(2)
                axs[0].plot(
                    line_string,
                    alpha=0.7,
                    linewidth=3,
                    solid_capstyle="round",
                    zorder=2,
                )
                axs[1].plot(
                    simplified_line_string,
                    alpha=0.7,
                    linewidth=3,
                    solid_capstyle="round",
                    zorder=2,
                )
                plt.show()
        except Exception as e:
            print("Error: {}\n".format(e))
Exemplo n.º 4
0
def test_simplification_negative_tolerance():
    line = [(30, 10), (10, 30), (40, 40), (50, 30)]
    with pytest.raises(ValueError):
        simplify(line, -5, 6)
Exemplo n.º 5
0
def test_simplification_short_line():
    line = [(30, 10), (10, 30), (40, 40), (50, 30)]
    simplified_line = simplify(line, 5, 6)
    assert len(simplified_line) == 4
Exemplo n.º 6
0
def test_simplification_small_window():
    line = [(30, 10), (10, 30), (40, 40), (50, 30)]
    simplified_line = simplify(line, 5, 2)
    assert len(simplified_line) == 4