Exemplo n.º 1
0
def test_ST_Contains():
    p11 = "POLYGON((0 0,1 0,1 1,0 1,0 0))"
    p12 = "POLYGON((8 0,9 0,9 1,8 1,8 0))"
    p13 = "POINT(2 2)"
    p14 = "POINT(200 2)"
    data1 = pandas.Series([p11, p12, p13, p14])

    p21 = "POLYGON((0 0,0 8,8 8,8 0,0 0))"
    p22 = "POLYGON((0 0,0 8,8 8,8 0,0 0))"
    p23 = "POLYGON((0 0,0 8,8 8,8 0,0 0))"
    p24 = "POLYGON((0 0,0 8,8 8,8 0,0 0))"
    data2 = pandas.Series([p21, p22, p23, p24])
    rst = arctern.ST_Contains(arctern.ST_GeomFromText(data2),
                              arctern.ST_GeomFromText(data1))
    assert len(rst) == 4
    assert rst[0] == 1
    assert rst[1] == 0
    assert rst[2] == 1
    assert rst[3] == 0

    rst = arctern.ST_Contains(
        arctern.ST_GeomFromText(data2),
        arctern.ST_GeomFromText("POLYGON((0 0,0 8,8 8,8 0,0 0))")[0])
    assert len(rst) == 4
    assert rst[0] == 1
    assert rst[1] == 1
    assert rst[2] == 1
    assert rst[3] == 1

    rst = arctern.ST_Contains(
        arctern.ST_GeomFromText("POLYGON((0 0,0 8,8 8,8 0,0 0))")[0],
        arctern.ST_GeomFromText(data1))
    assert len(rst) == 4
    assert rst[0] == 1
    assert rst[1] == 0
    assert rst[2] == 1
    assert rst[3] == 0

    rst = arctern.ST_Contains(
        arctern.ST_GeomFromText("POLYGON((0 0,0 8,8 8,8 0,0 0))")[0],
        arctern.ST_GeomFromText("POLYGON((0 0,0 8,8 8,8 0,0 0))")[0])
    assert len(rst) == 1
    assert rst[0] == 1
Exemplo n.º 2
0
    def fillna(self, value=None, method=None, limit=None):
        from pandas.util._validators import validate_fillna_kwargs
        value, method = validate_fillna_kwargs(value, method)

        mask = self.isna()
        from pandas.api.types import is_array_like, infer_dtype
        if is_array_like(value):
            if len(value) != len(self):
                raise ValueError(
                    f"Length of 'value' does not match. Got ({len(value)}) "
                    f"expected {len(self)}")
            value = value[mask]
        else:
            # because pandas infer_type(scalar) cant work on scalar value, we put the value into a list
            value = [value]
        if mask.any():
            if method is not None:
                from pandas.core.missing import pad_1d
                from pandas.core.missing import backfill_1d
                func = pad_1d if method == "pad" else backfill_1d
                new_values = func(self.astype(object), limit=limit, mask=mask)
                new_values = self._from_sequence(new_values, dtype=self.dtype)
                # raise NotImplementedError("not support fillna with method")
            else:
                # translate value
                if not isinstance(getattr(value, "dtype", value),
                                  (GeoDtype, type(None))):
                    inferred_type = infer_dtype(value, skipna=True)
                    if inferred_type == "string":
                        value = arctern.ST_GeomFromText(value)
                    elif inferred_type == "bytes":
                        pass
                    else:
                        raise ValueError(
                            "can only fillna with wkt formed string or wkb formed bytes"
                        )

                # fill with value
                new_values = self.copy()
                new_values[mask] = value
        else:
            new_values = self.copy()
        return new_values
Exemplo n.º 3
0
    def __init__(self, data=None, index=None, name=None, crs=None, **kwargs):

        if hasattr(data, "crs") and crs:
            if not data.crs:
                data = data.copy()
            elif not data.crs == crs:
                raise ValueError(
                    "csr of the passed geometry data is different from crs.")
        # scalar wkb or wkt
        if isinstance(data, (bytes, str)):
            n = len(index) if index is not None else 1
            data = [data] * n

        if not is_geometry_array(data):
            s = Series(data, index=index, name=name, **kwargs)
            index = s.index
            name = s.name

            from pandas.api.types import is_object_dtype, is_float_dtype
            # The default dtype for empty Series is 'float64' in pandas
            if not is_geometry_array(s):
                if is_float_dtype(s.dtype) and s.empty:
                    s = s.astype(object)
                # make sure missing value is None
                s[s.isna()] = None
                from pandas.api.types import infer_dtype
                inferred = infer_dtype(s, skipna=True)
                if inferred in ("bytes", "empty"):
                    pass
                elif inferred == "string":
                    s = arctern.ST_GeomFromText(s)
                else:
                    raise TypeError(
                        "Can not use no bytes or string data to construct GeoSeries."
                    )
            data = GeoArray(s.values)

        super().__init__(data, index=index, name=name, **kwargs)

        self._crs = None
        self.set_crs(crs)
