def __init__(self, geoms): self._n_geoms = len(geoms) # GEOS STRtree capacity has to be > 1 self._tree_handle = lgeos.GEOSSTRtree_create(max(2, len(geoms))) for geom in geoms: lgeos.GEOSSTRtree_insert(self._tree_handle, geom._geom, ctypes.py_object(geom))
def __init__( self, geoms: Iterable[BaseGeometry], items: Iterable[Any] = None, node_capacity: int = 10, ): self.node_capacity = node_capacity # Keep references to geoms self._geoms = list(geoms) # Default enumeration index to store in the tree self._idxs = list(range(len(self._geoms))) # handle items self._has_custom_items = items is not None if not self._has_custom_items: items = self._idxs self._items = items # initialize GEOS STRtree self._tree = lgeos.GEOSSTRtree_create(self.node_capacity) i = 0 for idx, geom in zip(self._idxs, self._geoms): # filter empty geometries out of the input if geom is not None and not geom.is_empty: lgeos.GEOSSTRtree_insert(self._tree, geom._geom, ctypes.py_object(idx)) i += 1 self._n_geoms = i
def __init__(self, geoms): # filter empty geometries out of the input geoms = [geom for geom in geoms if not geom.is_empty] self._n_geoms = len(geoms) # GEOS STRtree capacity has to be > 1 self._tree_handle = lgeos.GEOSSTRtree_create(max(2, len(geoms))) for geom in geoms: lgeos.GEOSSTRtree_insert(self._tree_handle, geom._geom, ctypes.py_object(geom))
def __init__(self, items): """ Parameter items is a list of tuples, where each tuple lookes like: (entity_id: long, entity_geometry: shapely.geometry.polygon) """ self._n_geoms = len(items) self._tree_handle = shapely.geos.lgeos.GEOSSTRtree_create(max(4, len(items))) for item in items: _lgeos.GEOSSTRtree_insert(self._tree_handle, item[1]._geom, ctypes.py_object(long(item[0]))) geoms = [item[1] for item in items] self._geoms = list(geoms)
def _init_tree_handle(self, geoms): node_capacity = 10 self._tree_handle = lgeos.GEOSSTRtree_create(node_capacity) for geom in geoms: lgeos.GEOSSTRtree_insert(self._tree_handle, geom._geom, ctypes.py_object(geom))