예제 #1
0
파일: ops.py 프로젝트: jGaboardi/Shapely
def clip_by_rect(geom, xmin, ymin, xmax, ymax):
    """Returns the portion of a geometry within a rectangle

    The geometry is clipped in a fast but possibly dirty way. The output is
    not guaranteed to be valid. No exceptions will be raised for topological
    errors.

    Parameters
    ----------
    geom : geometry
        The geometry to be clipped
    xmin : float
        Minimum x value of the rectangle
    ymin : float
        Minimum y value of the rectangle
    xmax : float
        Maximum x value of the rectangle
    ymax : float
        Maximum y value of the rectangle

    Notes
    -----
    Requires GEOS >= 3.5.0
    New in 1.7.
    """
    if geom.is_empty:
        return geom
    return shapely.clip_by_rect(geom, xmin, ymin, xmax, ymax)
예제 #2
0
def test_clip_by_rect_non_scalar_kwargs():
    msg = "only accepts scalar values"
    with pytest.raises(TypeError, match=msg):
        shapely.clip_by_rect([line_string, line_string], 0, 0, 1, np.array([0, 1]))
예제 #3
0
def test_clip_by_rect_empty(geom):
    # TODO empty point
    actual = shapely.clip_by_rect(geom, 0, 0, 1, 1)
    assert actual == Geometry("GEOMETRYCOLLECTION EMPTY")
예제 #4
0
def test_clip_by_rect_missing():
    actual = shapely.clip_by_rect(None, 0, 0, 1, 1)
    assert actual is None
예제 #5
0
def test_clip_by_rect_array(geometry):
    actual = shapely.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)
예제 #6
0
def test_clip_by_rect_polygon(geom, rect, expected):
    geom, expected = shapely.Geometry(geom), shapely.Geometry(expected)
    actual = shapely.clip_by_rect(geom, *rect)
    assert_geometries_equal(actual, expected)
예제 #7
0
def test_clip_by_rect(geom, expected):
    geom, expected = shapely.Geometry(geom), shapely.Geometry(expected)
    actual = shapely.clip_by_rect(geom, 10, 10, 20, 20)
    assert_geometries_equal(actual, expected)
예제 #8
0
 def time_clip_by_rect(self):
     for bounds in self.bounds:
         shapely.clip_by_rect(self.polygon, *bounds)