How to use the rtree.core.RTreeError function in Rtree

To help you get started, we’ve selected a few Rtree examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github CosmiQ / cw-geodata / cw_geodata / vector_label / polygon.py View on Github external
gdf = gpd.read_file(gdf)
    if isinstance(im, str):
        im = rasterio.open(im)
    sindex = gdf.sindex
    # use transform_bounds in case the crs is different - no effect if not
    if im:
        bbox = transform_bounds(im.crs, gdf.crs, *im.bounds)
    else:
        if isinstance(bbox, Polygon):
            bbox = bbox.bounds
        if not bbox_crs:
            bbox_crs = gdf.crs
        bbox = transform_bounds(bbox_crs, gdf.crs, *bbox)
    try:
        intersectors = list(sindex.intersection(bbox))
    except RTreeError:
        intersectors = []

    return gdf.iloc[intersectors, :]
github CosmiQ / solaris / solaris / vector / polygon.py View on Github external
# use transform_bounds in case the crs is different - no effect if not
    if isinstance(bbox, Polygon):
        bbox = bbox.bounds
    if bbox_crs is None:
        try:
            bbox_crs = gdf.crs
        except AttributeError:
            raise ValueError('If `im` and `bbox_crs` are not provided, `gdf`'
                             'must provide a coordinate reference system.')
    else:
        bbox_crs = _check_crs(bbox_crs)
        bbox_crs = CRS.from_epsg(bbox_crs)
    bbox = transform_bounds(bbox_crs, gdf.crs, *bbox)
    try:
        intersectors = list(sindex.intersection(bbox))
    except RTreeError:
        intersectors = []

    return gdf.iloc[intersectors, :]
github CivicSpleen / ambry / ambry / old / geo / util.py View on Github external
from shapely.geometry import Point, Polygon
    from shapely.wkt import loads
    from collections import Iterable
    from ..dbexceptions import GeoError

    # Maybe this is only a performance improvement if the data is sorted in
    # the generator ...
    def gen_index():
        for i, wkt, container_obj in containers:
            container_geometry = loads(wkt)

            yield (i, container_geometry.bounds, (container_obj, container_geometry))

    try:
        idx = index.Index(gen_index())
    except RTreeError:
        raise GeoError(
            "Failed to create RTree Index. Check that the container generator produced valud output")

    # Find the point containment
    for contained_coords, contained_obj in containeds:

        locations = idx.intersection(contained_coords, objects=True)

        if len(contained_coords) == 2:
            contained = Point(contained_coords)
        elif len(contained_coords) == 4 and not isinstance(contained_coords[0],
                                                           Iterable):
            # Assume it is bounding box coords. If the elements were iterables ( x,y points ) it
            # could be something else.
            # bounding boxes are: (minx, miny, maxx, maxy)
            (minx, miny, maxx, maxy) = contained_coords