grid_overlay
cellseg_gsontools.grid.grid_overlay(gdf, patch_size=(256, 256), stride=(256, 256), pad=20, predicate='intersects')
¶
Overlay a square grid to the given areas of a geopandas.GeoDataFrame
.
Note
Returns None if the gdf is empty.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
gdf |
GeoDataFrame
|
GeoDataFrame to fit the grid to. Uses the bounding box of the GeoDataFrame to fit the grid. |
required |
patch_size |
Tuple[int, int]
|
Patch size of the grid. |
(256, 256)
|
stride |
Tuple[int, int]
|
Stride of the sliding window in the grid. |
(256, 256)
|
pad |
int
|
Pad the bounding box with the given number of pixels, by default None. |
20
|
predicate |
str
|
Predicate to use for the spatial join, by default "intersects". Allowed values are "intersects" and "within". |
'intersects'
|
Returns:
Type | Description |
---|---|
GeoDataFrame
|
gpd.GeoDataFrame: GeoDataFrame with the grid fitted to the given GeoDataFrame. |
Raises:
Type | Description |
---|---|
ValueError
|
If predicate is not one of "intersects" or "within". |
Examples:
Fit a square grid to a gdf:
>>> from cellseg_gsontools import read_gdf
>>> from cellseg_gsontools.grid import grid_overlay
>>> # Read in the tissue areas
>>> area_gdf = gpd.read_file("path/to/area.geojson")
>>> # Fit the grid
>>> sq_grid = grid_overlay(area_gdf, patch_size=(256, 256), stride=(256, 256))
>>> sq_grid
gpd.GeoDataFrame