Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bug in new `calculate_default_transform` from terracotta

See original GitHub issue

Issue Description

While using the new calculate_default_transform from Terracotta seemed to help with the performance, I encountered a but when dealing with scene that crosses the dateline separation

The problem happens here:

which will return negative width/height


|-386.76, 0.00,-9392582.04|
| 0.00, 6.31, 6887893.49|
| 0.00, 0.00, 1.00|


dataset link:

Not sure if it means something but here is the result from both rasterio and terracotta’s calculate_default_transform for a random tile.

# rasterio
| 238.34, 0.00,-20037508.08|
| 0.00,-238.34, 13596067.67|
| 0.00, 0.00, 1.00|

# terracotta
|-386.54, 0.00,-20028306.76|
| 0.00, 6.31, 13596067.67|
| 0.00, 0.00, 1.00|

@dionhaefner, could you test terracotta with the dataset I shared, so I can confirm this is only happening in rio-tiler ?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:16 (6 by maintainers)

github_iconTop GitHub Comments

dionhaefnercommented, Mar 25, 2020

I think I understand the problem now.

It is relatively easy to construct a transform that yields higher quality reprojections than GDAL’s default transform. Just oversample the image a bit to make sure you don’t lose any data.

This changes though when overviews are involved. If you oversample the image, overviews are triggered earlier, leading to an overall degraded quality. You can consider a situation where we duplicate every pixel at the VRT level:


If we then zoom out by a factor of 2, we would ideally see


But by then, the first overview is triggered already! So we actually see something like


As you noticed, trying to force GDAL to use a specific overview is a can of worms that I can’t open at this point.

I suggest the following workaround:

dst_transform, _, _ = rasterio.warp.calculate_default_transform(, target_crs, src.width, src.height, *src.bounds

tile_transform = transform.from_bounds(*tile_bounds, *tile_size)

dst_res = (
    min(abs(dst_transform.a), abs(tile_transform.a)),
    min(abs(dst_transform.e), abs(tile_transform.e)),

At low zoom levels, this uses the default transform, where it performs reasonably well. At high zoom levels, where we’re at the pixel and sub-pixel level, it makes sure that the VRT always oversamples the tile, so we always get down to the true data density if we zoom far enough.



Performance difference is not above noise level.

dionhaefnercommented, Mar 20, 2020

Yikes, this image is pretty much the perfect storm for my method

Screen Shot 2020-03-20 at 14 50 08
  • It is rotated so much that the top right corner is further west than the bottom left corner
  • Only one corner of the raster crosses the date line
  • Top left and bottom right corner of the image lie almost on the same latitude
  • Bottom left and top right corner lie almost on the same longitude

In cases like these, we cannot possibly do better than GDAL’s default transform. So even after I fix the bugs and catch these edge-cases, the result will not be better than the default.

I’ll have to come up with a better way to solve this, in the meantime I suggest you revert to the default transform.

Read more comments on GitHub >

github_iconTop Results From Across the Web

rasterio.warp module - Read the Docs
transform (Affine) – Input affine transformation matrix ... are calculated using GDAL's method for suggest warp output. ... Default is rasterio.enums.
Read more >
EhCache POM is misbehaving - java - Stack Overflow
The ehcache versions prior to 2.9.0 have declared terracotta artifacts as a managed dependency supplied by the specific maven repository. A fix for...
Read more >
How to use the rasterio.warp.calculate_default_transform ...
To help you get started, we've selected a few rasterio.warp.calculate_default_transform examples, based on popular ways it is used in public projects.
Read more >
Possible Bug With Asymmetric Support For Nested Animations ...
I believe there might be a bug in the animation functionality that expresses itself as asymmetric support for nested animations.
Read more >
Release Notes for Cisco Prime Collaboration Deployment ...
There are no new features added for this release. Caveats. Bug Search Tool. The system grades known problems (bugs) per severity level.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found