예제 #1
0
def test_intersection_3d():
    line = LineString([(0, 0), (4, 4)])
    line2 = LineString([(0, 4), (4, 0)])

    res_wkt = line.intersection_3d(line2).wktDecim(2)

    geom1 = sfcgal.read_wkt(res_wkt)
    geom2 = sfcgal.read_wkt('POINT(2 2)')

    assert geom1.covers(geom2)

    line = LineString([(0, 0, 1), (4, 4, 3)])
    line2 = LineString([(0, 4, 5), (4, 0, 2)])

    assert line.intersection_3d(line2).is_empty == 1

    line = LineString([(0, 0, 2), (4, 4, 4)])
    line2 = LineString([(0, 4, 4), (4, 0, 2)])

    res_wkt = line.intersection_3d(line2).wktDecim(0)

    geom1 = sfcgal.read_wkt(res_wkt)
    geom2 = sfcgal.read_wkt('POINT(2 2 3)')

    assert geom1.covers(geom2)
예제 #2
0
def test_approximate_medial_axis():
    poly = Polygon([(190, 190), (10, 190), (10, 10), (190, 10), (190, 20),
                    (160, 30), (60, 30), (60, 130), (190, 140), (190, 190)])
    res_wkt = poly.approximate_medial_axis().wktDecim(2)

    geom1 = sfcgal.read_wkt(res_wkt)
    geom2 = sfcgal.read_wkt("""MULTILINESTRING((184.19 15.81,158.38 20.00),
        (50.00 20.00,158.38 20.00),(50.00 20.00,35.00 35.00),(35.00 35.00,35.00
        153.15),(35.00 153.15,40.70 159.30),(164.04 164.04,40.70 159.30))""")
    assert geom1.covers(geom2)
예제 #3
0
def test_union():
    poly = Polygon([(0, 0, 1), (0, 1, 1), (1, 1, 1), (1, 0, 1), (0, 0, 1)])
    poly2 = Polygon([(-1, -1, 10), (-1, 1, 10), (1, 1, 10), (1, -1, 10),
                     (-1, -1, 10)])

    res_wkt = poly.union(poly2).wktDecim(2)

    geom1 = sfcgal.read_wkt(res_wkt)
    geom2 = sfcgal.read_wkt(
        """POLYGON((0.00 1.00,-1.00 1.00,-1.00 -1.00,1.00 -1.00,1.00 0.00,1.00
        1.00,0.00 1.00))""")

    assert geom1.covers(geom2)
예제 #4
0
def test_straight_skeleton():
    poly = Polygon([(190, 190), (10, 190), (10, 10), (190, 10), (190, 20),
                    (160, 30), (60, 30), (60, 130), (190, 140), (190, 190)])
    res_wkt = poly.straight_skeleton().wktDecim(2)

    geom1 = sfcgal.read_wkt(res_wkt)
    geom2 = sfcgal.read_wkt(
        """MULTILINESTRING((190.00 190.00,164.04 164.04),(10.00
    190.00,40.70 159.30),(10.00 10.00,35.00 35.00),(190.00 10.00,184.19
    15.81),(190.00 20.00,184.19 15.81),(160.00 30.00,158.38 20.00),(60.00
    30.00,50.00 20.00),(60.00 130.00,35.00 153.15),(190.00 140.00,164.04
    164.04),(184.19 15.81,158.38 20.00),(50.00 20.00,158.38 20.00),(50.00
    20.00,35.00 35.00),(35.00 35.00,35.00 153.15),(35.00 153.15,40.70
    159.30),(164.04 164.04,40.70 159.30))""")
    assert geom1.covers(geom2)
