spaghetti.regular_lattice

spaghetti.regular_lattice(bounds, nh, nv=None, exterior=False)[source]

Generate a regular lattice of line segments (libpysal.cg.Chain objects).

Parameters
bounds{tuple, list}

Area bounds in the form - <minx,miny,maxx,maxy>.

nhint

The number of internal horizontal lines of the lattice.

nvint

The number of internal vertical lines of the lattice. Defaults to nh if left as None.

exteriorbool

Flag for including the outer bounding box segments. Default is False.

Returns
latticelist

libpysal.cg.Chain objects forming a regular lattice

Notes

The nh and nv parameters do not include the external line segments. For example, setting nh=3, nv=2, exterior=True will result in 5 horizontal line sets and 4 vertical line sets.

Examples

Create a 5x5 regular lattice with an exterior

>>> import spaghetti
>>> lattice = spaghetti.regular_lattice((0,0,4,4), 3, exterior=True)
>>> lattice[0].vertices
[(0.0, 0.0), (1.0, 0.0)]

Create a 5x5 regular lattice without an exterior

>>> lattice = spaghetti.regular_lattice((0,0,5,5), 3, exterior=False)
>>> lattice[-1].vertices
[(3.75, 3.75), (3.75, 5.0)]

Create a 7x9 regular lattice with an exterior from the bounds of streets.shp.

>>> path = libpysal.examples.get_path("streets.shp")
>>> shp = libpysal.io.open(path)
>>> lattice = spaghetti.regular_lattice(shp.bbox, 5, nv=7, exterior=True)
>>> lattice[0].vertices
[(723414.3683108028, 875929.0396895551), (724286.1381211297, 875929.0396895551)]