Exemplo n.º 4
0
def test_ST_Envelope():
    p1 = "point (10 10)"
    p2 = "linestring (0 0 , 0 10)"
    p3 = "linestring (0 0 , 10 0)"
    p4 = "linestring (0 0 , 10 10)"
    p5 = "polygon ((0 0, 10 0, 10 10, 0 10, 0 0))"
    p6 = "multipoint (0 0, 10 0, 5 5)"
    p7 = "multilinestring ((0 0, 5 5), (6 6, 6 7, 10 10))"
    p8 = "multipolygon (((0 0, 10 0, 10 10, 0 10, 0 0), (11 11, 20 11, 20 20, 20 11, 11 11)))"
    data = [p1, p2, p3, p4, p5, p6, p7, p8]
    data = pandas.Series(data)
    rst = arctern.ST_AsText(arctern.ST_Envelope(arctern.ST_GeomFromText(data)))

    assert rst[0] == "POINT (10 10)"
    assert rst[1] == "LINESTRING (0 0,0 10)"
    assert rst[2] == "LINESTRING (0 0,10 0)"
    assert rst[3] == "POLYGON ((0 0,0 10,10 10,10 0,0 0))"
    assert rst[4] == "POLYGON ((0 0,0 10,10 10,10 0,0 0))"
    assert rst[5] == "POLYGON ((0 0,0 5,10 5,10 0,0 0))"
    assert rst[6] == "POLYGON ((0 0,0 10,10 10,10 0,0 0))"
    assert rst[7] == "POLYGON ((0 0,0 20,20 20,20 0,0 0))"
Exemplo n.º 5
0
def test_ST_Equals():
    data1 = pandas.Series(["POLYGON ((1 1,1 2,2 2,2 1,1 1))", "POLYGON ((1 1,1 2,2 2,2 1,1 1))"])
    data2 = pandas.Series(["POLYGON ((1 1,1 2,2 2,2 1,1 1))", "POLYGON ((2 1,3 1,3 2,2 2,2 1))"])
    rst = arctern.ST_Equals(arctern.ST_GeomFromText(data1), arctern.ST_GeomFromText(data2))
    assert len(rst) == 2
    assert rst[0] == 1
    assert rst[1] == 0

    rst = arctern.ST_Equals(arctern.ST_GeomFromText(data2),
                            arctern.ST_GeomFromText("POLYGON ((1 1,1 2,2 2,2 1,1 1))")[0])
    assert len(rst) == 2
    assert rst[0] == 1
    assert rst[1] == 0

    rst = arctern.ST_Equals(arctern.ST_GeomFromText("POLYGON ((1 1,1 2,2 2,2 1,1 1))")[0],
                            arctern.ST_GeomFromText(data2))
    assert len(rst) == 2
    assert rst[0] == 1
    assert rst[1] == 0

    rst = arctern.ST_Equals(arctern.ST_GeomFromText("POLYGON ((1 1,1 2,2 2,2 1,1 1))")[0],
                            arctern.ST_GeomFromText("POLYGON ((1 1,1 2,2 2,2 1,1 1))")[0])
    assert len(rst) == 1
    assert rst[0] == 1
Exemplo n.º 6
0
def test_plot8():
    raw_data = []
    raw_data.append('point(0 0)')
    raw_data.append('linestring(0 10, 5 5, 10 0)')
    raw_data.append('polygon((2 2,2 3,3 3,3 2,2 2))')
    raw_data.append("GEOMETRYCOLLECTION(" \
                    "polygon((1 1,1 2,2 2,2 1,1 1))," \
                    "linestring(0 1, 5 6, 10 11)," \
                    "POINT(4 7))")

    arr_wkt = pandas.Series(raw_data)
    arr_wkb = arctern.ST_CurveToLine(arctern.ST_GeomFromText(arr_wkt))

    file_name = "/tmp/test_plot8.png"

    if os.path.exists(file_name):
        os.remove(file_name)

    if os.path.exists(file_name):
        assert False

    fig, ax = plt.subplots()
    arctern.plot.plot_geometry(ax,
                               arr_wkb,
                               color=['orange', 'green'],
                               marker='^',
                               markersize=100,
                               alpha=0.6,
                               linewidth=[None, 7, 8],
                               linestyle=[None, 'dashed', 'dashdot'],
                               edgecolor=[None, None, 'red'],
                               facecolor=[None, None, 'black'])
    ax.grid()
    fig.savefig(file_name)
    file_size = os.path.getsize(file_name)
    file_size = file_size / 1024
    # print(file_size)
    assert 20 <= file_size <= 30