예제 #5
0
def test_polygon_with_breaklines_point():
    print("""\n\ntessellate(Polygon([(0,0), (1,0), (1,1), (0,1)]),
        MultiLineString([LineString([(.2, .6), (.8,.6)]), LineString([(.2, .4),
        (.8,.4)])]), [Point(.9, .9)])""")
    poly = Polygon([(0, 0), (1, 0), (1, 1), (0, 1)])
    multiline = MultiLineString([[(.2, .6), (.8, .6)], [(.2, .4), (.8, .4)]])
    point = Point(.9, .9)
    geom = GeometryCollection()
    geom.addGeometry(poly)
    geom.addGeometry(multiline)
    geom.addGeometry(point)
    tesselation = geom.tessellate()
    geom2 = sfcgal.read_wkt("""GEOMETRYCOLLECTION(
    TRIANGLE((0.0 0.0,1.0 0.0,0.2 0.4,0.0 0.0)),
    TRIANGLE((1.0 0.0,1.0 1.0,0.8 0.6,1.0 0.0)),
    TRIANGLE((0.8 0.4,1.0 0.0,0.8 0.6,0.8 0.4)),
    TRIANGLE((0.2 0.4,0.2 0.6,0.0 1.0,0.2 0.4)),
    TRIANGLE((0.0 0.0,0.2 0.4,0.0 1.0,0.0 0.0)),
    TRIANGLE((0.9 0.9,1.0 1.0,0.0 1.0,0.9 0.9)),
    TRIANGLE((0.2 0.6,0.9 0.9,0.0 1.0,0.2 0.6)),
    TRIANGLE((0.8 0.6,0.9 0.9,0.2 0.6,0.8 0.6)),
    TRIANGLE((0.2 0.4,0.8 0.4,0.2 0.6,0.2 0.4)),
    TRIANGLE((0.8 0.4,0.8 0.6,0.2 0.6,0.8 0.4)),
    TRIANGLE((0.2 0.4,1.0 0.0,0.8 0.4,0.2 0.4)),
    TRIANGLE((0.8 0.6,1.0 1.0,0.9 0.9,0.8 0.6)))""")
    assert tesselation.covers(geom2)
예제 #6
0
def test_polygon_with_breaklines():
    print("""\n\ntessellate(Polygon([(0,0), (1,0), (1,1), (0,1)]),
        [LineString([(.2, .6), (.8,.6)]), LineString([(.2, .4), (.8,.4)])])""")
    poly = Polygon([(0, 0), (1, 0), (1, 1), (0, 1)])
    lines = [
        LineString([(.2, .6), (.8, .6)]),
        LineString([(.2, .4), (.8, .4)])
    ]
    geom = GeometryCollection()
    geom.addGeometry(poly)
    for line in lines:
        geom.addGeometry(line)
    tesselation = geom.tessellate()
    geom2 = sfcgal.read_wkt("""GEOMETRYCOLLECTION(
    TRIANGLE((0.2 0.4,1.0 0.0,0.8 0.4,0.2 0.4)),
    TRIANGLE((1.0 0.0,1.0 1.0,0.8 0.6,1.0 0.0)),
    TRIANGLE((0.8 0.4,1.0 0.0,0.8 0.6,0.8 0.4)),
    TRIANGLE((0.2 0.4,0.2 0.6,0.0 1.0,0.2 0.4)),
    TRIANGLE((0.2 0.6,1.0 1.0,0.0 1.0,0.2 0.6)),
    TRIANGLE((0.0 0.0,1.0 0.0,0.2 0.4,0.0 0.0)),
    TRIANGLE((0.0 0.0,0.2 0.4,0.0 1.0,0.0 0.0)),
    TRIANGLE((0.8 0.6,1.0 1.0,0.2 0.6,0.8 0.6)),
    TRIANGLE((0.8 0.4,0.8 0.6,0.2 0.6,0.8 0.4)),
    TRIANGLE((0.2 0.4,0.8 0.4,0.2 0.6,0.2 0.4)))""")
    assert tesselation.covers(geom2)
예제 #7
0
def test_union_3d():
    poly = Polygon([(0, 0, 1), (0, 1, 1), (1, 1, 1), (1, 0, 1), (0, 0, 1)])
    poly2 = Polygon([(-1, -1, 10), (-1, 1, 10), (1, 1, 10), (1, -1, 10),
                     (-1, -1, 10)])

    res_wkt = poly.union(poly2).wktDecim(2)

    geom1 = sfcgal.read_wkt(res_wkt)
    geom2 = sfcgal.read_wkt(
        """GEOMETRYCOLLECTION(TIN(((-0.00 0.00 1.00,-0.00 1.00 1.00,1.00 1.00
        1.00,-0.00 0.00 1.00)),((1.00 -0.00 1.00,-0.00 0.00 1.00,1.00 1.00
        1.00,1.00 -0.00 1.00))),TIN(((-1.00 -1.00 10.00,-1.00 1.00 10.00,1.00
        1.00 10.00,-1.00 -1.00 10.00)),((1.00 -1.00 10.00,-1.00 -1.00 10.00,
        1.00 1.00 10.00,1.00 -1.00 10.00))))""")

    assert geom1.covers(geom2)
예제 #8
0
def test_simple_polygon():
    print("\n\ntessellate(Polygon([(0,0), (1,0), (1,1), (0,1)]))")
    poly = Polygon([(0, 0), (1, 0), (1, 1), (0, 1)])
    print(poly.wktDecim(1))
    geom = GeometryCollection()
    geom.addGeometry(poly)
    tesselation = geom.tessellate()
    geom2 = sfcgal.read_wkt("""GEOMETRYCOLLECTION(
    TRIANGLE((1.0 0.0,1.0 1.0,0.0 1.0,1.0 0.0)),
    TRIANGLE((0.0 0.0,1.0 0.0,0.0 1.0,0.0 0.0)))""")
    assert tesselation.covers(geom2)
