def test_Extent___init__(): # basic ex1 = Extent(3, -4, -5, 10, srs=EPSG4326) assert (ex1.xyXY == (-5, -4, 3, 10)) ex1b = Extent((3, -4, -5, 10), srs=EPSG4326) assert (ex1b.xyXY == (-5, -4, 3, 10)) # from source ex2 = Extent.fromVector( source=MULTI_FTR_SHAPE_PATH ) assert (ex2.xyXY == (6.212409755390094, 48.864894076418935, 7.782393932571588, 49.932593106005655)) # from source ex3 = Extent.fromRaster( source=AACHEN_ELIGIBILITY_RASTER ) assert (ex3.xyXY == (5.974, 50.494, 6.42, 50.951)) assert ex3.srs.IsSame(EPSG4326)
def test_Extent_createRaster(): ex = Extent.fromRaster(CLC_RASTER_PATH) # Test failure on bad resolution # 200m does not fit to the CLC raster by design try: r = ex.createRaster(pixelHeight=200, pixelWidth=200, fill=2) assert False except error.GeoKitExtentError: assert True else: assert False # Test successful r = ex.createRaster(pixelHeight=100, pixelWidth=100, fill=2) assert np.isclose(raster.extractMatrix(r).mean(), 2)
def test_Extent_findWithin(): bigExt = Extent.fromRaster(CLC_RASTER_PATH) smallExt = Extent(4050200, 3076800, 4055400, 3080300, srs=EPSG3035) # do regular w1 = bigExt.findWithin(smallExt, res=100) assert w1.xStart == 381 # xStart assert w1.yStart == 307 # yStart assert w1.xWin == 52 # xWin assert w1.yWin == 35 # yWin # do flipped (only yStart should change) w2 = bigExt.findWithin(smallExt, res=100, yAtTop=False) assert w2.xStart == 381 # flipped - xStart assert w2.yStart == 450 # flipped - yStart assert w2.xWin == 52 # flipped - xWin assert w2.yWin == 35 # flipped - yWin
def test_Extent_fromRaster(): ex1 = Extent.fromRaster(CLC_RASTER_PATH) assert np.isclose(ex1.xMin, 4012100) assert np.isclose(ex1.yMin, 3031800) assert np.isclose(ex1.xMax, 4094600) assert np.isclose(ex1.yMax, 3111000)