def test_relate_pattern(): g = shapely.linestrings([(0, 0), (1, 0), (1, 1)]) polygon = shapely.box(0, 0, 2, 2) assert shapely.relate(g, polygon) == "11F00F212" assert shapely.relate_pattern(g, polygon, "11F00F212") assert shapely.relate_pattern(g, polygon, "*********") assert not shapely.relate_pattern(g, polygon, "F********")
def test_relate_pattern_non_scalar(): with pytest.raises(ValueError, match="only supports scalar"): shapely.relate_pattern([point] * 2, polygon, ["*********"] * 2)
def test_relate_pattern_non_string(pattern): with pytest.raises(TypeError, match="expected string"): shapely.relate_pattern(point, polygon, pattern)
def test_relate_pattern_incorrect_length(): with pytest.raises(shapely.GEOSException, match="Should be length 9"): shapely.relate_pattern(point, polygon, "**") with pytest.raises(shapely.GEOSException, match="Should be length 9"): shapely.relate_pattern(point, polygon, "**********")
def test_relate_pattern_none(g1, g2): assert shapely.relate_pattern(g1, g2, "*" * 9).item() is False
def test_relate_pattern_empty(): with ignore_invalid(): # Empty geometries give 'invalid value encountered' in all predicates # (see https://github.com/libgeos/geos/issues/515) assert shapely.relate_pattern(empty, empty, "*" * 9).item() is True
def relate_pattern(self, other, pattern): """Returns True if the DE-9IM string code for the relationship between the geometries satisfies the pattern, else False""" return bool(shapely.relate_pattern(self, other, pattern))