예제 #9
0
def test_minkowski_sum():
    poly = Polygon([(190, 190), (10, 190), (10, 10), (190, 10), (190, 20),
                    (160, 30), (60, 30), (60, 130), (190, 140), (190, 190)])
    poly2 = Polygon([(185, 185), (185, 190), (190, 190), (190, 185),
                     (185, 185)])
    res_wkt = poly.straight_skeleton().minkowski_sum(poly2).wktDecim(2)

    geom1 = sfcgal.read_wkt(res_wkt)
    geom2 = sfcgal.read_wkt(
        """MULTIPOLYGON(((375.00 210.00,370.11 206.47,349.17
    209.87,350.00 215.00,350.00 220.00,345.00 220.00,343.38 210.00,245.00
    210.00,250.00 215.00,250.00 220.00,245.00 220.00,237.50 212.50,225.00
    225.00,225.00 333.52,245.00 315.00,250.00 315.00,250.00 320.00,227.49
    340.84,230.70 344.30,349.24 348.86,375.00 325.00,380.00 325.00,380.00
    330.00,356.64 351.64,380.00 375.00,380.00 380.00,375.00 380.00,349.04
    354.04,230.51 349.49,200.00 380.00,195.00 380.00,195.00 375.00,223.29
    346.71,220.00 343.15,220.00 225.00,195.00 200.00,195.00 195.00,200.00
    195.00,222.50 217.50,235.00 205.00,240.00 205.00,343.38 205.00,369.19
    200.81,375.00 195.00,380.00 195.00,380.00 200.00,377.09 202.91,380.00
    205.00,380.00 210.00,375.00 210.00)))""")
    assert geom1.covers(geom2)
예제 #10
0
def test_polygon_with_quasi_collinear_points():
    print("""\n\ntessellate(Polygon(((-4.165589, -29.100525),
    (8.623957000000001, -28.461553), (21.413503, -27.822581), (10.706928,
    -13.90117), (0.000353, 0.020242), (-2.082618, -14.540141), (-4.165589,
    -29.100525))))""")
    poly = Polygon([(-4.165589, -29.100525), (8.623957000000001, -28.461553),
                    (21.413503, -27.822581), (10.706928, -13.90117),
                    (0.000353, 0.020242), (-2.082618, -14.540141),
                    (-4.165589, -29.100525)])
    geom = GeometryCollection()
    geom.addGeometry(poly)
    tesselation = geom.tessellate()
    geom2 = sfcgal.read_wkt("""GEOMETRYCOLLECTION(
    TRIANGLE((-4.1656 -29.1005,8.6240 -28.4616,-2.0826 -14.5401,
    -4.1656 -29.1005)),
    TRIANGLE((8.6240 -28.4616,10.7069 -13.9012,-2.0826 -14.5401,
    8.6240 -28.4616)),
    TRIANGLE((-2.0826 -14.5401,10.7069 -13.9012,0.0004 0.0202,
    -2.0826 -14.5401)),
    TRIANGLE((8.6240 -28.4616,21.4135 -27.8226,10.7069
    -13.9012,8.6240 -28.4616)))""")
    geom1 = sfcgal.read_wkt(tesselation.wktDecim(4))
    assert geom1.covers(geom2)
예제 #11
0
def test_polygon_with_points():
    print("""\n\ntessellate(Polygon([(0,0), (1,0), (1,1), (0,1)]), lines=None,
        points=[Point(.9, .9)])""")
    poly = Polygon([(0, 0), (1, 0), (1, 1), (0, 1)])
    point = Point(.9, .9)
    geom = GeometryCollection()
    geom.addGeometry(poly)
    geom.addGeometry(point)
    tesselation = geom.tessellate()
    geom2 = sfcgal.read_wkt("""GEOMETRYCOLLECTION(
    TRIANGLE((0.9 0.9,1.0 1.0,0.0 1.0,0.9 0.9)),
    TRIANGLE((0.0 0.0,1.0 0.0,0.9 0.9,0.0 0.0)),
    TRIANGLE((0.0 0.0,0.9 0.9,0.0 1.0,0.0 0.0)),
    TRIANGLE((1.0 0.0,1.0 1.0,0.9 0.9,1.0 0.0)))""")
    assert tesselation.covers(geom2)
