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] assert all(expected == result)
def test_multipolygon_array(): multipolygon = MultiPolygonArray([[[large_square_ccw, unit_square_cw], [large_square_ccw + 4.0]], [[large_square_ccw + 8.0]]]) np.testing.assert_equal(multipolygon.length, [28.0, 12.0]) np.testing.assert_equal(multipolygon.area, [17.0, 9.0]) assert multipolygon.total_bounds == (0.0, 0.0, 11.0, 11.0)
def test_multipolygon_subpixel_horizontal(DataFrame, scale): df = GeoDataFrame({ 'geometry': MultiPolygonArray([[ [[0, 0, 1, 0, 1, 1, 0, 1, 0, 0]], [[0, 2, 1, 2, 1, 3, 0, 3, 0, 2]], ]]) }) cvs = ds.Canvas(plot_height=8, plot_width=8, x_range=(-2 * scale, 2 * scale), y_range=(0, 4)) agg = cvs.polygons(df, 'geometry', agg=ds.count()) sol = np.array([[0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0]], dtype=np.int32) axis = ds.core.LinearAxis() lincoords_x = axis.compute_index( axis.compute_scale_and_translate((-2 * scale, 2 * scale), 8), 8) lincoords_y = axis.compute_index( axis.compute_scale_and_translate((0, 4), 8), 8) out = xr.DataArray(sol, coords=[lincoords_y, lincoords_x], dims=['y', 'x']) assert_eq_xr(agg, out)
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 MultiPolygonArray.intersects_rect with inds inds = np.flipud(np.arange(0, len(multipolygons))) result = multipolygons.intersects_bounds(rect, inds) np.testing.assert_equal(result, np.flipud(expected)) # Test MultiPolygon.intersects_rect result = np.array([ multipolygon.intersects_bounds(rect) for multipolygon in multipolygons ]) np.testing.assert_equal(result, expected)
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)