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 def test_multiline_array_to_geopandas(gp_multiline): result = GeoSeries(gp_multiline, dtype='multiline').to_geopandas() assert_series_equal(result, gp_multiline) @given(st_polygon_array(geoseries=True)) @hyp_settings def test_polygon_array_to_geopandas(gp_polygon): result = GeoSeries(gp_polygon, dtype='polygon').to_geopandas() assert_series_equal(result, gp_polygon) @given(st_multipolygon_array(geoseries=True)) @hyp_settings def test_multipolygon_array_to_geopandas(gp_multipolygon): result = GeoSeries(gp_multipolygon, dtype='multipolygon').to_geopandas() assert_series_equal(result, gp_multipolygon)
np.testing.assert_equal(result, expected) # Test PolygonArray.intersects_rect with inds inds = np.flipud(np.arange(0, len(polygons))) result = polygons.intersects_bounds(rect, inds) np.testing.assert_equal(result, np.flipud(expected)) # Test Polygon.intersects_rect result = np.array([ polygon.intersects_bounds(rect) for polygon in polygons ]) np.testing.assert_equal(result, expected) @given( st_multipolygon_array(), st_bounds( x_min=-150, x_max=150, y_min=-150, y_max=150 ) ) @hyp_settings def test_multipolygon_intersects_rect(gp_multipolygon, rect): sg_rect = sg.box(*rect) expected = gp_multipolygon.intersects(sg_rect) multipolygons = MultiPolygonArray.from_geopandas(gp_multipolygon) # Test MultiPolygonArray.intersects_rect result = multipolygons.intersects_bounds(rect) np.testing.assert_equal(result, expected)
# Test PointArray.intersect result = points.intersects(polygon) np.testing.assert_equal(result, expected) # Test PointArray.intersects with inds inds = np.flipud(np.arange(0, len(points))) result = points.intersects(polygon, inds) np.testing.assert_equal(result, np.flipud(expected)) # Test GeoSeries.intersects pd.testing.assert_series_equal( points_series.intersects(polygon), pd.Series(expected, index=points_series.index)) @given(st_point_array(), st_multipolygon_array(min_size=1, max_size=1)) @hyp_settings def test_points_intersects_multipolygon(gp_points, gp_multipolygon): # Get scalar MultiPolygon sg_multipolygon = gp_multipolygon[0] # Compute expected intersection expected = gp_points.intersects(sg_multipolygon) # Create spatialpandas objects multipolygon = MultiPolygon.from_shapely(sg_multipolygon) points = PointArray.from_geopandas(gp_points) points_series = GeoSeries(points, index=np.arange(10, 10 + len(points))) # Test Point.intersects result = np.array(
st_bounds( x_min=-150, x_max=150, y_min=-150, y_max=150, orient=True ) ) @hyp_settings def test_polygon_cx_selection(gp_polygon, rect): x0, y0, x1, y1 = rect for xslice in get_slices(x0, x1): for yslice in get_slices(y0, y1): expected = PolygonArray.from_geopandas(gp_polygon.cx[xslice, yslice]) result = PolygonArray.from_geopandas(gp_polygon).cx[xslice, yslice] assert all(expected == result) @given( st_multipolygon_array(min_size=1, geoseries=True), st_bounds( x_min=-150, x_max=150, y_min=-150, y_max=150, orient=True ) ) @hyp_settings def test_multipolygon_cx_selection(gp_multipolygon, rect): x0, y0, x1, y1 = rect for xslice in get_slices(x0, x1): for yslice in get_slices(y0, y1): expected = MultiPolygonArray.from_geopandas( gp_multipolygon.cx[xslice, yslice] ) result = MultiPolygonArray.from_geopandas( gp_multipolygon ).cx[xslice, yslice]
import numpy as np from hypothesis import given from spatialpandas.geometry import MultiPolygonArray, PolygonArray from tests.geometry.strategies import (st_multipolygon_array, hyp_settings, st_polygon_array) @given(st_polygon_array()) @hyp_settings def test_polygon_area(gp_polygon): polygons = PolygonArray.from_geopandas(gp_polygon) expected_area = gp_polygon.area area = polygons.area np.testing.assert_allclose(area, expected_area) @given(st_multipolygon_array()) @hyp_settings def test_multipolygon_area(gp_multipolygon): multipolygons = MultiPolygonArray.from_geopandas(gp_multipolygon) expected_area = gp_multipolygon.area area = multipolygons.area np.testing.assert_allclose(area, expected_area)