Skip to content

Commit 5feb757

Browse files
Fix resetting of extent with local files (#155) (#156)
Co-authored-by: Joris Van den Bossche <[email protected]>
1 parent 27d60da commit 5feb757

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

contextily/plotting.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,19 +177,21 @@ def add_basemap(
177177
}
178178
]
179179
image, img_transform = riomask(raster, window, crop=True)
180+
extent = left, right, bottom, top
180181
else:
181182
# Read full
182183
image = np.array([band for band in raster.read()])
183184
img_transform = raster.transform
185+
bb = raster.bounds
186+
extent = bb.left, bb.right, bb.bottom, bb.top
184187
# Warp
185188
if (crs is not None) and (raster.crs != crs):
186189
image, bounds, _ = _warper(
187190
image, img_transform, raster.crs, crs, resampling
188191
)
189-
else:
190-
bounds = raster.bounds
192+
extent = bounds.left, bounds.right, bounds.bottom, bounds.top
191193
image = image.transpose(1, 2, 0)
192-
extent = bounds.left, bounds.right, bounds.bottom, bounds.top
194+
193195
# Plotting
194196
if image.shape[2] == 1:
195197
image = image[:, :, 0]

tests/test_ctx.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -294,13 +294,7 @@ def test_add_basemap():
294294
loc = ctx.Place(SEARCH, path="./test2.tif", zoom_adjust=ADJUST)
295295
ctx.add_basemap(ax, url="./test2.tif", reset_extent=True)
296296

297-
raster_extent = (
298-
-11740803.981631357,
299-
-11701668.223149346,
300-
4852910.488797556,
301-
4892046.247279563,
302-
)
303-
assert_array_almost_equal(raster_extent, ax.images[0].get_extent())
297+
assert_array_almost_equal(subset, ax.images[0].get_extent())
304298
assert ax.images[0].get_array().sum() == 8440966
305299
assert ax.images[0].get_array().shape == (126, 126, 3)
306300
assert_array_almost_equal(ax.images[0].get_array().mean(), 177.22696733014195)

0 commit comments

Comments
 (0)