def test_RegionMask_pixelRes(): # test succeed rm1 = RegionMask.fromMask(Extent(0, 0, 100, 100, srs=EPSG3035), MASK_DATA) ps = rm1.pixelRes assert ps == 1 # test fail rm2 = RegionMask.fromMask(Extent(0, 0, 100, 200, srs=EPSG3035), MASK_DATA) try: ps = rm2.pixelRes assert False except error.GeoKitRegionMaskError as e: assert str( e) == 'pixelRes only accessable when pixelWidth equals pixelHeight' else: assert False
def test_RegionMask_fromMask(): ext = Extent(0, 0, 100, 100, srs=EPSG3035) rm = RegionMask.fromMask( mask=MASK_DATA, extent=ext, attributes={"hats": 5}) assert rm.mask.sum() == MASK_DATA.sum() # mask assert rm.extent == ext # extent assert rm.srs.IsSame(ext.srs) # srs
def test_RegionMask_fromMask(): ext = Extent(0, 0, 100, 100, srs=EPSG3035) rm = RegionMask.fromMask(mask=MASK_DATA, extent=ext, attributes={"hats": 5}) if not rm.mask.sum() == MASK_DATA.sum(): error("fromSource - mask") if not rm.extent == ext: error("fromSource - extent") if not rm.srs.IsSame(ext.srs): error("fromSource - srs") print("RegionMask_fromMask passed")
def test_RegionMask_pixelRes(): # test succeed rm1 = RegionMask.fromMask(Extent(0, 0, 100, 100, srs=EPSG3035), MASK_DATA) ps = rm1.pixelRes if not ps == 1: error("pixelRes") # test fail rm2 = RegionMask.fromMask(Extent(0, 0, 100, 200, srs=EPSG3035), MASK_DATA) try: ps = rm2.pixelRes error("pixelRes - fail test") except GeoKitRegionMaskError as e: if not str( e ) == 'pixelRes only accessable when pixelWidth equals pixelHeight': error("pixelRes - fail test") else: error("pixelRes - fail test") print("RegionMask_pixelRes passed")