예제 #1
0
from pandas.testing import assert_series_equal
from spatialpandas import GeoSeries
from tests.geometry.strategies import (st_multipoint_array, st_bounds,
                                       st_line_array, st_multiline_array,
                                       st_polygon_array, st_multipolygon_array,
                                       hyp_settings, st_point_array)


@given(st_point_array(geoseries=True))
@hyp_settings
def test_point_array_to_geopandas(gp_point):
    result = GeoSeries(gp_point, dtype='point').to_geopandas()
    assert_series_equal(result, gp_point)


@given(st_multipoint_array(geoseries=True))
@hyp_settings
def test_multipoint_array_to_geopandas(gp_multipoint):
    result = GeoSeries(gp_multipoint, dtype='multipoint').to_geopandas()
    assert_series_equal(result, gp_multipoint)


@given(st_line_array(geoseries=True))
@hyp_settings
def test_line_array_to_geopandas(gp_line):
    result = GeoSeries(gp_line, dtype='line').to_geopandas()
    assert_series_equal(result, gp_line)


@given(st_multiline_array(geoseries=True))
@hyp_settings
예제 #2
0
    result = points.intersects_bounds(rect)
    np.testing.assert_equal(result, expected)

    # Test MultiPointArray.intersects_rect with inds
    inds = np.flipud(np.arange(0, len(points)))
    result = points.intersects_bounds(rect, inds)
    np.testing.assert_equal(result, np.flipud(expected))

    # Test MultiPoint.intersects_rect
    result = np.array([
        point.intersects_bounds(rect) for point in points
    ])
    np.testing.assert_equal(result, expected)


@given(st_multipoint_array(), st_bounds())
@hyp_settings
def test_multipoint_intersects_rect(gp_multipoint, rect):
    sg_rect = sg.box(*rect)
    expected = gp_multipoint.intersects(sg_rect)
    multipoints = MultiPointArray.from_geopandas(gp_multipoint)

    # Test MultiPointArray.intersects_rect
    result = multipoints.intersects_bounds(rect)
    np.testing.assert_equal(result, expected)

    # Test MultiPointArray.intersects_rect with inds
    inds = np.flipud(np.arange(0, len(multipoints)))
    result = multipoints.intersects_bounds(rect, inds)
    np.testing.assert_equal(result, np.flipud(expected))
예제 #3
0
def get_slices(v0, v1):
    return [slice(v0, v1), slice(None, v1), slice(v0, None), slice(None, None)]


@given(st_point_array(min_size=1, geoseries=True), st_bounds(orient=True))
@hyp_settings
def test_multipoint_cx_selection(gp_point, rect):
    x0, y0, x1, y1 = rect
    for xslice in get_slices(x0, x1):
        for yslice in get_slices(y0, y1):
            expected = PointArray.from_geopandas(gp_point.cx[xslice, yslice])
            result = PointArray.from_geopandas(gp_point).cx[xslice, yslice]
            assert all(expected == result)


@given(st_multipoint_array(min_size=1, geoseries=True), st_bounds(orient=True))
@hyp_settings
def test_multipoint_cx_selection(gp_multipoint, rect):
    x0, y0, x1, y1 = rect
    for xslice in get_slices(x0, x1):
        for yslice in get_slices(y0, y1):
            expected = MultiPointArray.from_geopandas(gp_multipoint.cx[xslice, yslice])
            result = MultiPointArray.from_geopandas(gp_multipoint).cx[xslice, yslice]
            assert all(expected == result)


@given(st_line_array(min_size=1, geoseries=True), st_bounds(orient=True))
@hyp_settings
def test_line_cx_selection(gp_line, rect):
    x0, y0, x1, y1 = rect
    for xslice in get_slices(x0, x1):
예제 #4
0
    # Create spatialpandas PointArray
    point = Point.from_shapely(sg_point)
    points = PointArray.from_geopandas(gp_points)[offset:]

    # Test PointArray.intersect
    result = points.intersects(point)
    np.testing.assert_equal(result, expected)

    # Test PointArray.intersects with inds
    inds = np.flipud(np.arange(0, len(points)))
    result = points.intersects(point, inds)
    np.testing.assert_equal(result, np.flipud(expected))


@given(st_point_array(), st_multipoint_array(min_size=1, max_size=1))
@hyp_settings
def test_points_intersects_multipoint(gp_points, gp_multipoint):
    # Get scalar Point
    sg_multipoint = gp_multipoint[0]
    if len(gp_points) > 0:
        # Add gp_point to gp_multipoints so we know something will intersect
        gp_points = from_shapely(list(gp_points) + [gp_multipoint[0][-1]])

    # Compute expected intersection
    expected = gp_points.intersects(sg_multipoint)

    # Create spatialpandas PointArray
    multipoint = MultiPoint.from_shapely(sg_multipoint)
    points = PointArray.from_geopandas(gp_points)
    points_series = GeoSeries(points, index=np.arange(10, 10 + len(points)))
예제 #5
0
import dask.dataframe as dd
import pandas as pd
from spatialpandas import GeoSeries, GeoDataFrame
from spatialpandas.dask import DaskGeoDataFrame
from tests.geometry.strategies import (st_multipoint_array, st_multiline_array,
                                       st_point_array)
import numpy as np
from spatialpandas.io import (to_parquet, read_parquet, read_parquet_dask,
                              to_parquet_dask)

hyp_settings = settings(deadline=None, max_examples=100)


@given(
    gp_point=st_point_array(min_size=1, geoseries=True),
    gp_multipoint=st_multipoint_array(min_size=1, geoseries=True),
    gp_multiline=st_multiline_array(min_size=1, geoseries=True),
)
@hyp_settings
def test_parquet(gp_point, gp_multipoint, gp_multiline, tmp_path):
    # Build dataframe
    n = min(len(gp_multipoint), len(gp_multiline))
    df = GeoDataFrame({
        'point': GeoSeries(gp_point[:n]),
        'multipoint': GeoSeries(gp_multipoint[:n]),
        'multiline': GeoSeries(gp_multiline[:n]),
        'a': list(range(n))
    })

    path = tmp_path / 'df.parq'
    to_parquet(df, path)
예제 #6
0
from tests.geometry.strategies import (st_multipoint_array, st_multiline_array,
                                       st_point_array, st_bounds)
import numpy as np
from spatialpandas.io import (to_parquet, read_parquet, read_parquet_dask,
                              to_parquet_dask)

dask.config.set(scheduler="single-threaded")

hyp_settings = settings(deadline=None,
                        max_examples=100,
                        suppress_health_check=[HealthCheck.too_slow])


@given(
    gp_point=st_point_array(min_size=1, geoseries=True),
    gp_multipoint=st_multipoint_array(min_size=1, geoseries=True),
    gp_multiline=st_multiline_array(min_size=1, geoseries=True),
)
@hyp_settings
def test_parquet(gp_point, gp_multipoint, gp_multiline, tmp_path):
    # Build dataframe
    n = min(len(gp_multipoint), len(gp_multiline))
    df = GeoDataFrame({
        'point': GeoSeries(gp_point[:n]),
        'multipoint': GeoSeries(gp_multipoint[:n]),
        'multiline': GeoSeries(gp_multiline[:n]),
        'a': list(range(n))
    })

    df.index.name = 'range_idx'