libpysal.cg.
Grid
(bounds, resolution)[source]¶Representation of a binning data structure.
__init__
(self, bounds, resolution)[source]¶Returns a grid with specified properties.
__init__(Rectangle, number) -> Grid
Examples
TODO: complete this doctest >>> g = Grid(Rectangle(0, 0, 10, 10), 1)
Methods
|
Returns a grid with specified properties. |
|
Adds an item to the grid at a specified location. |
|
Returns a list of items found in the grid within the bounds specified. |
|
Returns whether a 2-tuple location _loc_ lies inside the grid bounds. |
|
Returns the nearest item to a point. |
|
Returns a list of items found in the grid within a specified distance of a point. |
|
Removes an item from the grid at a specified location. |
add
(self, item, pt)[source]¶Adds an item to the grid at a specified location.
add(x, Point) -> x
Examples
>>> g = Grid(Rectangle(0, 0, 10, 10), 1)
>>> g.add('A', Point((4.2, 8.7)))
'A'
bounds
(self, bounds)[source]¶Returns a list of items found in the grid within the bounds specified.
bounds(Rectangle) -> x list
Examples
>>> g = Grid(Rectangle(0, 0, 10, 10), 1)
>>> g.add('A', Point((1.0, 1.0)))
'A'
>>> g.add('B', Point((4.0, 4.0)))
'B'
>>> g.bounds(Rectangle(0, 0, 3, 3))
['A']
>>> g.bounds(Rectangle(2, 2, 5, 5))
['B']
>>> sorted(g.bounds(Rectangle(0, 0, 5, 5)))
['A', 'B']
in_grid
(self, loc)[source]¶Returns whether a 2-tuple location _loc_ lies inside the grid bounds.
Test tag: <tc>#is#Grid.in_grid</tc>
nearest
(self, pt)[source]¶Returns the nearest item to a point.
nearest(Point) -> x
Examples
>>> g = Grid(Rectangle(0, 0, 10, 10), 1)
>>> g.add('A', Point((1.0, 1.0)))
'A'
>>> g.add('B', Point((4.0, 4.0)))
'B'
>>> g.nearest(Point((2.0, 1.0)))
'A'
>>> g.nearest(Point((7.0, 5.0)))
'B'
proximity
(self, pt, r)[source]¶Returns a list of items found in the grid within a specified distance of a point.
proximity(Point, number) -> x list
Examples
>>> g = Grid(Rectangle(0, 0, 10, 10), 1)
>>> g.add('A', Point((1.0, 1.0)))
'A'
>>> g.add('B', Point((4.0, 4.0)))
'B'
>>> g.proximity(Point((2.0, 1.0)), 2)
['A']
>>> g.proximity(Point((6.0, 5.0)), 3.0)
['B']
>>> sorted(g.proximity(Point((4.0, 1.0)), 4.0))
['A', 'B']
remove
(self, item, pt)[source]¶Removes an item from the grid at a specified location.
remove(x, Point) -> x
Examples
>>> g = Grid(Rectangle(0, 0, 10, 10), 1)
>>> g.add('A', Point((4.2, 8.7)))
'A'
>>> g.remove('A', Point((4.2, 8.7)))
'A'