コード例 #1
0
ファイル: plot_test.py プロジェクト: zeroseekyou/arctern
def test_plot2():
    raw_data = []
    raw_data.append('point(0 0)')
    raw_data.append('point(1 1)')
    raw_data.append('point(2 2)')

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

    file_name = "/tmp/test_plot2.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(ax,
                 arr_wkb,
                 color=['red', 'blue', 'black'],
                 marker='^',
                 markersize=100)
    ax.grid()
    fig.savefig(file_name)
    file_size = os.path.getsize(file_name)
    file_size = file_size / 1024
    assert 10 <= file_size <= 15
コード例 #2
0
ファイル: plot_test.py プロジェクト: zeroseekyou/arctern
def test_plot3():
    raw_data = []
    raw_data.append('linestring(0 0, 5 5, 10 10)')
    raw_data.append('linestring(0 10, 5 5, 10 0)')
    raw_data.append('linestring(0 1, 5 6, 10 11)')
    raw_data.append('linestring(0 11, 5 6, 10 1)')

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

    file_name = "/tmp/test_plot3.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(ax,
                 arr_wkb,
                 color=['green', 'red', 'black', 'orange'],
                 linewidth=[5, 6, 7, 8],
                 linestyle=['solid', 'dashed', 'dashdot', 'dotted'])
    ax.grid()
    fig.savefig(file_name)
    file_size = os.path.getsize(file_name)
    file_size = file_size / 1024
    assert 30 <= file_size <= 50
コード例 #3
0
ファイル: plot_test.py プロジェクト: zeroseekyou/arctern
def test_plot1():
    raw_data = []
    raw_data.append('polygon((0 0,0 1,1 1,1 0,0 0))')
    raw_data.append('linestring(0 0,0 1,1 1,1 0,0 0)')
    raw_data.append('point(2 2)')
    raw_data.append("GEOMETRYCOLLECTION(" \
                    "MULTIPOLYGON (((0 0,0 1,1 1,1 0,0 0)),((1 1,1 2,2 2,2 1,1 1)))," \
                    "POLYGON((3 3,3 4,4 4,4 3,3 3))," \
                    "LINESTRING(0 8,5 5,8 0)," \
                    "POINT(4 7)," \
                    "MULTILINESTRING ((1 1,1 2),(2 4,1 9,1 8))," \
                    "MULTIPOINT (6 8,5 7)" \
                    ")")
    arr_wkt = pandas.Series(raw_data)
    arr_wkb = arctern.ST_GeomFromText(arr_wkt)

    file_name = "/tmp/test_plot1.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(ax, arr_wkb)
    ax.grid()
    fig.savefig(file_name)
    file_size = os.path.getsize(file_name)
    file_size = file_size / 1024
    assert 15 <= file_size <= 25
コード例 #4
0
ファイル: plot_test.py プロジェクト: zeroseekyou/arctern
def test_plot4():
    raw_data = []
    raw_data.append('polygon((0 0,0 1,1 1,1 0,0 0))')
    raw_data.append('polygon((1 1,1 2,2 2,2 1,1 1))')
    raw_data.append('polygon((2 2,2 3,3 3,3 2,2 2))')
    raw_data.append('polygon((3 3,3 4,4 4,4 3,3 3))')

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

    file_name = "/tmp/test_plot4.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(ax,
                 arr_wkb,
                 edgecolor=['green', 'red', 'black', 'orange'],
                 linewidth=[5, 6, 7, 8],
                 linestyle=['solid', 'dashed', 'dashdot', 'dotted'],
                 facecolor=['red', 'black', 'orange', 'green'])
    ax.grid()
    fig.savefig(file_name)
    file_size = os.path.getsize(file_name)
    file_size = file_size / 1024
    assert 10 <= file_size <= 20
コード例 #5
0
ファイル: plot_test.py プロジェクト: zeroseekyou/arctern
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(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
コード例 #6
0
ファイル: plot_test.py プロジェクト: zeroseekyou/arctern
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(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
コード例 #7
0
def plot(ax, geoms, **style_kwds):
    """
    Plot a collection of geometries to `ax`. Parameters 'linewidth', 'linestyle', 'edgecolor',
    'facecolor', 'color', 'marker', 'markersize' are used to describe the style of plotted figure.

    For geometry types `Polygon` and `MultiPolygon`, only 'linewidth', 'linestyle', 'edgecolor',
    'facecolor' are effective.

    For geometry types `Linestring` and `MultiLinestring`, only 'color', 'linewidth', 'linestyle' are effective.

    For geometry types `Point` and `MultiPoint`, only 'color', 'marker', 'markersize' are effective.

    :type ax: matplotlib.axes.Axes
    :param ax: The axes where geometries will be plotted.

    :type geoms: Series or DataFrame
    :param geoms: sequence of geometries.

    :type linewidth: list(float)
    :param linewidth: The width of line, the default value is 1.0.

    :type linestyle: list(string)
    :param linestyle: The style of the line, the default value is '-'.

    :type edgecolor: list(string)
    :param edgecolor: The edge color of the geometry, the default value is 'black'.

    :type facecolor: list(string)
    :param facecolor: The color of the face of the geometry, the default value is 'C0'.

    :type color: list(string)
    :param color: The color of the geometry, the default value is 'C0'.

    :type marker: string
    :param marker: The shape of point, the default value is 'o'.

    :type markersize: double
    :param markersize: The size of points, the default value is 6.0.

    :example:
       >>> from arctern_pyspark import register_funcs
       >>> from pyspark.sql.types import *
       >>> import matplotlib.pyplot as plt
       >>> from arctern_pyspark import plot
       >>> spark.conf.set("spark.sql.execution.arrow.pyspark.enabled", "true")
       >>> 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))",))
       >>> raw_schema = StructType([StructField('geo', StringType(),False)])
       >>> df = spark.createDataFrame(data=raw_data, schema=raw_schema)
       >>> df.createOrReplaceTempView("geoms")
       >>> df2=spark.sql("select st_geomfromtext(geo) from geoms")
       >>> fig, ax = plt.subplots()
       >>> plot(ax, df2,
                 color=['orange', 'green'],
                 marker='^',
                 markersize=100,
                 linewidth=[None, 7, 8],
                 linestyle=[None, 'dashed', 'dashdot'],
                 edgecolor=[None, None, 'red'],
                 facecolor=[None, None, 'black'])
       >>> ax.grid()
       >>> fig.savefig('/tmp/plot_test.png')
    """
    import pyspark.sql.dataframe
    import arctern
    if isinstance(geoms, pyspark.sql.dataframe.DataFrame):
        pandas_df = geoms.toPandas()
        arctern.plot(ax, pandas_df, **style_kwds)
コード例 #8
0
def plot(ax, geoms):
    import pyspark.sql.dataframe
    import arctern
    if isinstance(geoms, pyspark.sql.dataframe.DataFrame):
        pandas_df = geoms.toPandas()
        arctern.plot(ax, pandas_df)