lmpy.spatial.spatial_index

Module containing a class for working with a spatial index.

Version 1: Store geometries in memory in table. Save as wkt.

Module Contents

Classes

SpatialIndex

Constructor for the spatial index.

class lmpy.spatial.spatial_index.SpatialIndex(index_name=None)[source]

Constructor for the spatial index.

Parameters

index_name (str) – A name to use for saving the index to a file.

static _point_intersect(pt_x, pt_y, geom)[source]

Perform a point intersect.

Parameters
  • pt_x (numeric) – The x coordinate of the point.

  • pt_y (numeric) – The y coordinate of the point.

  • geom (ogr.Geometry) – The geometry to intersect.

Returns

Indication if the point is within the geometry.

Return type

bool

add_feature(self, identifier, geom, att_dict)[source]

Add a feature to the index.

Parameters
  • identifier (str) – An identifier for this feature in the lookup table.

  • geom (ogr.Geometry) – A geometry to spatially index.

  • att_dict (dict) – A dictionary of attributes to store in the lookup table.

close(self)[source]

Close the index.

save(self)[source]

Save the index attributes.

search(self, x, y)[source]

Search for x, y and return attributes in lookup if found.

Parameters
  • x (numeric) – The x coordinate to search for.

  • y (numeric) – The y coordinate to search for.

Returns

A dictionary of index hits for the search.

Return type

dict