Exemplo n.º 7
0
def test_plot5():
    raw_data = []
    raw_data.append('circularstring(-2 -2, 2 2, -2 -2)')
    raw_data.append('circularstring(-1 -1, 1 1, -1 -1)')

    arr_wkt = pandas.Series(raw_data)
    arr_wkb = arctern.ST_CurveToLine(arctern.ST_GeomFromText(arr_wkt))

    file_name = "/tmp/test_plot5.png"

    if os.path.exists(file_name):
        os.remove(file_name)

    if os.path.exists(file_name):
        assert False

    fig, ax = plt.subplots()
    arctern.plot.plot_geometry(ax, arr_wkb)
    ax.grid()
    fig.savefig(file_name)
    file_size = os.path.getsize(file_name)
    file_size = file_size / 1024
    assert 25 <= file_size <= 35
Exemplo n.º 8
0
def test_ST_MakeValid():
    data = pandas.Series(["POLYGON ((2 1,3 1,3 2,2 2,2 8,2 1))"])
    rst = arctern.ST_AsText(arctern.ST_MakeValid(
        arctern.ST_GeomFromText(data)))
    assert rst[
        0] == "GEOMETRYCOLLECTION (POLYGON ((2 2,3 2,3 1,2 1,2 2)),LINESTRING (2 2,2 8))"
Exemplo n.º 9
0
def test_ST_GeometryType():
    data = pandas.Series(
        ["POLYGON ((1 1,1 2,2 2,2 1,1 1))", "POLYGON ((1 1,1 2,2 2,2 1,1 1))"])
    rst = arctern.ST_GeometryType(arctern.ST_GeomFromText(data))
    assert rst[0] == "ST_POLYGON"
    assert rst[1] == "ST_POLYGON"
Exemplo n.º 10
0
def test_ST_ConvexHull():
    data = ["POINT (1.1 101.1)"]
    data = pandas.Series(data)
    rst = arctern.ST_AsText(arctern.ST_ConvexHull(arctern.ST_GeomFromText(data)))

    assert rst[0] == "POINT (1.1 101.1)"
Exemplo n.º 11
0
 def test_series(self):
     p1 = "POLYGON ((0 0,4 0,4 4,0 4,0 0))"
     p2 = "POLYGON ((5 1,7 1,7 2,5 2,5 1))"
     data = pandas.Series([p1, p2])
     rst = arctern.ST_AsText(arctern.ST_Envelope_Aggr(arctern.ST_GeomFromText(data)))
     assert rst[0] == "POLYGON ((0 0,0 4,7 4,7 0,0 0))"
Exemplo n.º 12
0
def test_near_road():
    roads = pandas.Series(["LINESTRING (0 0,2 0)", "LINESTRING (5 0,5 5)"])
    gps_points = pandas.Series("POINT (1.0001 0.0001)")
    rst = arctern.near_road(arctern.ST_GeomFromText(roads), arctern.ST_GeomFromText(gps_points), 100)
    assert len(rst) == 1
    assert rst[0]
def python_test(data):
    TIME_START(func_name)
    arctern.ST_AsText(arctern.ST_PrecisionReduce(arctern.ST_GeomFromText(data), 3))
    TIME_END(func_name)

    return TIME_INFO()
Exemplo n.º 14
0
def python_test(data):
    TIME_START(func_name)
    arctern.ST_AsText(arctern.ST_Envelope_Aggr(arctern.ST_GeomFromText(data)))
    TIME_END(func_name)

    return TIME_INFO()
Exemplo n.º 15
0
def test_ST_Envelope():
    geo = "POLYGON ((0 0,0 1,1 1,1 0,0 0))"
    arr = [geo for x in range(1, 10000001)]
    data = pandas.Series(arr)
    rst = arctern.ST_AsText(arctern.ST_Envelope(arctern.ST_GeomFromText(data)))
    assert len(rst) == 10000000
Exemplo n.º 16
0
def python_test(data):
    TIME_START("st_buffer")
    arctern.ST_AsText(arctern.ST_Buffer(arctern.ST_GeomFromText(data), 1.2))
    TIME_END("st_buffer")
    return TIME_INFO()
