Example #1
0
def clip_by_rect(data, xmin, ymin, xmax, ymax):
    if compat.USE_PYGEOS:
        return pygeos.clip_by_rect(data, xmin, ymin, xmax, ymax)
    else:
        clipped_geometries = np.empty(len(data), dtype=object)
        clipped_geometries[:] = [
            shapely.ops.clip_by_rect(s, xmin, ymin, xmax, ymax)
            if s is not None
            else None
            for s in data
        ]
        return clipped_geometries
Example #2
0
def constructive(arr, operation, *args, **kwargs):
    if operation == 'boundary':
        geometries = pg.boundary(pg.from_wkb(arr), **kwargs)
    elif operation == 'buffer':
        geometries = pg.buffer(pg.from_wkb(arr), *args, **kwargs)
    elif operation == 'build_area':
        geometries = pg.build_area(pg.from_wkb(arr), **kwargs)
    elif operation == 'centroid':
        geometries = pg.centroid(pg.from_wkb(arr), **kwargs)
    elif operation == 'clip_by_rect':
        geometries = pg.clip_by_rect(pg.from_wkb(arr), *args, **kwargs)
    elif operation == 'convex_hull':
        geometries = pg.convex_hull(pg.from_wkb(arr), **kwargs)
    elif operation == 'delaunay_triangles':
        geometries = pg.delaunay_triangles(pg.from_wkb(arr), **kwargs)
    elif operation == 'envelope':
        geometries = pg.envelope(pg.from_wkb(arr), **kwargs)
    elif operation == 'extract_unique_points':
        geometries = pg.extract_unique_points(pg.from_wkb(arr), **kwargs)
    elif operation == 'make_valid':
        geometries = pg.make_valid(pg.from_wkb(arr), **kwargs)
    elif operation == 'normalize':
        geometries = pg.normalize(pg.from_wkb(arr), **kwargs)
    elif operation == 'offset_curve':
        geometries = pg.offset_curve(pg.from_wkb(arr), *args, **kwargs)
    elif operation == 'point_on_surface':
        geometries = pg.point_on_surface(pg.from_wkb(arr), **kwargs)
    elif operation == 'reverse':
        geometries = pg.reverse(pg.from_wkb(arr), **kwargs)
    elif operation == 'simplify':
        geometries = pg.simplify(pg.from_wkb(arr), *args, **kwargs)
    elif operation == 'snap':
        geometries = pg.snap(pg.from_wkb(arr), *args, **kwargs)
    elif operation == 'voronoi_polygons':
        geometries = pg.voronoi_polygons(pg.from_wkb(arr), **kwargs)
    else:
        warnings.warn(f'Operation {operation} not supported.')
        return None
    return pg.to_wkb(geometries)
Example #3
0
 def time_clip_by_rect(self):
     for bounds in self.bounds:
         pygeos.clip_by_rect(self.polygon, *bounds)
Example #4
0
def test_clip_by_rect_non_scalar_kwargs():
    msg = "only accepts scalar values"
    with pytest.raises(TypeError, match=msg):
        pygeos.clip_by_rect([line_string, line_string], 0, 0, 1, np.array([0, 1]))
Example #5
0
def test_clip_by_rect_empty(geom):
    # TODO empty point
    actual = pygeos.clip_by_rect(geom, 0, 0, 1, 1)
    assert actual == Geometry("GEOMETRYCOLLECTION EMPTY")
Example #6
0
def test_clip_by_rect_missing():
    actual = pygeos.clip_by_rect(None, 0, 0, 1, 1)
    assert actual is None
Example #7
0
def test_clip_by_rect_array(geometry):
    actual = pygeos.clip_by_rect([geometry, geometry], 0.0, 0.0, 1.0, 1.0)
    assert actual.shape == (2,)
    assert actual[0] is None or isinstance(actual[0], Geometry)
Example #8
0
def test_clip_by_rect_polygon(geom, rect, expected):
    geom, expected = pygeos.Geometry(geom), pygeos.Geometry(expected)
    actual = pygeos.clip_by_rect(geom, *rect)
    assert pygeos.equals(actual, expected)
Example #9
0
def test_clip_by_rect(geom, expected):
    geom, expected = pygeos.Geometry(geom), pygeos.Geometry(expected)
    actual = pygeos.clip_by_rect(geom, 10, 10, 20, 20)
    assert pygeos.equals(actual, expected)