Exemplo n.º 1
0
def test_get_parts(geom):
    expected_num_parts = shapely.get_num_geometries(geom)
    if expected_num_parts == 0:
        expected_parts = []
    else:
        expected_parts = shapely.get_geometry(geom,
                                              range(0, expected_num_parts))

    parts = shapely.get_parts(geom)
    assert len(parts) == expected_num_parts
    assert_geometries_equal(parts, expected_parts)
Exemplo n.º 2
0
def test_get_parts_return_index():
    geom = np.array([multi_point, point, multi_polygon])
    expected_parts = []
    expected_index = []
    for i, g in enumerate(geom):
        for j in range(0, shapely.get_num_geometries(g)):
            expected_parts.append(shapely.get_geometry(g, j))
            expected_index.append(i)

    parts, index = shapely.get_parts(geom, return_index=True)
    assert len(parts) == len(expected_parts)
    assert_geometries_equal(parts, expected_parts)
    assert np.array_equal(index, expected_index)
Exemplo n.º 3
0
def test_get_parts_geometry_collection_multi():
    """On the first pass, the individual Multi* geometry objects are returned
    from the collection.  On the second pass, the individual singular geometry
    objects within those are returned.
    """
    geom = shapely.geometrycollections(
        [multi_point, multi_line_string, multi_polygon])
    expected_num_parts = shapely.get_num_geometries(geom)
    expected_parts = shapely.get_geometry(geom, range(0, expected_num_parts))

    parts = shapely.get_parts(geom)
    assert len(parts) == expected_num_parts
    assert_geometries_equal(parts, expected_parts)

    expected_subparts = []
    for g in np.asarray(expected_parts):
        for i in range(0, shapely.get_num_geometries(g)):
            expected_subparts.append(shapely.get_geometry(g, i))

    subparts = shapely.get_parts(parts)
    assert len(subparts) == len(expected_subparts)
    assert_geometries_equal(subparts, expected_subparts)
Exemplo n.º 4
0
def test_get_parts_array():
    # note: this also verifies that None is handled correctly
    # in the mix; internally it returns -1 for count of geometries
    geom = np.array(
        [None, empty_line_string, multi_point, point, multi_polygon])
    expected_parts = []
    for g in geom:
        for i in range(0, shapely.get_num_geometries(g)):
            expected_parts.append(shapely.get_geometry(g, i))

    parts = shapely.get_parts(geom)
    assert len(parts) == len(expected_parts)
    assert_geometries_equal(parts, expected_parts)
Exemplo n.º 5
0
    def setup(self):
        # create irregular polygons my merging overlapping point buffers
        self.polygons = shapely.get_parts(
            shapely.union_all(
                shapely.buffer(
                    shapely.points(np.random.random((2000, 2)) * 500), 5)))
        self.tree = shapely.STRtree(self.polygons)
        # initialize the tree by making a tiny query first
        self.tree.query(shapely.points(0, 0))

        # create points that extend beyond the domain of the above polygons to ensure
        # some don't overlap
        self.points = shapely.points((np.random.random((2000, 2)) * 750) - 125)
        self.point_tree = shapely.STRtree(
            shapely.points(np.random.random((2000, 2)) * 750))
        self.point_tree.query(shapely.points(0, 0))

        # create points on a grid for testing equidistant nearest neighbors
        # creates 2025 points
        grid_coords = np.mgrid[:45, :45].T.reshape(-1, 2)
        self.grid_point_tree = shapely.STRtree(shapely.points(grid_coords))
        self.grid_points = shapely.points(grid_coords + 0.5)
Exemplo n.º 6
0
 def time_get_parts(self):
     """Cython implementation of get_parts"""
     shapely.get_parts(self.multipolygons)
Exemplo n.º 7
0
def test_get_rings_invalid_dimensions(geom):
    """Only 1D inputs are supported"""
    with pytest.raises(ValueError, match="Array should be one dimensional"):
        shapely.get_parts(geom)
Exemplo n.º 8
0
def test_get_parts_invalid_geometry(geom):
    with pytest.raises(TypeError,
                       match="One of the arguments is of incorrect type."):
        shapely.get_parts(geom)
Exemplo n.º 9
0
def test_get_parts_None(geom):
    assert len(shapely.get_parts(geom)) == 0
Exemplo n.º 10
0
def test_get_parts_non_multi(geom):
    """Non-multipart geometries should be returned identical to inputs"""
    assert_geometries_equal(geom, shapely.get_parts(geom))