libpysal.cg.Grid¶
-
class
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
- Parameters
- bounds
theareaforthegridtoencompass - resolution
thediameterofeachbin
- bounds
Examples
TODO: complete this doctest >>> g = Grid(Rectangle(0, 0, 10, 10), 1)
Methods
__init__(self, bounds, resolution)Returns a grid with specified properties.
add(self, item, pt)Adds an item to the grid at a specified location.
bounds(self, bounds)Returns a list of items found in the grid within the bounds specified.
in_grid(self, loc)Returns whether a 2-tuple location _loc_ lies inside the grid bounds.
nearest(self, pt)Returns the nearest item to a point.
proximity(self, pt, r)Returns a list of items found in the grid within a specified distance of a point.
remove(self, item, pt)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
- Parameters
- item
theitemtoinsertintothegrid - pt
thelocationtoinserttheitemat
- item
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
- Parameters
- item
theitemtoremovefromthegrid - pt
thelocationtheitemwasaddedat
- item
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
- Parameters
- pt
thelocationtosearchnear
- pt
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
- Parameters
- pt
thelocationtosearcharound - r
thedistancetosearcharoundthepoint
- pt
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
- Parameters
- item
theitemtoremovefromthegrid - pt
thelocationtheitemwasaddedat
- item
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'
-