natcap.invest.recreation.out_of_core_quadtree¶
A hierarchical spatial index for fast culling of points in 2D space.
-
class
natcap.invest.recreation.out_of_core_quadtree.
OutOfCoreQuadTree
(bounding_box, max_points_per_node, max_node_depth, quad_tree_storage_dir, node_depth=0, node_data_manager=None, pickle_filename=None)¶ Bases:
object
An out of core quad tree spatial indexing structure.
-
add_points
(point_list, left_bound, right_bound)¶ Add a list of points to the current node.
This function will split the current node if the added points exceed the maximum number of points allowed per node and is already not at the maximum level.
- Parameters
point_list (numpy.ndarray) – a numpy array of (data, x_coord, y_coord) tuples
left_bound (int) – left index inclusive of points to consider under point_list
right_bound (int) – right index non-inclusive of points to consider under point_list
- Returns
None
-
build_node_shapes
(ogr_polygon_layer)¶ Add features to an ogr.Layer to visualize quadtree segmentation.
- Parameters
ogr_polygon_layer (ogr.layer) – an ogr polygon layer with fields ‘n_points’ (int) and ‘bb_box’ (string) defined.
- Returns
None
-
flush
()¶ Flush any cached data to disk.
-
get_intersecting_points_in_bounding_box
(bounding_box)¶ Get list of data that is contained by bounding_box.
This function takes in a bounding box and returns a list of (data, lat, lng) tuples that are contained in the leaf nodes that intersect that bounding box.
- Parameters
bounding_box (list) – of the form [xmin, ymin, xmax, ymax]
- Returns
numpy.ndarray array of (data, x_coord, lng) of nodes that intersect the bounding box.
-
get_intersecting_points_in_polygon
(shapely_polygon)¶ Return the points contained in shapely_prepared_polygon.
This function is a high performance test routine to return the points contained in the shapely_prepared_polygon that are stored in self’s representation of a quadtree.
- Parameters
shapely_polygon (ogr.DataSource) – a polygon datasource to bound against
- Returns
- deque of (data, x_coord, y_coord) of nodes that are contained
in shapely_prepared_polygon.
-
n_nodes
()¶ Return the number of nodes in the quadtree
-
n_points
()¶ Return the number of nodes in the quadtree
-
next_available_blob_id
= 0¶
-