예제 #12
0
def test_polygon_with_an_hole():
    print("""\n\ntessellate(Polygon([(0,0), (1,0), (1,1), (0,1)],
        [[(.2,.2),(.2,.8),(.8,.8),(.8,.2)]]))""")
    poly = Polygon([(0, 0), (1, 0), (1, 1), (0, 1)], [[(.2, .2), (.2, .8),
                                                       (.8, .8), (.8, .2)]])
    geom = GeometryCollection()
    geom.addGeometry(poly)
    tesselation = geom.tessellate()
    geom2 = sfcgal.read_wkt("""GEOMETRYCOLLECTION(
    TRIANGLE((0.2 0.2,1.0 0.0,0.8 0.2,0.2 0.2)),
    TRIANGLE((0.0 0.0,1.0 0.0,0.2 0.2,0.0 0.0)),
    TRIANGLE((0.0 0.0,0.2 0.2,0.0 1.0,0.0 0.0)),
    TRIANGLE((0.2 0.8,1.0 1.0,0.0 1.0,0.2 0.8)),
    TRIANGLE((0.2 0.2,0.2 0.8,0.0 1.0,0.2 0.2)),
    TRIANGLE((0.8 0.8,1.0 1.0,0.2 0.8,0.8 0.8)),
    TRIANGLE((0.8 0.2,1.0 1.0,0.8 0.8,0.8 0.2)),
    TRIANGLE((1.0 0.0,1.0 1.0,0.8 0.2,1.0 0.0)))""")
    assert tesselation.covers(geom2)
예제 #13
0
def test_polygon_with_hole_and_break_lines():
    print("""\n\ntessellate(Polygon([(0,0), (1,0), (1,1), (0,1)], [[(.2,.2),
    (.2,.8), (.8,.8), (.8, .2)]]), lines=[LineString([(.1, .1), (.9,.1)]),
    LineString([(.9, .1), (.9,.9)]), LineString([(.9, .9), (.1,.9)]),
    LineString([(.1, .9), (.1,.1)])])""")
    poly = Polygon([(0, 0), (1, 0), (1, 1), (0, 1)], [[(.2, .2), (.2, .8),
                                                       (.8, .8), (.8, .2)]])
    lines = [
        LineString([(.1, .1), (.9, .1)]),
        LineString([(.9, .1), (.9, .9)]),
        LineString([(.9, .9), (.1, .9)]),
        LineString([(.1, .9), (.1, .1)])
    ]
    geom = GeometryCollection()
    geom.addGeometry(poly)
    for line in lines:
        geom.addGeometry(line)
    tesselation = geom.tessellate()
    geom2 = sfcgal.read_wkt("""GEOMETRYCOLLECTION(
    TRIANGLE((0.0 0.0,1.0 0.0,0.1 0.1,0.0 0.0)),
    TRIANGLE((0.0 0.0,0.1 0.1,0.0 1.0,0.0 0.0)),
    TRIANGLE((0.1 0.9,1.0 1.0,0.0 1.0,0.1 0.9)),
    TRIANGLE((0.1 0.1,0.1 0.9,0.0 1.0,0.1 0.1)),
    TRIANGLE((0.1 0.1,0.9 0.1,0.2 0.2,0.1 0.1)),
    TRIANGLE((0.1 0.1,1.0 0.0,0.9 0.1,0.1 0.1)),
    TRIANGLE((0.2 0.8,0.9 0.9,0.1 0.9,0.2 0.8)),
    TRIANGLE((0.1 0.1,0.2 0.2,0.1 0.9,0.1 0.1)),
    TRIANGLE((0.2 0.2,0.2 0.8,0.1 0.9,0.2 0.2)),
    TRIANGLE((0.9 0.9,1.0 1.0,0.1 0.9,0.9 0.9)),
    TRIANGLE((0.2 0.2,0.9 0.1,0.8 0.2,0.2 0.2)),
    TRIANGLE((0.8 0.8,0.9 0.9,0.2 0.8,0.8 0.8)),
    TRIANGLE((0.9 0.1,0.9 0.9,0.8 0.2,0.9 0.1)),
    TRIANGLE((0.8 0.2,0.9 0.9,0.8 0.8,0.8 0.2)),
    TRIANGLE((0.9 0.1,1.0 1.0,0.9 0.9,0.9 0.1)),
    TRIANGLE((1.0 0.0,1.0 1.0,0.9 0.1,1.0 0.0)))""")
    assert tesselation.covers(geom2)
예제 #14
0
def wkt_leak():
    while True:
        p = read_wkt("POINT (1 2)")
        p.wkt
예제 #15
0
def test_wkt_write(geometry):
    geom = sfcgal.shape(geometry)
    wkt = geom.wkt
    assert wkt
    data = sfcgal.mapping(sfcgal.read_wkt(wkt))
    assert geometry == data