Skip to content

Grid

Bases: Iterable[Coordinates]

A grid specifies the spatial extent of an area of interest by a set of coordinates of the bottom left corner of each tile and the tile size.

Notes
  • The coordinates are assumed to be in shape (n, 2) and data type int32, where n is the number of coordinates
  • The coordinates are sorted
PARAMETER DESCRIPTION
coordinates

Coordinates (x_min, y_min) of each tile in meters

TYPE: CoordinatesSet | None

tile_size

Tile size in meters

TYPE: TileSize

coordinates property

RETURNS DESCRIPTION
CoordinatesSet

Coordinates (x_min, y_min) of each tile in meters

tile_size property

RETURNS DESCRIPTION
TileSize

Tile size in meters

area property

RETURNS DESCRIPTION
int

Area in square meters

from_bounding_box classmethod

Creates a grid from a bounding box.

PARAMETER DESCRIPTION
bounding_box

Bounding box

TYPE: BoundingBox

tile_size

Tile size in meters

TYPE: TileSize

snap

If True, the bounding box is snapped to tile_size

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
Grid

Grid

from_gdf classmethod

Creates a grid from a geodataframe.

PARAMETER DESCRIPTION
gdf

Geodataframe

TYPE: gpd.GeoDataFrame

tile_size

Tile size in meters

TYPE: TileSize

snap

If True, the bounding box is snapped to tile_size

TYPE: bool DEFAULT: True

RETURNS DESCRIPTION
Grid

Grid

from_json classmethod

Creates a grid from a JSON string.

Notes
  • The JSON string contains a list of coordinates (x_min, y_min) of each tile and the tile size
Example

Assume the JSON string is '{"coordinates": [[363084, 5715326], [363212, 5715326], [363084, 5715454], [363212, 5715454]], "tile_size": 128}'.

You can create a grid from the JSON string.

grid = Grid.from_json(
    json_string=(
        '{"coordinates": '
        '[[363084, 5715326], '
        '[363212, 5715326], '
        '[363084, 5715454], '
        '[363212, 5715454]], '
        '"tile_size": 128}'
    ),
)
PARAMETER DESCRIPTION
json_string

JSON string

TYPE: str

RETURNS DESCRIPTION
Grid

Grid

from_grids classmethod

Creates a grid from grids.

PARAMETER DESCRIPTION
grids

Grids

TYPE: list[Grid]

RETURNS DESCRIPTION
Grid

Grid

from_config classmethod

Creates a grid from the configuration.

PARAMETER DESCRIPTION
config

Configuration

TYPE: GridConfig

RETURNS DESCRIPTION
Grid

Grid

__eq__

Compares the grids.

PARAMETER DESCRIPTION
other

Other grid

TYPE: object

RETURNS DESCRIPTION
bool

True if the grids are equal, False otherwise

__len__

Computes the number of coordinates.

RETURNS DESCRIPTION
int

Number of coordinates

__bool__

Checks if the grid contains coordinates.

RETURNS DESCRIPTION
bool

True if the grid contains coordinates, False otherwise

__contains__

Checks if the coordinates are in the grid.

PARAMETER DESCRIPTION
coordinates

Coordinates (x_min, y_min) of the tile in meters

TYPE: Coordinates | CoordinatesSet

RETURNS DESCRIPTION
bool

True if the coordinates are in the grid, False otherwise

__getitem__

Returns the coordinates or the sliced grid.

PARAMETER DESCRIPTION
index

Index or slice of the coordinates

TYPE: int | slice

RETURNS DESCRIPTION
Coordinates | Grid

Coordinates (x_min, y_min) of the tile in meters or grid

__iter__

Iterates over the coordinates.

YIELDS DESCRIPTION
Coordinates

Coordinates (x_min, y_min) of the tile in meters

__add__

Adds the grids.

PARAMETER DESCRIPTION
other

Other grid

TYPE: Grid

RETURNS DESCRIPTION
Grid

Grid

__sub__

Subtracts the grids.

PARAMETER DESCRIPTION
other

Other grid

TYPE: Grid

RETURNS DESCRIPTION
Grid

Grid

__and__

Intersects the grids.

PARAMETER DESCRIPTION
other

Other grid

TYPE: Grid

RETURNS DESCRIPTION
Grid

Grid

__or__

Unions the grids.

PARAMETER DESCRIPTION
other

Other grid

TYPE: Grid

RETURNS DESCRIPTION
Grid

Grid

append

Appends the coordinates.

PARAMETER DESCRIPTION
coordinates

Coordinates (x_min, y_min) of the tile or of each tile in meters

TYPE: Coordinates | CoordinatesSet

inplace

If True, the coordinates are appended inplace

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Grid

Grid

chunk

Chunks the grid.

PARAMETER DESCRIPTION
num_chunks

Number of chunks

TYPE: int

RETURNS DESCRIPTION
list[Grid]

Grids

filter

Filters the grid.

PARAMETER DESCRIPTION
coordinates_filter

Coordinates filter

TYPE: CoordinatesFilter

inplace

If True, the coordinates are filtered inplace

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Grid

Grid

remove

Removes the coordinates.

PARAMETER DESCRIPTION
coordinates

Coordinates (x_min, y_min) of the tile or of each tile in meters

TYPE: Coordinates | CoordinatesSet

inplace

If True, the coordinates are removed inplace

TYPE: bool DEFAULT: False

RETURNS DESCRIPTION
Grid

Grid

to_gdf

Converts the grid to a geodataframe.

PARAMETER DESCRIPTION
epsg_code

EPSG code

TYPE: EPSGCode | None

RETURNS DESCRIPTION
gpd.GeoDataFrame

Geodataframe

to_json

Converts the grid to a JSON string.

Notes
  • The JSON string contains a list of coordinates (x_min, y_min) of each tile and the tile size
RETURNS DESCRIPTION
str

JSON string


GridConfig

Bases: pydantic.BaseModel

Configuration for the from_config class method of Grid

The configuration must have exactly one of the following field combinations
  • bounding_box_coordinates and tile_size
  • gpkg_path and tile_size
  • json_path
Create the configuration from a config file
  • Use null instead of None
  • Use false or true instead of False or True
Example

You can create a configuration from a config file.

config.yaml
bounding_box_coordinates:
  - 363084
  - 5715326
  - 363340
  - 5715582
gpkg_path: null
json_path: null
ignore_bounding_box_coordinates: null
ignore_gpkg_path: null
ignore_json_path: null
tile_size: 128
snap: true
ATTRIBUTE DESCRIPTION
bounding_box_coordinates

Bounding box coordinates (x_min, y_min, x_max, y_max) in meters - defaults to None

TYPE: tuple[Coordinate, Coordinate, Coordinate, Coordinate] | None

gpkg_path

Path to the geopackage (.gpkg file) - defaults to None

TYPE: Path | None

json_path

Path to the JSON file (.json file) - defaults to None

TYPE: Path | None

ignore_bounding_box_coordinates

Bounding box coordinates to ignore (x_min, y_min, x_max, y_max) in meters - defaults to None

TYPE: tuple[Coordinate, Coordinate, Coordinate, Coordinate] | None

ignore_gpkg_path

Path to the geopackage (.gpkg file) to ignore - defaults to None

TYPE: Path | None

ignore_json_path

Path to the JSON file (.json file) to ignore - defaults to None

TYPE: Path | None

tile_size

Tile size in meters - defaults to None

TYPE: TileSize | None

snap

If True, the bounding box is snapped to tile_size - defaults to True

TYPE: bool