def time_get_parts_python(self): """Python / ufuncs version of get_parts""" parts = [] for i in range(len(self.multipolygons)): num_parts = shapely.get_num_geometries(self.multipolygons[i]) parts.append( shapely.get_geometry(self.multipolygons[i], range(num_parts))) parts = np.concatenate(parts)
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)
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)
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)
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)
def test_get_num_geometries(): actual = shapely.get_num_geometries(all_types + (None, )).tolist() assert actual == [1, 1, 1, 1, 2, 1, 2, 2, 0, 0]
def test_get_geometry_collection(geom): n = shapely.get_num_geometries(geom) actual = shapely.get_geometry(geom, [0, -n, n, -(n + 1)]) assert_geometries_equal(actual[0], actual[1]) assert shapely.is_missing(actual[2:4]).all()
def __len__(self): return shapely.get_num_geometries(self.__p__)
def test_create_collection_skips_none(func, sub_geom): actual = func([sub_geom, None, None, sub_geom]) assert shapely.get_num_geometries(actual) == 2