コード例 #1
0
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)
コード例 #2
0
def test_polygon_array():
    polygons = PolygonArray([[large_square_ccw],
                             [large_square_ccw, unit_square_cw],
                             [unit_square_cw]])
    np.testing.assert_equal(polygons.length, [12.0, 16.0, 4.0])
    np.testing.assert_equal(polygons.area, [9.0, 8.0, -1.0])
    assert polygons.total_bounds == (0.0, 0.0, 3.0, 3.0)
コード例 #3
0
def _to_spatialpandas(
    column: List[Union[int, float]],
    polygon_points: List[np.ndarray],
    column_name: str,
):
    from spatialpandas import GeoDataFrame
    from spatialpandas.geometry import PolygonArray

    # spatialpandas expects 1d numpy arrays.
    for i, arrays in enumerate(polygon_points):
        polygon_points[i] = \
            list(map(lambda array: np.reshape(array, -1), arrays))

    df = GeoDataFrame({
        column_name: column,
        "geometry": PolygonArray(polygon_points)
    })
    return df
コード例 #4
0
def test_polygon_intersects_rect(gp_polygon, rect):
    sg_rect = sg.box(*rect)

    expected = gp_polygon.intersects(sg_rect)
    polygons = PolygonArray.from_geopandas(gp_polygon)

    # Test PolygonArray.intersects_rect
    result = polygons.intersects_bounds(rect)
    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)
コード例 #5
0
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)