Exemplo n.º 1
0
def test_set_coords(geoms, count, has_ring, include_z):
    arr_geoms = np.array(geoms, np.object_)
    n = 3 if include_z else 2
    coords = get_coordinates(arr_geoms,
                             include_z=include_z) + np.random.random((1, n))
    new_geoms = set_coordinates(arr_geoms, coords)
    assert_equal(coords, get_coordinates(new_geoms, include_z=include_z))
Exemplo n.º 2
0
def _assert_nan_coords_same(x, y, tolerance, err_msg, verbose):
    x, y = np.broadcast_arrays(x, y)
    x_coords = shapely.get_coordinates(x, include_z=True)
    y_coords = shapely.get_coordinates(y, include_z=True)

    # Check the shapes (condition is copied from numpy test_array_equal)
    if x_coords.shape != y_coords.shape:
        return False

    # Check NaN positional equality
    x_id = np.isnan(x_coords)
    y_id = np.isnan(y_coords)
    if not (x_id == y_id).all():
        msg = build_err_msg(
            [x, y],
            err_msg + "\nx and y nan coordinate location mismatch:",
            verbose=verbose,
        )
        raise AssertionError(msg)

    # If this passed, replace NaN with a number to be able to use equals_exact
    x_no_nan = shapely.apply(x, _replace_nan, include_z=True)
    y_no_nan = shapely.apply(y, _replace_nan, include_z=True)

    return _equals_exact_with_ndim(x_no_nan, y_no_nan, tolerance=tolerance)
Exemplo n.º 3
0
def test_apply(geoms, include_z):
    geoms = np.array(geoms, np.object_)
    coordinates_before = get_coordinates(geoms, include_z=include_z)
    new_geoms = apply(geoms, lambda x: x + 1, include_z=include_z)
    assert new_geoms is not geoms
    coordinates_after = get_coordinates(new_geoms, include_z=include_z)
    assert_allclose(coordinates_before + 1, coordinates_after, equal_nan=True)
Exemplo n.º 4
0
def _unpickle_linearring(wkb):
    linestring = shapely.from_wkb(wkb)
    srid = shapely.get_srid(linestring)
    linearring = shapely.linearrings(shapely.get_coordinates(linestring))
    if srid:
        linearring = shapely.set_srid(linearring, srid)
    return linearring
Exemplo n.º 5
0
def test_get_coords(geoms, x, y, include_z):
    actual = get_coordinates(np.array(geoms, np.object_), include_z=include_z)
    if not include_z:
        expected = np.array([x, y], np.float64).T
    else:
        expected = np.array([x, y, [np.nan] * len(x)], np.float64).T
    assert_equal(actual, expected)
Exemplo n.º 6
0
def test_get_coords_3d(geoms, x, y, z, include_z):
    actual = get_coordinates(np.array(geoms, np.object_), include_z=include_z)
    if include_z:
        expected = np.array([x, y, z], np.float64).T
    else:
        expected = np.array([x, y], np.float64).T
    assert_equal(actual, expected)
Exemplo n.º 7
0
def test_pickle(geom):
    if shapely.get_type_id(geom) == 2:
        # Linearrings get converted to linestrings
        expected = shapely.linestrings(shapely.get_coordinates(geom))
    else:
        expected = geom
    pickled = pickle.dumps(geom)
    assert_geometries_equal(pickle.loads(pickled), expected, tolerance=0)
Exemplo n.º 8
0
def test_set_coords_mixed_dimension(include_z):
    geoms = np.array([point, point_z], dtype=object)
    coords = get_coordinates(geoms, include_z=include_z)
    new_geoms = set_coordinates(geoms, coords * 2)
    if include_z:
        # preserve original dimensionality
        assert not shapely.has_z(new_geoms[0])
        assert shapely.has_z(new_geoms[1])
    else:
        # all 2D
        assert not shapely.has_z(new_geoms).any()
Exemplo n.º 9
0
def _unpickle_linearring(wkb):
    linestring = shapely.from_wkb(wkb)
    return shapely.linearrings(shapely.get_coordinates(linestring))
Exemplo n.º 10
0
 def coords(self):
     """Access to geometry's coordinates (CoordinateSequence)"""
     coords_array = shapely.get_coordinates(self, include_z=self.has_z)
     return CoordinateSequence(coords_array)
Exemplo n.º 11
0
def test_set_coords_nan():
    geoms = np.array([point])
    coords = np.array([[np.nan, np.inf]])
    new_geoms = set_coordinates(geoms, coords)
    assert_equal(coords, get_coordinates(new_geoms))
Exemplo n.º 12
0
def test_get_coords_index_multidim(order):
    geometry = np.array([[point, line_string], [empty, empty]], order=order)
    expected = [0, 1, 1, 1]  # would be [0, 2, 2, 2] with fortran order
    _, actual = get_coordinates(geometry, return_index=True)
    assert_equal(actual, expected)
Exemplo n.º 13
0
def test_get_coords_index(geoms, index):
    _, actual = get_coordinates(np.array(geoms, np.object_), return_index=True)
    expected = np.array(index, dtype=np.intp)
    assert_equal(actual, expected)