Re: Reconciling transforms by from_origin and from_bounds


Luke
 
Edited

rasterio.transform.from_origin(westnorthxsizeysize)

Return an Affine transformation given upper left and pixel sizes.

https://rasterio.readthedocs.io/en/latest/api/rasterio.transform.html#rasterio.transform.from_origin

After changing your height calculation from bottom - top to top - bottom, for your coords I get similar transforms:

import math
from rasterio.transform import (from_origin, from_bounds, array_bounds)
from rasterio.coords import BoundingBox

bounds = BoundingBox(
left=1679712.0, bottom=5860848.0, right=1862208.0, top=6029312.0)
width = math.ceil((bounds.right - bounds.left) /
100) # resolution of 100
height = math.ceil((bounds.top - bounds.bottom) / 100) # resolution of 100

T_o = from_origin(bounds.left, bounds.top, 100, 100)

T_b = from_bounds(*bounds
, width, height)

print(T_o)
print(T_b)

print(array_bounds(height, width, T_o))
print(array_bounds(height, width, T_b))

| 100.00, 0.00, 1679712.00| | 0.00,-100.00, 6029312.00| | 0.00, 0.00, 1.00| | 100.00, 0.00, 1679712.00| | 0.00,-99.98, 6029312.00| | 0.00, 0.00, 1.00| (1679712.0, 5860812.0, 1862212.0, 6029312.0) (1679712.0, 5860848.0, 1862208.0, 6029312.0)

Join main@rasterio.groups.io to automatically receive all group messages.