cartagen.partition_grid

Contents

cartagen.partition_grid#

partition_grid(objects, width, height=None, shape='square')#

Partition objects using a grid of a given shape.

This algorithm divides the extent of the provided objects using a regular grid of the specified shape and size and assign the objects to the cell they intersects.

Parameters:
  • objects (GeoDataFrame) – The objects to partition.

  • width (float) – Width of the grid.

  • height (float, optional) – Height of the grid. If set to None, the height equals the width.

  • shape (str, optional) – Shape of the grid cells, can be ‘square’, ‘diamond’, ‘hexagonal’.

Returns:

partition (tuple) – A tuple containing two elements :

  1. A list of lists of index ordered by the grid cells

  2. A list of the geometry of the grid cells

See also

tessellate

Create a tessellation of cells of a given shape.

partition_quadtree

Partition objects using a quadtree.

partition_networks

Partition objects using one or multiple networks.

Examples

>>> points = gpd.GeoDataFrame(geometry=[ Point(2, 1), Point(4, 2) ])
>>> partition_grid(points, 1)
([[0], [1]], [<POLYGON ((2 1, 3 1, 3 2, 2 2, 2 1))>, <POLYGON ((3 1, 4 1, 4 2, 3 2, 3 1))>])

(Source code)

../_images/partition_grid.png