Beispiel #1
0
 def __init__(self, context):
     if isinstance(context, PreparedGeometry):
         self.context = context.context
     else:
         shapely.prepare(context)
         self.context = context
     self.prepared = True
Beispiel #2
0
def touches(geometry, x, y):
    """
    Vectorized (element-wise) version of `touches` which checks whether
    multiple points touch the exterior of a single geometry.

    Parameters
    ----------
    geometry : PreparedGeometry or subclass of BaseGeometry
        The geometry which is to be checked to see whether each point is
        contained within. The geometry will be "prepared" if it is not already
        a PreparedGeometry instance.
    x : array
        The x coordinates of the points to check.
    y : array
        The y coordinates of the points to check.

    Returns
    -------
    Mask of points which touch the exterior of the given `geometry`.

    """
    points = _construct_points(x, y)
    if isinstance(geometry, PreparedGeometry):
        geometry = geometry.context
    shapely.prepare(geometry)
    return shapely.touches(geometry, points)
Beispiel #3
0
def _prepare_input(geometry, prepare):
    """Prepare without modifying inplace"""
    if prepare:
        geometry = shapely.apply(geometry, lambda x: x)  # makes a copy
        shapely.prepare(geometry)
        return geometry
    else:
        return geometry
Beispiel #4
0
def test_destroy_prepared():
    arr = np.array([shapely.points(1, 1), None, shapely.box(0, 0, 1, 1)])
    shapely.prepare(arr)
    assert arr[0]._ptr_prepared != 0
    assert arr[2]._ptr_prepared != 0
    shapely.destroy_prepared(arr)
    assert arr[0]._ptr_prepared == 0
    assert arr[1] is None
    assert arr[2]._ptr_prepared == 0
    shapely.destroy_prepared(arr)  # does not error
Beispiel #5
0
def test_prepare():
    arr = np.array([shapely.points(1, 1), None, shapely.box(0, 0, 1, 1)])
    assert arr[0]._ptr_prepared == 0
    assert arr[2]._ptr_prepared == 0
    shapely.prepare(arr)
    assert arr[0]._ptr_prepared != 0
    assert arr[1] is None
    assert arr[2]._ptr_prepared != 0

    # preparing again actually does nothing
    original = arr[0]._ptr_prepared
    shapely.prepare(arr)
    assert arr[0]._ptr_prepared == original
Beispiel #6
0
def _prepare_with_copy(geometry):
    """Prepare without modifying inplace"""
    geometry = shapely.apply(geometry, lambda x: x)  # makes a copy
    shapely.prepare(geometry)
    return geometry