def test_move(fps1px): fps = fps1px with buzz.Env(warnings=False, allow_complex_footprint=True): # Test the `warnings` deprecation assert fpeq( fps.B, fps.A.move(fps.B.tl), fps.B.move(fps.B.tl), fps.C.move(fps.B.tl), fps.A.move(fps.B.tl, fps.B.tr), fps.B.move(fps.B.tl, fps.B.tr), fps.C.move(fps.B.tl, fps.B.tr), fps.A.move(fps.B.tl, fps.B.tr, fps.B.br), fps.B.move(fps.B.tl, fps.B.tr, fps.B.br), fps.C.move(fps.B.tl, fps.B.tr, fps.B.br), ) aff = ( Affine.translation(*fps.A.bl) * Affine.rotation(45) * Affine.scale(2**0.5, 2**0.5 * -2) ) assert fpeq( buzz.Footprint(gt=aff.to_gdal(), rsize=(1, 1)), fps.A.move(fps.A.bl, fps.A.tr, fps.I.tr), fps.B.move(fps.A.bl, fps.A.tr, fps.I.tr), fps.C.move(fps.A.bl, fps.A.tr, fps.I.tr), ) with pytest.raises(ValueError, match='angle'): fps.C.move(fps.A.bl, fps.A.tr, fps.I.c)
def test_mode1(fps, shp1_path, tif1_path, shp2_path, tif2_path): ds = buzz.DataSource() ds.open_raster('rast1', tif1_path) ds.open_vector('poly1', shp1_path) ds.open_raster('rast2', tif2_path) ds.open_vector('poly2', shp2_path) # Test footprints equality assert fpeq( fps.AI, ds.rast1.fp, ds.rast1.fp_origin, buzz.Footprint.of_extent(ds.poly1.extent, fps.AI.scale), ds.rast2.fp, ds.rast2.fp_origin, buzz.Footprint.of_extent(ds.poly2.extent, fps.AI.scale), ) # Test what's written in all 4 files rast1 = ds.rast1.get_data() rast2 = ds.rast2.get_data() for i, letter in enumerate(string.ascii_uppercase[:9]): poly1 = ds.poly1.get_data(i, None) raster1_polys = ds.rast1.fp.find_polygons(rast1 == ord(letter)) assert len(raster1_polys) == 1 assert (poly1 ^ raster1_polys[0]).is_empty poly2 = ds.poly2.get_data(i, None) raster2_polys = ds.rast2.fp.find_polygons(rast2 == ord(letter)) assert len(raster2_polys) == 1 assert (poly2 ^ raster2_polys[0]).is_empty
def test_clip(fps1px): fps = fps1px assert fpeq( fps.E, fps.E.clip(0, 0, 1, 1), fps.E.clip(-1, -1, 1, 1), fps.AI.clip(1, 1, 2, 2), fps.AI.clip(-2, -2, -1, -1), fps.BI.clip(0, 1, 1, 2), fps.BI.clip(0 - 2, 1 - 3, 1 - 2, 2 - 3), )
def test_mode4(fps, shp1_path, tif1_path, random_path_shp, random_path_tif, env): wkt_origin = buzz.srs.wkt_of_file(tif1_path) wkt_work = buzz.srs.wkt_of_file(tif1_path, center=True) ds = buzz.DataSource(wkt_work, sr_origin=wkt_origin) ds.open_raster('rast', tif1_path) ds.open_vector('poly', shp1_path) with buzz.Env(allow_complex_footprint=True): ds.create_avector(random_path_shp, 'polygon', [], sr=None).close() ds.create_araster(random_path_tif, fps.AI, 'int32', 1, {}, sr=None).close() fp_poly = buzz.Footprint.of_extent(ds.poly.extent, ds.rast.fp.scale) fp_poly_origin = buzz.Footprint.of_extent(ds.poly.extent_origin, ds.rast.fp_origin.scale) assert fpeq( ds.rast.fp, fp_poly, ) assert fpeq( ds.rast.fp_origin, fps.AI, fp_poly_origin, ) rast = ds.rast.get_data() def f(x, y, z=None): return np.around(x, 6), np.around(y, 6) for i, letter in enumerate(string.ascii_uppercase[:9]): poly = ds.poly.get_data(i, None) raster_polys = ds.rast.fp.find_polygons(rast == ord(letter)) assert len(raster_polys) == 1 raster_poly = raster_polys[0] del raster_polys poly = shapely.ops.transform(f, poly) raster_poly = shapely.ops.transform(f, poly) assert (poly ^ raster_poly).is_empty
def test_rectangles(fps): for a, b in itertools.combinations_with_replacement(fps.values(), 2): if a.poly.overlaps(b.poly) or a.poly.covers(b.poly) or b.poly.covers( a.poly): assert fpeq(a.intersection(b), b.intersection(a)) dfs = [ fps.DF, fps.AF.intersection(fps.DI), fps.DF.intersection(fps.AI), fps.DF.intersection(fps.AF), fps.DF.intersection(fps.DI), ] for a in dfs: assert fpeq(a, dfs[0]) bhs = [ fps.BH, fps.AH.intersection(fps.BI), fps.BH.intersection(fps.AI), fps.BH.intersection(fps.AH), fps.BH.intersection(fps.BI), ] for a in bhs: assert fpeq(a, bhs[0]) assert fpeq( fps.E, fps.E.intersection(fps.E), fps.AI.intersection( fps.BH, fps.DF, fps.AH, fps.BI, fps.AF, fps.DI, fps.AI, ), )
def test_points(fps1px): """Test points at fps.E's points of interest""" fps = fps1px assert fpeq( fps.E, fps.AI.intersection(sg.Point(*fps.E.c)), fps.AI.intersection(sg.Point(*fps.E.t)), fps.AI.intersection(sg.Point(*fps.E.l)), fps.AI.intersection(sg.Point(*fps.E.tl)), ) assert fpeq( fps.I, fps.AI.intersection(sg.Point(*fps.E.br)), ) assert fpeq( fps.H, fps.AI.intersection(sg.Point(*fps.E.bl)), fps.AI.intersection(sg.Point(*fps.E.b)), ) assert fpeq( fps.F, fps.AI.intersection(sg.Point(*fps.E.tr)), fps.AI.intersection(sg.Point(*fps.E.r)), )
def test_mode2(fps, shp1_path, tif1_path, shp2_path, tif2_path, random_path_shp, random_path_tif, env): ds = buzz.DataSource(sr_work=SR1['wkt']) ds.open_raster('rast1', tif1_path) ds.open_vector('poly1', shp1_path) ds.open_raster('rast2', tif2_path) ds.open_vector('poly2', shp2_path) # Test file creation without spatial reference with buzz.Env(allow_complex_footprint=True): with pytest.raises(ValueError, match='spatial refe'): ds.create_avector(random_path_shp, 'polygon', [], sr=None) with pytest.raises(ValueError, match='spatial refe'): ds.create_araster(random_path_tif, fps.AI, 'int32', 1, {}, sr=None) # Test foorprints equality assert fpeq( fps.AI, ds.rast1.fp, ds.rast1.fp_origin, buzz.Footprint.of_extent(ds.poly1.extent, fps.AI.scale), ds.rast2.fp_origin, ) assert fpeq( ds.rast2.fp, buzz.Footprint.of_extent(ds.poly2.extent, fps.AI.scale), ) assert ds.rast2.fp != ds.rast1.fp # Test file creation with/without conversion of footprint with buzz.Env(allow_complex_footprint=True): with ds.create_araster(random_path_tif, fps.AI, 'int32', 1, sr=SR1['wkt']).delete as r: assert fpeq(fps.AI, r.fp, r.fp_origin) with ds.create_araster(random_path_tif, fps.AI, 'int32', 1, sr=SR2['wkt']).delete as r: assert fpeq( fps.AI, r.fp, ) assert fps.AI != r.fp_origin # Test what's written in rast1/poly1 files rast1 = ds.rast1.get_data() def f(x, y, z=None): return np.around(x, 6), np.around(y, 6) for i, letter in enumerate(string.ascii_uppercase[:9]): poly1 = ds.poly1.get_data(i, None) raster1_polys = ds.rast1.fp.find_polygons(rast1 == ord(letter)) assert len(raster1_polys) == 1 raster1_poly = raster1_polys[0] del raster1_polys poly1 = shapely.ops.transform(f, poly1) raster1_poly = shapely.ops.transform(f, poly1) assert (poly1 ^ raster1_poly).is_empty
def test_mode4(fps, shp1_path, tif1_path, shp2_path, tif2_path, shp3_path, tif3_path, random_path_shp, random_path_tif, env): ds = buzz.Dataset(sr_work=SR1['wkt'], sr_forced=SR2['wkt']) ds.open_raster('tif1', tif1_path) ds.open_vector('shp1', shp1_path) ds.open_raster('tif2', tif2_path) ds.open_vector('shp2', shp2_path) ds.open_raster('tif3', tif3_path) ds.open_vector('shp3', shp3_path) # Test file creation without spatial reference with buzz.Env(allow_complex_footprint=True): with ds.acreate_vector(random_path_shp, 'polygon', [], sr=None).close as r: assert r.wkt_stored == None assert sreq(r.wkt_virtual, SR2['wkt']) with ds.acreate_raster(random_path_tif, fps.AI, 'int32', 1, {}, sr=None).close as v: assert v.wkt_stored == None assert sreq(v.wkt_virtual, SR2['wkt']) # Test SR equality assert sreq( ds.wkt, ds.proj4, ds.tif1.wkt_stored, ds.tif1.proj4_stored, ds.shp1.wkt_stored, ds.shp1.proj4_stored, ) assert sreq( ds.tif1.wkt_virtual, ds.tif1.proj4_virtual, ds.shp1.wkt_virtual, ds.shp1.proj4_virtual, ds.tif2.wkt_virtual, ds.tif2.proj4_virtual, ds.shp2.wkt_virtual, ds.shp2.proj4_virtual, ds.tif2.wkt_stored, ds.tif2.proj4_stored, ds.shp2.wkt_stored, ds.shp2.proj4_stored, ds.tif3.wkt_virtual, ds.tif3.proj4_virtual, ds.shp3.wkt_virtual, ds.shp3.proj4_virtual, ) assert not sreq(ds.tif1.wkt_stored, ds.tif2.wkt_stored) assert (None == ds.tif3.wkt_stored == ds.tif3.proj4_stored == ds.shp3.wkt_stored == ds.shp3.proj4_stored) # Test foorprints equality assert fpeq( fps.AI, # tif/shp 1 ds.tif1.fp_origin, buzz.Footprint.of_extent(ds.shp1.extent_stored, fps.AI.scale), buzz.Footprint.of_extent(ds.shp1.bounds_stored[[0, 2, 1, 3]], fps.AI.scale), # tif/shp 2 ds.tif2.fp_origin, buzz.Footprint.of_extent(ds.shp2.extent_stored, fps.AI.scale), buzz.Footprint.of_extent(ds.shp2.bounds_stored[[0, 2, 1, 3]], fps.AI.scale), # tif/shp 3 ds.tif3.fp_origin, buzz.Footprint.of_extent(ds.shp3.extent_stored, fps.AI.scale), buzz.Footprint.of_extent(ds.shp3.bounds_stored[[0, 2, 1, 3]], fps.AI.scale), ) assert fpeq( # tif/shp 1 ds.tif1.fp, buzz.Footprint.of_extent(ds.shp1.extent, fps.AI.scale), buzz.Footprint.of_extent(ds.shp1.bounds[[0, 2, 1, 3]], fps.AI.scale), # tif/shp 2 ds.tif2.fp, buzz.Footprint.of_extent(ds.shp2.extent, fps.AI.scale), buzz.Footprint.of_extent(ds.shp2.bounds[[0, 2, 1, 3]], fps.AI.scale), # tif/shp 3 ds.tif3.fp, buzz.Footprint.of_extent(ds.shp3.extent, fps.AI.scale), buzz.Footprint.of_extent(ds.shp3.bounds[[0, 2, 1, 3]], fps.AI.scale), ) assert ds.tif1.fp != ds.tif1.fp_stored # Test what's written in all 6 files tif1 = ds.tif1.get_data() tif2 = ds.tif2.get_data() tif3 = ds.tif3.get_data() assert np.all(tif1 == tif2) assert np.all(tif1 == tif3) def f(x, y, z=None): return np.around(x, 6), np.around(y, 6) for i, letter in enumerate(string.ascii_uppercase[:9]): # tif/shp 1 shp1 = ds.shp1.get_data(i, None) shp1 = shapely.ops.transform(f, shp1) raster1_polys = ds.tif1.fp.find_polygons(tif1 == ord(letter)) assert len(raster1_polys) == 1 raster1_poly = raster1_polys[0] raster1_poly = shapely.ops.transform(f, shp1) assert (shp1 ^ raster1_poly).is_empty # tif/shp 2 shp2 = ds.shp2.get_data(i, None) shp2 = shapely.ops.transform(f, shp2) raster2_polys = ds.tif2.fp.find_polygons(tif2 == ord(letter)) assert len(raster2_polys) == 1 raster2_poly = raster2_polys[0] raster2_poly = shapely.ops.transform(f, shp2) assert (shp2 ^ raster2_poly).is_empty # tif/shp 3 shp3 = ds.shp3.get_data(i, None) shp3 = shapely.ops.transform(f, shp3) raster3_polys = ds.tif3.fp.find_polygons(tif3 == ord(letter)) assert len(raster3_polys) == 1 raster3_poly = raster3_polys[0] raster3_poly = shapely.ops.transform(f, shp3) assert (shp3 ^ raster3_poly).is_empty
def test_mode2(fps, shp1_path, tif1_path, shp2_path, tif2_path, shp3_path, tif3_path, random_path_shp, random_path_tif, env): ds = buzz.Dataset(sr_work=SR1['wkt']) ds.open_raster('tif1', tif1_path) ds.open_vector('shp1', shp1_path) ds.open_raster('tif2', tif2_path) ds.open_vector('shp2', shp2_path) # Test file creation/opening without spatial reference with buzz.Env(allow_complex_footprint=True): with pytest.raises(ValueError, match='spatial refe'): ds.acreate_vector(random_path_shp, 'polygon', [], sr=None) with pytest.raises(ValueError, match='spatial refe'): ds.acreate_raster(random_path_tif, fps.AI, 'int32', 1, {}, sr=None) with pytest.raises(ValueError, match='spatial refe'): ds.aopen_raster(tif3_path) with pytest.raises(ValueError, match='spatial refe'): ds.aopen_vector(shp3_path) # Test SR equality assert sreq( ds.wkt, ds.proj4, ds.tif1.wkt_virtual, ds.tif1.wkt_stored, ds.tif1.proj4_virtual, ds.tif1.proj4_stored, ds.shp1.wkt_virtual, ds.shp1.wkt_stored, ds.shp1.proj4_virtual, ds.shp1.proj4_stored, ) assert sreq( ds.tif2.wkt_virtual, ds.tif2.proj4_virtual, ds.shp2.wkt_virtual, ds.shp2.proj4_virtual, ds.tif2.wkt_stored, ds.tif2.proj4_stored, ds.shp2.wkt_stored, ds.shp2.proj4_stored, ) assert not sreq(ds.tif1.wkt_stored, ds.tif2.wkt_stored) # Test foorprints equality assert fpeq( fps.AI, # tif/shp 1 ds.tif1.fp, ds.tif1.fp_origin, buzz.Footprint.of_extent(ds.shp1.extent, fps.AI.scale), buzz.Footprint.of_extent(ds.shp1.extent_stored, fps.AI.scale), buzz.Footprint.of_extent(ds.shp1.bounds[[0, 2, 1, 3]], fps.AI.scale), buzz.Footprint.of_extent(ds.shp1.bounds_stored[[0, 2, 1, 3]], fps.AI.scale), # tif/shp 2 ds.tif2.fp_origin, buzz.Footprint.of_extent(ds.shp2.extent_stored, fps.AI.scale), buzz.Footprint.of_extent(ds.shp2.bounds_stored[[0, 2, 1, 3]], fps.AI.scale), ) assert fpeq( ds.tif2.fp, buzz.Footprint.of_extent(ds.shp2.extent, fps.AI.scale), buzz.Footprint.of_extent(ds.shp2.bounds[[0, 2, 1, 3]], fps.AI.scale), ) assert ds.tif2.fp != ds.tif1.fp # Test file creation with/without conversion of footprint with buzz.Env(allow_complex_footprint=True): with ds.acreate_raster(random_path_tif, fps.AI, 'int32', 1, sr=SR1['wkt'], ow=1).delete as r: assert fpeq(fps.AI, r.fp, r.fp_origin) with ds.acreate_raster(random_path_tif, fps.AI, 'int32', 1, sr=SR2['wkt'], ow=1).delete as r: assert fpeq( fps.AI, r.fp, ) assert fps.AI != r.fp_origin # Test what's written in all 4 files tif1 = ds.tif1.get_data() tif2 = ds.tif2.get_data() assert np.all(tif1 == tif2) def f(x, y, z=None): return np.around(x, 6), np.around(y, 6) for i, letter in enumerate(string.ascii_uppercase[:9]): # tif/shp 1 shp1 = ds.shp1.get_data(i, None) shp1 = shapely.ops.transform(f, shp1) raster1_polys = ds.tif1.fp.find_polygons(tif1 == ord(letter)) assert len(raster1_polys) == 1 raster1_poly = raster1_polys[0] raster1_poly = shapely.ops.transform(f, shp1) assert (shp1 ^ raster1_poly).is_empty # tif/shp 2 shp2 = ds.shp2.get_data(i, None) shp2 = shapely.ops.transform(f, shp2) raster2_polys = ds.tif2.fp.find_polygons(tif2 == ord(letter)) assert len(raster2_polys) == 1 raster2_poly = raster2_polys[0] raster2_poly = shapely.ops.transform(f, shp2) assert (shp2 ^ raster2_poly).is_empty
def test_mode1(fps, shp1_path, tif1_path, shp2_path, tif2_path, shp3_path, tif3_path): ds = buzz.Dataset() ds.open_raster('tif1', tif1_path) ds.open_vector('shp1', shp1_path) ds.open_raster('tif2', tif2_path) ds.open_vector('shp2', shp2_path) ds.open_raster('tif3', tif3_path) ds.open_vector('shp3', shp3_path) # Test SR equality assert sreq( ds.tif1.wkt_virtual, ds.tif1.wkt_stored, ds.tif1.proj4_virtual, ds.tif1.proj4_stored, ds.shp1.wkt_virtual, ds.shp1.wkt_stored, ds.shp1.proj4_virtual, ds.shp1.proj4_stored, ) assert sreq( ds.tif2.wkt_virtual, ds.tif2.wkt_stored, ds.tif2.proj4_virtual, ds.tif2.proj4_stored, ds.shp2.wkt_virtual, ds.shp2.wkt_stored, ds.shp2.proj4_virtual, ds.shp2.proj4_stored, ) assert not sreq(ds.tif1.wkt_stored, ds.tif2.wkt_stored) assert (None == ds.wkt == ds.proj4 == ds.tif3.wkt_virtual == ds.tif3.wkt_stored == ds.tif3.proj4_virtual == ds.tif3.proj4_stored == ds.shp3.wkt_virtual == ds.shp3.wkt_stored == ds.shp3.proj4_virtual == ds.shp3.proj4_stored) # Test footprints equality assert fpeq( fps.AI, # tif/shp 1 ds.tif1.fp, ds.tif1.fp_origin, buzz.Footprint.of_extent(ds.shp1.extent, fps.AI.scale), buzz.Footprint.of_extent(ds.shp1.extent_stored, fps.AI.scale), buzz.Footprint.of_extent(ds.shp1.bounds[[0, 2, 1, 3]], fps.AI.scale), buzz.Footprint.of_extent(ds.shp1.bounds_stored[[0, 2, 1, 3]], fps.AI.scale), # tif/shp 2 ds.tif2.fp, ds.tif2.fp_origin, buzz.Footprint.of_extent(ds.shp2.extent, fps.AI.scale), buzz.Footprint.of_extent(ds.shp2.extent_stored, fps.AI.scale), buzz.Footprint.of_extent(ds.shp2.bounds[[0, 2, 1, 3]], fps.AI.scale), buzz.Footprint.of_extent(ds.shp2.bounds_stored[[0, 2, 1, 3]], fps.AI.scale), # tif/shp 3 ds.tif3.fp, ds.tif3.fp_origin, buzz.Footprint.of_extent(ds.shp3.extent, fps.AI.scale), buzz.Footprint.of_extent(ds.shp3.extent_stored, fps.AI.scale), buzz.Footprint.of_extent(ds.shp3.bounds[[0, 2, 1, 3]], fps.AI.scale), buzz.Footprint.of_extent(ds.shp3.bounds_stored[[0, 2, 1, 3]], fps.AI.scale), ) # Test what's written in all 6 files tif1 = ds.tif1.get_data() tif2 = ds.tif2.get_data() tif3 = ds.tif3.get_data() assert np.all(tif1 == tif2) assert np.all(tif1 == tif3) for i, letter in enumerate(string.ascii_uppercase[:9]): # tif/shp 1 shp1 = ds.shp1.get_data(i, None) raster1_polys = ds.tif1.fp.find_polygons(tif1 == ord(letter)) assert len(raster1_polys) == 1 assert (shp1 ^ raster1_polys[0]).is_empty # tif/shp 2 shp2 = ds.shp2.get_data(i, None) raster2_polys = ds.tif2.fp.find_polygons(tif2 == ord(letter)) assert len(raster2_polys) == 1 assert (shp2 ^ raster2_polys[0]).is_empty # tif/shp 3 shp3 = ds.shp3.get_data(i, None) raster3_polys = ds.tif3.fp.find_polygons(tif3 == ord(letter)) assert len(raster3_polys) == 1 assert (shp3 ^ raster3_polys[0]).is_empty
def test_corner_cases(fps1px): fps = fps1px with pytest.raises(ValueError): fps.A.intersection() with pytest.raises(ValueError): fps.A.intersection(fps.A, hello=True) with pytest.raises(TypeError): fps.A.intersection(42) assert fpeq( fps.BH, fps.AH.intersection(_FtPoly(fps.BI.__geo_interface__)), ) with pytest.raises(ValueError): fps.A.intersection(fps.A, scale='hello') with pytest.raises(ValueError): fps.A.intersection(fps.A, rotation='hello') with pytest.raises(ValueError): fps.A.intersection(fps.A, alignment='hello') # reso assert fpeq( buzz.Footprint(rsize=[2, 6], size=fps.BH.size, tl=fps.BH.tl), fps.AH.intersection(fps.BI, scale=0.5), fps.AH.intersection(fps.BI, scale=[0.5, -0.5]), fps.AH.intersection(fps.BI, scale=[0.5]), ) with pytest.raises(ValueError): fps.AH.intersection(fps.BI, scale=[]) with pytest.raises(ValueError): fps.AH.intersection(fps.BI, scale=0) lowest = fps.BH.intersection(fps.BH, scale=0.5) highest = fps.BH.intersection(fps.BH, scale=1.0) assert fpeq( lowest, lowest.intersection(highest, scale='lowest'), highest.intersection(lowest, scale='lowest'), ) assert fpeq( highest, highest.intersection(lowest, scale='highest'), lowest.intersection(highest, scale='highest'), ) # rot / align assert fpeq( fps.BH, fps.AH.intersection(fps.BI, rotation=0), fps.AH.intersection(fps.BI, alignment=fps.BH.tl), ) with pytest.raises(ValueError): fps.AH.intersection(fps.BI, alignment=[]) assert fpeq( buzz.Footprint(rsize=[1 + 1, 3 + 1], size=fps.BH.size * [2 / 1, 4 / 3], tl=fps.BH.tl - [0.5, -0.5]), fps.BH.intersection(fps.BH, alignment=[0.5, 0.5]), ) assert fpeq( fps.BH, fps.BH.intersection(fps.BH, alignment='tl'), ) with buzz.Env(allow_complex_footprint=True): for angle in np.r_[0:180:13j]: rotated = fps.E.intersection(fps.E, rotation=angle) nofit = angle % 90 != 0 if nofit: assert tuple(rotated.rsize) == (2, 2) else: assert tuple(rotated.rsize) == (1, 1) assert all(np.around(rotated.scale, 3) == (1, -1)) assert np.around(rotated.angle, 3) == angle diff = rotated.poly - fps.E.poly if nofit: assert np.around(diff.area, 3) == 3.0 else: assert np.around(diff.area, 3) == 0.0 dot = np.dot(fps.E.lrvec / fps.E.w, rotated.lrvec / rotated.w) angle_real = np.arccos(dot) / np.pi * 180 assert np.around(angle_real) == angle # h**o assert fpeq( fps.BH, fps.BH.intersection(fps.BH, homogeneous=True), ) with pytest.raises(ValueError, match='grid'): fps.BH.intersection( fps.BH.intersection(fps.BH, scale=0.5), homogeneous=True, ) with pytest.raises(ValueError, match='grid'): fps.BH.intersection( fps.BH.intersection(fps.BH, alignment=[0.5, 0.5]), homogeneous=True, ) with buzz.Env(allow_complex_footprint=True): with pytest.raises(ValueError, match='grid'): fps.AH.intersection( fps.E.intersection(fps.E, rotation=42), homogeneous=True, ) # fit stripe = sg.Polygon([fps.A.tr, fps.I.tr, fps.I.bl, fps.A.bl]) assert fpeq( fps.AI, fps.AI.intersection(stripe), fps.AI.intersection(stripe, rotation=0), ) with buzz.Env(allow_complex_footprint=True): assert fpeq( fps.AI.intersection(stripe, rotation='fit'), fps.AI.intersection(stripe, rotation=45), ) # misc with pytest.raises(ValueError, match='touch'): fps.A.intersection(fps.B) with pytest.raises(ValueError, match='empty'): fps.A.intersection(fps.C) with pytest.raises(ValueError, match='touch'): fps.A.intersection(fps.D)
def test_lines(fps1px): """Test small lines centered at fps.E's points of interest Test all 3 orientations """ fps = fps1px def _f(coords, axes): """create small line around point""" axes = np.asarray(axes) assert 1 <= axes.sum() <= 2 epsilon = 10**-(buzz.env.significant - 1) tl = coords - (epsilon, epsilon) * axes * (1, -1) br = coords + (epsilon, epsilon) * axes * (1, -1) return sg.LineString([tl, br]) # Middle, size 1 assert fpeq( fps.E, fps.AI.intersection(_f(fps.E.c, (1, 0))), fps.AI.intersection(_f(fps.E.c, (1, 1))), fps.AI.intersection(_f(fps.E.c, (0, 1))), fps.AI.intersection(_f(fps.E.l, (0, 1))), fps.AI.intersection(_f(fps.E.t, (1, 0))), ) # Connectivity 4, size 1&2 assert fpeq( fps.BE, fps.AI.intersection(_f(fps.E.t, (1, 1))), fps.AI.intersection(_f(fps.E.t, (0, 1))), fps.AI.intersection(_f(fps.E.tl, (0, 1))), ) assert fpeq( fps.EF, fps.AI.intersection(_f(fps.E.r, (1, 0))), fps.AI.intersection(_f(fps.E.r, (1, 1))), fps.AI.intersection(_f(fps.E.tr, (1, 0))), ) assert fpeq( fps.F, fps.AI.intersection(_f(fps.E.r, (0, 1))), ) assert fpeq( fps.EH, fps.AI.intersection(_f(fps.E.b, (1, 1))), fps.AI.intersection(_f(fps.E.b, (0, 1))), fps.AI.intersection(_f(fps.E.bl, (0, 1))), ) assert fpeq( fps.H, fps.AI.intersection(_f(fps.E.b, (1, 0))), ) assert fpeq( fps.DE, fps.AI.intersection(_f(fps.E.l, (1, 0))), fps.AI.intersection(_f(fps.E.l, (1, 1))), fps.AI.intersection(_f(fps.E.tl, (1, 0))), ) # Connectivity 8, size 4 assert fpeq( fps.AE, fps.AI.intersection(_f(fps.E.tl, (1, 1))), ) assert fpeq( fps.BF, fps.AI.intersection(_f(fps.E.tr, (1, 1))), ) assert fpeq( fps.EI, fps.AI.intersection(_f(fps.E.br, (1, 1))), ) assert fpeq( fps.DH, fps.AI.intersection(_f(fps.E.bl, (1, 1))), ) # Connectivity 8, size 2 assert fpeq( fps.CF, fps.AI.intersection(_f(fps.E.tr, (0, 1))), ) assert fpeq( fps.FI, fps.AI.intersection(_f(fps.E.br, (0, 1))), ) assert fpeq( fps.HI, fps.AI.intersection(_f(fps.E.br, (1, 0))), ) assert fpeq( fps.GH, fps.AI.intersection(_f(fps.E.bl, (1, 0))), ) # Bonus (diagonals) assert fpeq( fps.AI, fps.AI.intersection(sg.LineString([fps.AI.tl, fps.AI.br])), fps.AI.intersection(sg.LineString([fps.AI.bl, fps.AI.tr])), fps.AI.intersection(sg.LineString([fps.A.t, fps.I.b])), fps.AI.intersection(sg.LineString([fps.A.l, fps.I.r])), fps.AI.intersection(sg.LineString([fps.A.c, fps.I.c])), ) # Bonus 2 (multi point line) assert fpeq( fps.AI, fps.AI.intersection(sg.LineString([ fps.A.c, fps.F.c, fps.G.c, ])), fps.AI.intersection(sg.LineString([ fps.A.c, fps.C.c, fps.G.r, ])), )