Esempio n. 1
0
def test_from_wkt(string_type):
    if string_type == "str":
        f = six.text_type
    else:
        if six.PY3:

            def f(x):
                return bytes(x, "utf8")

        else:

            def f(x):
                return x

    # list
    L_wkt = [f(p.wkt) for p in points_no_missing]
    res = from_wkt(L_wkt)
    assert isinstance(res, GeometryArray)
    assert all(v.almost_equals(t) for v, t in zip(res, points_no_missing))

    # array
    res = from_wkt(np.array(L_wkt, dtype=object))
    assert isinstance(res, GeometryArray)
    assert all(v.almost_equals(t) for v, t in zip(res, points_no_missing))

    # missing values
    L_wkt.extend([f(""), None])
    res = from_wkt(L_wkt)
    assert res[-1] is None
    assert res[-2] is None
Esempio n. 2
0
def test_from_wkt(string_type):
    if string_type == "str":
        f = six.text_type
    else:
        if six.PY3:

            def f(x):
                return bytes(x, "utf8")

        else:

            def f(x):
                return x

    # list
    L_wkt = [f(p.wkt) for p in points_no_missing]
    res = from_wkt(L_wkt)
    assert isinstance(res, GeometryArray)
    tol = 0.5 * 10**(-6)
    assert all(
        v.equals_exact(t, tolerance=tol)
        for v, t in zip(res, points_no_missing))
    assert all(
        v.equals_exact(t, tolerance=tol)
        for v, t in zip(res, points_no_missing))

    # array
    res = from_wkt(np.array(L_wkt, dtype=object))
    assert isinstance(res, GeometryArray)
    assert all(
        v.equals_exact(t, tolerance=tol)
        for v, t in zip(res, points_no_missing))

    # missing values
    # TODO(pygeos) does not support empty strings, np.nan, or pd.NA
    missing_values = [None]
    if not compat.USE_PYGEOS:
        missing_values.extend([f(""), np.nan])

        if compat.PANDAS_GE_10:
            missing_values.append(pd.NA)

    res = from_wkb(missing_values)
    np.testing.assert_array_equal(res, np.full(len(missing_values), None))

    # single MultiPolygon
    multi_poly = shapely.geometry.MultiPolygon(
        [shapely.geometry.box(0, 0, 1, 1),
         shapely.geometry.box(3, 3, 4, 4)])
    res = from_wkt([f(multi_poly.wkt)])
    assert res[0] == multi_poly
Esempio n. 3
0
def test_from_wkt(string_type):
    if string_type == "str":
        f = six.text_type
    else:
        if six.PY3:

            def f(x):
                return bytes(x, "utf8")

        else:

            def f(x):
                return x

    # list
    L_wkt = [f(p.wkt) for p in points_no_missing]
    res = from_wkt(L_wkt)
    assert isinstance(res, GeometryArray)
    assert all(v.almost_equals(t) for v, t in zip(res, points_no_missing))

    # array
    res = from_wkt(np.array(L_wkt, dtype=object))
    assert isinstance(res, GeometryArray)
    assert all(v.almost_equals(t) for v, t in zip(res, points_no_missing))

    # missing values
    # TODO(pygeos) does not support empty strings
    if compat.USE_PYGEOS:
        L_wkt.extend([None])
    else:
        L_wkt.extend([f(""), None])
    res = from_wkt(L_wkt)
    assert res[-1] is None
    if not compat.USE_PYGEOS:
        assert res[-2] is None

    # single MultiPolygon
    multi_poly = shapely.geometry.MultiPolygon(
        [shapely.geometry.box(0, 0, 1, 1), shapely.geometry.box(3, 3, 4, 4)]
    )
    res = from_wkt([f(multi_poly.wkt)])
    assert res[0] == multi_poly
Esempio n. 4
0
 def test_from_wkt(self):
     L_wkt = [p.wkt for p in self.geoms]
     arr = from_wkt(L_wkt, crs=27700)
     assert arr.crs == self.osgb