Exemplo n.º 17
0
def test_ST_CurveToLine():
    data = ["CURVEPOLYGON(CIRCULARSTRING(0 0, 4 0, 4 4, 0 4, 0 0))"]
    data = pandas.Series(data)
    rst = arctern.ST_AsText(arctern.ST_CurveToLine(arctern.ST_GeomFromText(data)))

    assert str(rst[0]).startswith("POLYGON")
Exemplo n.º 18
0
def test_ST_PrecisionReduce():
    data = pandas.Series(["POINT (1.333 2.666)", "POINT (2.655 4.447)"])
    rst = arctern.ST_AsText(
        arctern.ST_PrecisionReduce(arctern.ST_GeomFromText(data), 3))
    assert rst[0] == "POINT (1.33 2.67)"
    assert rst[1] == "POINT (2.66 4.45)"
Exemplo n.º 19
0
def test_ST_NPoints():
    data = ["LINESTRING(1 1,1 4)"]
    data = pandas.Series(data)
    rst = arctern.ST_NPoints(arctern.ST_GeomFromText(data))

    assert rst[0] == 2
def python_test(data1, data2):
    TIME_START(func_name)
    arctern.ST_DistanceSphere(arctern.ST_GeomFromText(data1),
                              arctern.ST_GeomFromText(data2))
    TIME_END(func_name)
    return TIME_INFO()
Exemplo n.º 21
0
def python_test(data):
    TIME_START(func_name)
    arctern.ST_Length(arctern.ST_GeomFromText(data))
    TIME_END(func_name)

    return TIME_INFO()
Exemplo n.º 22
0
def ST_GeomFromText(geo):
    return arctern.ST_GeomFromText(geo)
Exemplo n.º 23
0
def test_nearest_location_on_road():
    roads = pandas.Series("LINESTRING (1 2,1 3)")
    gps_points = pandas.Series("POINT (1.0001 2.5)")
    rst = arctern.ST_AsText(arctern.nearest_location_on_road(arctern.ST_GeomFromText(roads), arctern.ST_GeomFromText(gps_points)))
    assert len(rst) == 1
    assert rst[0] == "POINT (1.0 2.5)"
Exemplo n.º 24
0
def python_test(data):
    TIME_START(func_name)
    arctern.ST_AsText(arctern.ST_MakeValid(arctern.ST_GeomFromText(data)))
    TIME_END(func_name)

    return TIME_INFO()
Exemplo n.º 25
0
def ST_LineStringFromText(geo):
    return arctern.ST_GeomFromText(geo)
Exemplo n.º 26
0
 def test_tuple(self):
     p1 = "POLYGON ((0 0,4 0,4 4,0 4,0 0))"
     p2 = "POLYGON ((5 1,7 1,7 2,5 2,5 1))"
     data = (p1, p2)
     rst = arctern.ST_AsText(arctern.ST_Envelope_Aggr(arctern.ST_GeomFromText(data)))
     assert rst[0] == "POLYGON ((0 0,0 4,7 4,7 0,0 0))"
Exemplo n.º 27
0
def test_ST_IsValid():
    data = pandas.Series(["POINT (1.3 2.6)", "POINT (2.6 4.7)"])
    rst = arctern.ST_IsValid(arctern.ST_GeomFromText(data))
    assert rst[0]
    assert rst[1]
Exemplo n.º 28
0
def test_ST_IsSimple():
    data = pandas.Series(
        ["POLYGON ((1 1,1 2,2 2,2 1,1 1))", "POLYGON ((1 1,1 2,2 2,2 1,1 1))"])
    rst = arctern.ST_IsSimple(arctern.ST_GeomFromText(data))
    assert rst[0] == 1
    assert rst[1] == 1
Exemplo n.º 29
0
def python_test(data1, data2):
    TIME_START(func_name)
    arctern.ST_Overlaps(arctern.ST_GeomFromText(data1), arctern.ST_GeomFromText(data2))
    TIME_END(func_name)

    return TIME_INFO()
Exemplo n.º 30
0
def test_ST_SimplifyPreserveTopology():
    data = pandas.Series(["POLYGON ((1 1,1 2,2 2,2 1,1 1))", "POLYGON ((1 1,1 2,2 2,2 1,1 1))"])
    rst = arctern.ST_AsText(arctern.ST_SimplifyPreserveTopology(
        arctern.ST_GeomFromText(data), 10000))
    assert rst[0] == "POLYGON ((1 1,1 2,2 2,2 1,1 1))"