Exemplo n.º 1
0
from hypothesis import given
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))
Exemplo n.º 2
0
@given(st_polygon(), st_points)
@hyp_settings
def test_point_intersects_polygon(sg_polygon, points):
    polygon = Polygon.from_shapely(sg_polygon)

    for r in range(points.shape[0]):
        x, y = points[r, :]
        result = point_intersects_polygon(
            x, y, polygon.buffer_values, polygon.buffer_inner_offsets
        )

        expected = sg_polygon.intersects(sg.Point([x, y]))
        assert expected == result


@given(st_point_array(), st_bounds())
@hyp_settings
def test_point_intersects_rect(gp_point, rect):
    sg_rect = sg.box(*rect)
    expected = gp_point.intersects(sg_rect)
    points = PointArray.from_geopandas(gp_point)

    # Test MultiPointArray.intersects_rect
    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))
Exemplo n.º 3
0
import dask.dataframe as dd
from spatialpandas import GeoSeries, GeoDataFrame
from spatialpandas.geometry import (
    MultiPointArray, LineArray, MultiLineArray, PolygonArray, MultiPolygonArray,
    PointArray)
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)


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):
Exemplo n.º 4
0
import shapely.geometry as sg
import numpy as np
import pandas as pd
from geopandas.array import from_shapely
from hypothesis import given, example, strategies as st
from spatialpandas import GeoSeries
from spatialpandas.geometry import PointArray, Point, MultiPoint, Line, MultiLine, \
    Polygon, MultiPolygon
from tests.geometry.strategies import st_point_array, st_multipoint_array, hyp_settings, \
    st_line_array, st_polygon_array, st_multipolygon_array


@given(st_point_array(), st_point_array(min_size=1, max_size=1))
@hyp_settings
def test_points_intersects_point(gp_points, gp_point):
    # Get scalar Point
    sg_point = gp_point[0]
    if len(gp_points) > 0:
        # Add gp_point to gp_points so we know something will intersect
        gp_points = pd.concat([pd.Series(gp_points),
                               pd.Series(gp_point)]).array

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

    # Create spatialpandas PointArray
    point = Point.from_shapely(sg_point)
    points = PointArray.from_geopandas(gp_points)
    points_series = GeoSeries(points, index=np.arange(10, 10 + len(points)))

    # Test Point.intersects
Exemplo n.º 5
0
from hypothesis import given, settings
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'
Exemplo n.º 6
0
import numpy as np
import pandas as pd
import geopandas as gp
import pytest
import dask.dataframe as dd
from hypothesis import given
import hypothesis.strategies as hs

import spatialpandas as sp
from spatialpandas import GeoDataFrame
from spatialpandas.dask import DaskGeoDataFrame
from tests.geometry.strategies import st_point_array, st_polygon_array
from tests.test_parquet import hyp_settings


@given(st_point_array(min_size=1, geoseries=True),
       st_polygon_array(min_size=1, geoseries=True),
       hs.sampled_from(["inner", "left", "right"]))
@hyp_settings
def test_sjoin(gp_points, gp_polygons, how):
    # join with geopandas
    left_gpdf = gp.GeoDataFrame({
        'geometry': gp_points,
        'a': np.arange(10, 10 + len(gp_points)),
        'c': np.arange(20, 20 + len(gp_points)),
        'v': np.arange(30, 30 + len(gp_points)),
    }).set_index('a')

    right_gpdf = gp.GeoDataFrame({
        'geometry': gp_polygons,
        'a': np.arange(10, 10 + len(gp_polygons)),