Skip to content

Commit

Permalink
Merge pull request #400 from ungarj/fix_395_bounds_area
Browse files Browse the repository at this point in the history
intersect area parameter with bounds
  • Loading branch information
ungarj authored Dec 16, 2021
2 parents 1c68bff + d4630bc commit d5f5cf3
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
1 change: 0 additions & 1 deletion mapchete/_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ def as_completed(
self.running_futures = set()

def _finished_futures(self):
logger.debug("%s running futures", len(self.running_futures))
for future in [f for f in self.running_futures if f.done()]:
yield future

Expand Down
2 changes: 1 addition & 1 deletion mapchete/cli/default/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def _validate_bidx(ctx, param, bidx):
@click.option(
"--clip-geometry",
"-c",
type=click.Path(exists=True),
type=click.Path(),
help="Clip output by geometry.",
)
@click.option("--bidx", callback=_validate_bidx, help="Band indexes to copy.")
Expand Down
8 changes: 6 additions & 2 deletions mapchete/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -601,6 +601,9 @@ def area_at_zoom(self, zoom=None):
"""
Return process area for zoom level.
The current process area is an intersection of the defined process area from the configuration,
the spatial subsets provided by extra arguments (e.g. bounds) and the union of all inputs.
Parameters
----------
zoom : int or None
Expand Down Expand Up @@ -638,14 +641,15 @@ def _area_at_zoom(self, zoom):
if v is not None
]
)
self._cache_area_at_zoom[zoom] = (
inputs_and_init = (
input_union.intersection(self.init_area)
if self.init_area
else input_union
)
# if no input items are available, just use init_bounds
else:
self._cache_area_at_zoom[zoom] = self.init_area
inputs_and_init = self.init_area
self._cache_area_at_zoom[zoom] = inputs_and_init.intersection(self.area)
return self._cache_area_at_zoom[zoom]

def bounds_at_zoom(self, zoom=None):
Expand Down
6 changes: 6 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ def aoi_br_geojson():
return os.path.join(TESTDATA_DIR, "aoi_br.geojson")


@pytest.fixture
def sample_geojson():
"""Fixture for sample.geojson"""
return os.path.join(TESTDATA_DIR, "sample.geojson")


@pytest.fixture
def geometrycollection():
"""Fixture for geometrycollection.geojson"""
Expand Down
8 changes: 8 additions & 0 deletions test/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,14 @@ def test_effective_bounds(files_bounds, baselevels):
)


def test_area_and_bounds(cleantopo_br_tiledir, sample_geojson):
outside_bounds = (-1.7578125, 54.931640625, -1.73583984375, 54.95361328125)
with mapchete.open(
dict(cleantopo_br_tiledir.dict, area=sample_geojson), bounds=outside_bounds
) as mp:
assert len(list(mp.get_process_tiles())) == 0


def test_read_mapchete_input(mapchete_input):
"""Read Mapchete files as input files."""
config = MapcheteConfig(mapchete_input.dict)
Expand Down
8 changes: 8 additions & 0 deletions test/testdata/sample.geojson
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"type": "FeatureCollection",
"name": "4mo_north_region_buffered",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature", "properties": { }, "geometry": { "type": "MultiPolygon", "coordinates": [ [ [ [ 67.5, 22.5 ], [ 66.09375, 22.5 ], [ 66.09375, 23.90625 ], [ 64.6875, 23.90625 ], [ 63.28125, 23.90625 ], [ 61.875, 23.90625 ], [ 60.46875, 23.90625 ], [ 59.0625, 23.90625 ], [ 57.65625, 23.90625 ], [ 56.25, 23.90625 ], [ 56.25, 25.3125 ], [ 54.84375, 25.3125 ], [ 53.4375, 25.3125 ], [ 52.03125, 25.3125 ], [ 50.625, 25.3125 ], [ 50.625, 26.71875 ], [ 49.21875, 26.71875 ], [ 49.21875, 28.125 ], [ 47.8125, 28.125 ], [ 46.40625, 28.125 ], [ 45.0, 28.125 ], [ 43.59375, 28.125 ], [ 43.59375, 29.53125 ], [ 42.1875, 29.53125 ], [ 42.1875, 30.9375 ], [ 40.78125, 30.9375 ], [ 39.375, 30.9375 ], [ 37.96875, 30.9375 ], [ 36.5625, 30.9375 ], [ 36.5625, 32.34375 ], [ 35.15625, 32.34375 ], [ 33.75, 32.34375 ], [ 33.75, 33.75 ], [ 33.75, 35.15625 ], [ 32.34375, 35.15625 ], [ 32.34375, 33.75 ], [ 30.9375, 33.75 ], [ 29.53125, 33.75 ], [ 28.125, 33.75 ], [ 26.71875, 33.75 ], [ 25.3125, 33.75 ], [ 23.90625, 33.75 ], [ 22.5, 33.75 ], [ 21.09375, 33.75 ], [ 19.6875, 33.75 ], [ 18.28125, 33.75 ], [ 18.28125, 35.15625 ], [ 16.875, 35.15625 ], [ 15.46875, 35.15625 ], [ 14.0625, 35.15625 ], [ 12.65625, 35.15625 ], [ 12.65625, 36.5625 ], [ 11.25, 36.5625 ], [ 9.84375, 36.5625 ], [ 9.84375, 37.96875 ], [ 8.4375, 37.96875 ], [ 7.03125, 37.96875 ], [ 7.03125, 36.5625 ], [ 5.625, 36.5625 ], [ 4.21875, 36.5625 ], [ 2.8125, 36.5625 ], [ 1.40625, 36.5625 ], [ 0.0, 36.5625 ], [ 0.0, 35.15625 ], [ -1.40625, 35.15625 ], [ -2.8125, 35.15625 ], [ -4.21875, 35.15625 ], [ -5.625, 35.15625 ], [ -7.03125, 35.15625 ], [ -8.4375, 35.15625 ], [ -9.84375, 35.15625 ], [ -11.25, 35.15625 ], [ -12.65625, 35.15625 ], [ -14.0625, 35.15625 ], [ -15.46875, 35.15625 ], [ -16.875, 35.15625 ], [ -16.875, 33.75 ], [ -18.28125, 33.75 ], [ -19.6875, 33.75 ], [ -21.09375, 33.75 ], [ -22.5, 33.75 ], [ -23.90625, 33.75 ], [ -25.3125, 33.75 ], [ -26.71875, 33.75 ], [ -28.125, 33.75 ], [ -29.53125, 33.75 ], [ -30.9375, 33.75 ], [ -32.34375, 33.75 ], [ -33.75, 33.75 ], [ -35.15625, 33.75 ], [ -36.5625, 33.75 ], [ -37.96875, 33.75 ], [ -39.375, 33.75 ], [ -40.78125, 33.75 ], [ -42.1875, 33.75 ], [ -43.59375, 33.75 ], [ -45.0, 33.75 ], [ -46.40625, 33.75 ], [ -47.8125, 33.75 ], [ -49.21875, 33.75 ], [ -50.625, 33.75 ], [ -52.03125, 33.75 ], [ -53.4375, 33.75 ], [ -54.84375, 33.75 ], [ -56.25, 33.75 ], [ -57.65625, 33.75 ], [ -59.0625, 33.75 ], [ -60.46875, 33.75 ], [ -61.875, 33.75 ], [ -63.28125, 33.75 ], [ -64.6875, 33.75 ], [ -64.6875, 32.34375 ], [ -66.09375, 32.34375 ], [ -67.5, 32.34375 ], [ -67.5, 30.9375 ], [ -68.90625, 30.9375 ], [ -70.3125, 30.9375 ], [ -71.71875, 30.9375 ], [ -71.71875, 29.53125 ], [ -73.125, 29.53125 ], [ -74.53125, 29.53125 ], [ -74.53125, 28.125 ], [ -75.9375, 28.125 ], [ -77.34375, 28.125 ], [ -77.34375, 26.71875 ], [ -78.75, 26.71875 ], [ -78.75, 25.3125 ], [ -78.75, 23.90625 ], [ -80.15625, 23.90625 ], [ -81.5625, 23.90625 ], [ -82.96875, 23.90625 ], [ -84.375, 23.90625 ], [ -85.78125, 23.90625 ], [ -87.1875, 23.90625 ], [ -88.59375, 23.90625 ], [ -90.0, 23.90625 ], [ -91.40625, 23.90625 ], [ -92.8125, 23.90625 ], [ -94.21875, 23.90625 ], [ -95.625, 23.90625 ], [ -97.03125, 23.90625 ], [ -97.03125, 25.3125 ], [ -98.4375, 25.3125 ], [ -99.84375, 25.3125 ], [ -99.84375, 26.71875 ], [ -101.25, 26.71875 ], [ -101.25, 28.125 ], [ -102.65625, 28.125 ], [ -104.0625, 28.125 ], [ -105.46875, 28.125 ], [ -105.46875, 29.53125 ], [ -106.875, 29.53125 ], [ -106.875, 30.9375 ], [ -108.28125, 30.9375 ], [ -109.6875, 30.9375 ], [ -111.09375, 30.9375 ], [ -112.5, 30.9375 ], [ -113.90625, 30.9375 ], [ -115.3125, 30.9375 ], [ -115.3125, 32.34375 ], [ -116.71875, 32.34375 ], [ -118.125, 32.34375 ], [ -118.125, 30.9375 ], [ -119.53125, 30.9375 ], [ -120.9375, 30.9375 ], [ -120.9375, 29.53125 ], [ -122.34375, 29.53125 ], [ -123.75, 29.53125 ], [ -125.15625, 29.53125 ], [ -126.5625, 29.53125 ], [ -127.96875, 29.53125 ], [ -129.375, 29.53125 ], [ -130.78125, 29.53125 ], [ -130.78125, 30.9375 ], [ -130.78125, 32.34375 ], [ -130.78125, 33.75 ], [ -130.78125, 35.15625 ], [ -130.78125, 36.5625 ], [ -130.78125, 37.96875 ], [ -130.78125, 39.375 ], [ -130.78125, 40.78125 ], [ -130.78125, 42.1875 ], [ -130.78125, 43.59375 ], [ -130.78125, 45.0 ], [ -130.78125, 46.40625 ], [ -130.78125, 47.8125 ], [ -130.78125, 49.21875 ], [ -130.78125, 50.625 ], [ -130.78125, 52.03125 ], [ -129.375, 52.03125 ], [ -127.96875, 52.03125 ], [ -126.5625, 52.03125 ], [ -125.15625, 52.03125 ], [ -123.75, 52.03125 ], [ -122.34375, 52.03125 ], [ -120.9375, 52.03125 ], [ -119.53125, 52.03125 ], [ -118.125, 52.03125 ], [ -116.71875, 52.03125 ], [ -115.3125, 52.03125 ], [ -113.90625, 52.03125 ], [ -112.5, 52.03125 ], [ -111.09375, 52.03125 ], [ -109.6875, 52.03125 ], [ -108.28125, 52.03125 ], [ -106.875, 52.03125 ], [ -105.46875, 52.03125 ], [ -104.0625, 52.03125 ], [ -102.65625, 52.03125 ], [ -101.25, 52.03125 ], [ -99.84375, 52.03125 ], [ -98.4375, 52.03125 ], [ -97.03125, 52.03125 ], [ -95.625, 52.03125 ], [ -94.21875, 52.03125 ], [ -92.8125, 52.03125 ], [ -91.40625, 52.03125 ], [ -90.0, 52.03125 ], [ -88.59375, 52.03125 ], [ -87.1875, 52.03125 ], [ -85.78125, 52.03125 ], [ -84.375, 52.03125 ], [ -82.96875, 52.03125 ], [ -81.5625, 52.03125 ], [ -80.15625, 52.03125 ], [ -78.75, 52.03125 ], [ -77.34375, 52.03125 ], [ -75.9375, 52.03125 ], [ -74.53125, 52.03125 ], [ -73.125, 52.03125 ], [ -71.71875, 52.03125 ], [ -70.3125, 52.03125 ], [ -68.90625, 52.03125 ], [ -67.5, 52.03125 ], [ -66.09375, 52.03125 ], [ -64.6875, 52.03125 ], [ -63.28125, 52.03125 ], [ -61.875, 52.03125 ], [ -60.46875, 52.03125 ], [ -59.0625, 52.03125 ], [ -57.65625, 52.03125 ], [ -56.25, 52.03125 ], [ -54.84375, 52.03125 ], [ -53.4375, 52.03125 ], [ -52.03125, 52.03125 ], [ -50.625, 52.03125 ], [ -49.21875, 52.03125 ], [ -47.8125, 52.03125 ], [ -46.40625, 52.03125 ], [ -45.0, 52.03125 ], [ -43.59375, 52.03125 ], [ -42.1875, 52.03125 ], [ -40.78125, 52.03125 ], [ -40.78125, 53.4375 ], [ -40.78125, 54.84375 ], [ -39.375, 54.84375 ], [ -37.96875, 54.84375 ], [ -36.5625, 54.84375 ], [ -35.15625, 54.84375 ], [ -35.15625, 56.25 ], [ -33.75, 56.25 ], [ -32.34375, 56.25 ], [ -30.9375, 56.25 ], [ -29.53125, 56.25 ], [ -29.53125, 57.65625 ], [ -29.53125, 59.0625 ], [ -29.53125, 60.46875 ], [ -29.53125, 61.875 ], [ -28.125, 61.875 ], [ -28.125, 63.28125 ], [ -28.125, 64.6875 ], [ -28.125, 66.09375 ], [ -26.71875, 66.09375 ], [ -26.71875, 67.5 ], [ -25.3125, 67.5 ], [ -25.3125, 68.90625 ], [ -23.90625, 68.90625 ], [ -22.5, 68.90625 ], [ -21.09375, 68.90625 ], [ -19.6875, 68.90625 ], [ -19.6875, 70.3125 ], [ -18.28125, 70.3125 ], [ -16.875, 70.3125 ], [ -15.46875, 70.3125 ], [ -15.46875, 71.71875 ], [ -14.0625, 71.71875 ], [ -12.65625, 71.71875 ], [ -12.65625, 73.125 ], [ -11.25, 73.125 ], [ -9.84375, 73.125 ], [ -8.4375, 73.125 ], [ -8.4375, 74.53125 ], [ -7.03125, 74.53125 ], [ -5.625, 74.53125 ], [ -5.625, 73.125 ], [ -4.21875, 73.125 ], [ -2.8125, 73.125 ], [ -1.40625, 73.125 ], [ 0.0, 73.125 ], [ 1.40625, 73.125 ], [ 2.8125, 73.125 ], [ 2.8125, 71.71875 ], [ 4.21875, 71.71875 ], [ 5.625, 71.71875 ], [ 7.03125, 71.71875 ], [ 8.4375, 71.71875 ], [ 9.84375, 71.71875 ], [ 11.25, 71.71875 ], [ 12.65625, 71.71875 ], [ 14.0625, 71.71875 ], [ 14.0625, 73.125 ], [ 15.46875, 73.125 ], [ 16.875, 73.125 ], [ 18.28125, 73.125 ], [ 19.6875, 73.125 ], [ 21.09375, 73.125 ], [ 22.5, 73.125 ], [ 22.5, 74.53125 ], [ 23.90625, 74.53125 ], [ 25.3125, 74.53125 ], [ 26.71875, 74.53125 ], [ 28.125, 74.53125 ], [ 29.53125, 74.53125 ], [ 30.9375, 74.53125 ], [ 32.34375, 74.53125 ], [ 32.34375, 75.9375 ], [ 33.75, 75.9375 ], [ 35.15625, 75.9375 ], [ 36.5625, 75.9375 ], [ 37.96875, 75.9375 ], [ 39.375, 75.9375 ], [ 40.78125, 75.9375 ], [ 42.1875, 75.9375 ], [ 42.1875, 77.34375 ], [ 43.59375, 77.34375 ], [ 45.0, 77.34375 ], [ 46.40625, 77.34375 ], [ 47.8125, 77.34375 ], [ 49.21875, 77.34375 ], [ 50.625, 77.34375 ], [ 52.03125, 77.34375 ], [ 52.03125, 75.9375 ], [ 52.03125, 74.53125 ], [ 52.03125, 73.125 ], [ 52.03125, 71.71875 ], [ 52.03125, 70.3125 ], [ 52.03125, 68.90625 ], [ 52.03125, 67.5 ], [ 52.03125, 66.09375 ], [ 52.03125, 64.6875 ], [ 52.03125, 63.28125 ], [ 53.4375, 63.28125 ], [ 54.84375, 63.28125 ], [ 56.25, 63.28125 ], [ 57.65625, 63.28125 ], [ 59.0625, 63.28125 ], [ 60.46875, 63.28125 ], [ 61.875, 63.28125 ], [ 63.28125, 63.28125 ], [ 64.6875, 63.28125 ], [ 66.09375, 63.28125 ], [ 67.5, 63.28125 ], [ 68.90625, 63.28125 ], [ 70.3125, 63.28125 ], [ 71.71875, 63.28125 ], [ 73.125, 63.28125 ], [ 74.53125, 63.28125 ], [ 75.9375, 63.28125 ], [ 77.34375, 63.28125 ], [ 78.75, 63.28125 ], [ 80.15625, 63.28125 ], [ 81.5625, 63.28125 ], [ 82.96875, 63.28125 ], [ 84.375, 63.28125 ], [ 85.78125, 63.28125 ], [ 87.1875, 63.28125 ], [ 88.59375, 63.28125 ], [ 90.0, 63.28125 ], [ 91.40625, 63.28125 ], [ 92.8125, 63.28125 ], [ 94.21875, 63.28125 ], [ 95.625, 63.28125 ], [ 97.03125, 63.28125 ], [ 98.4375, 63.28125 ], [ 99.84375, 63.28125 ], [ 101.25, 63.28125 ], [ 102.65625, 63.28125 ], [ 102.65625, 61.875 ], [ 102.65625, 60.46875 ], [ 102.65625, 59.0625 ], [ 102.65625, 57.65625 ], [ 102.65625, 56.25 ], [ 102.65625, 54.84375 ], [ 102.65625, 53.4375 ], [ 102.65625, 52.03125 ], [ 102.65625, 50.625 ], [ 102.65625, 49.21875 ], [ 102.65625, 47.8125 ], [ 102.65625, 46.40625 ], [ 102.65625, 45.0 ], [ 102.65625, 43.59375 ], [ 102.65625, 42.1875 ], [ 102.65625, 40.78125 ], [ 102.65625, 39.375 ], [ 102.65625, 37.96875 ], [ 102.65625, 36.5625 ], [ 102.65625, 35.15625 ], [ 102.65625, 33.75 ], [ 102.65625, 32.34375 ], [ 101.25, 32.34375 ], [ 99.84375, 32.34375 ], [ 98.4375, 32.34375 ], [ 98.4375, 30.9375 ], [ 97.03125, 30.9375 ], [ 95.625, 30.9375 ], [ 94.21875, 30.9375 ], [ 94.21875, 32.34375 ], [ 92.8125, 32.34375 ], [ 91.40625, 32.34375 ], [ 90.0, 32.34375 ], [ 88.59375, 32.34375 ], [ 88.59375, 33.75 ], [ 88.59375, 35.15625 ], [ 87.1875, 35.15625 ], [ 85.78125, 35.15625 ], [ 84.375, 35.15625 ], [ 82.96875, 35.15625 ], [ 81.5625, 35.15625 ], [ 80.15625, 35.15625 ], [ 78.75, 35.15625 ], [ 77.34375, 35.15625 ], [ 77.34375, 33.75 ], [ 75.9375, 33.75 ], [ 75.9375, 32.34375 ], [ 75.9375, 30.9375 ], [ 74.53125, 30.9375 ], [ 74.53125, 29.53125 ], [ 74.53125, 28.125 ], [ 73.125, 28.125 ], [ 73.125, 26.71875 ], [ 71.71875, 26.71875 ], [ 71.71875, 25.3125 ], [ 71.71875, 23.90625 ], [ 70.3125, 23.90625 ], [ 68.90625, 23.90625 ], [ 68.90625, 22.5 ], [ 67.5, 22.5 ] ], [ [ -19.6875, 56.25 ], [ -19.6875, 54.84375 ], [ -18.28125, 54.84375 ], [ -18.28125, 53.4375 ], [ -16.875, 53.4375 ], [ -16.875, 52.03125 ], [ -15.46875, 52.03125 ], [ -15.46875, 50.625 ], [ -14.0625, 50.625 ], [ -12.65625, 50.625 ], [ -12.65625, 49.21875 ], [ -11.25, 49.21875 ], [ -9.84375, 49.21875 ], [ -8.4375, 49.21875 ], [ -7.03125, 49.21875 ], [ -7.03125, 50.625 ], [ -5.625, 50.625 ], [ -4.21875, 50.625 ], [ -2.8125, 50.625 ], [ -1.40625, 50.625 ], [ 0.0, 50.625 ], [ 0.0, 52.03125 ], [ 1.40625, 52.03125 ], [ 1.40625, 53.4375 ], [ 2.8125, 53.4375 ], [ 2.8125, 54.84375 ], [ 1.40625, 54.84375 ], [ 1.40625, 56.25 ], [ 1.40625, 57.65625 ], [ 1.40625, 59.0625 ], [ 1.40625, 60.46875 ], [ 0.0, 60.46875 ], [ 0.0, 61.875 ], [ 0.0, 63.28125 ], [ -1.40625, 63.28125 ], [ -1.40625, 61.875 ], [ -2.8125, 61.875 ], [ -2.8125, 60.46875 ], [ -4.21875, 60.46875 ], [ -4.21875, 59.0625 ], [ -5.625, 59.0625 ], [ -7.03125, 59.0625 ], [ -8.4375, 59.0625 ], [ -9.84375, 59.0625 ], [ -9.84375, 60.46875 ], [ -9.84375, 61.875 ], [ -11.25, 61.875 ], [ -11.25, 60.46875 ], [ -12.65625, 60.46875 ], [ -14.0625, 60.46875 ], [ -14.0625, 59.0625 ], [ -15.46875, 59.0625 ], [ -16.875, 59.0625 ], [ -16.875, 57.65625 ], [ -18.28125, 57.65625 ], [ -19.6875, 57.65625 ], [ -19.6875, 56.25 ] ] ] ] } }
]
}

0 comments on commit d5f5cf3

Please sign in to comment.