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:
|
tile_size
|
Tile size in meters
TYPE:
|
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:
|
tile_size
|
Tile size in meters
TYPE:
|
snap
|
If True, the bounding box is snapped to
TYPE:
|
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:
|
RETURNS | DESCRIPTION |
---|---|
Grid
|
Grid |
from_config
classmethod
Creates a grid from the configuration.
PARAMETER | DESCRIPTION |
---|---|
config
|
Configuration
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Grid
|
Grid |
__eq__
Compares the grids.
PARAMETER | DESCRIPTION |
---|---|
other
|
Other grid
TYPE:
|
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:
|
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:
|
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 |
append
Appends the coordinates.
PARAMETER | DESCRIPTION |
---|---|
coordinates
|
Coordinates (x_min, y_min) of the tile or of each tile in meters
TYPE:
|
inplace
|
If True, the coordinates are appended inplace
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Grid
|
Grid |
chunk
Chunks the grid.
PARAMETER | DESCRIPTION |
---|---|
num_chunks
|
Number of chunks
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[Grid]
|
Grids |
filter
Filters the grid.
PARAMETER | DESCRIPTION |
---|---|
coordinates_filter
|
Coordinates filter
TYPE:
|
inplace
|
If True, the coordinates are filtered inplace
TYPE:
|
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:
|
inplace
|
If True, the coordinates are removed inplace
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Grid
|
Grid |
to_gdf
Converts the grid to a geodataframe.
PARAMETER | DESCRIPTION |
---|---|
epsg_code
|
EPSG code
TYPE:
|
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
andtile_size
gpkg_path
andtile_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.
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:
|
gpkg_path |
Path to the geopackage (.gpkg file) - defaults to None
TYPE:
|
json_path |
Path to the JSON file (.json file) - defaults to None
TYPE:
|
ignore_bounding_box_coordinates |
Bounding box coordinates to ignore (x_min, y_min, x_max, y_max) in meters - defaults to None
TYPE:
|
ignore_gpkg_path |
Path to the geopackage (.gpkg file) to ignore - defaults to None
TYPE:
|
ignore_json_path |
Path to the JSON file (.json file) to ignore - defaults to None
TYPE:
|
tile_size |
Tile size in meters - defaults to None
TYPE:
|
snap |
If True, the bounding box is snapped to
TYPE:
|