Skip to content

Commit

Permalink
Plum the new rowcol precision default all the way up thru rio-merge
Browse files Browse the repository at this point in the history
Follow up to #2106
  • Loading branch information
Sean Gillies committed Feb 10, 2021
1 parent ceb0e45 commit 8ff3305
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 12 deletions.
5 changes: 5 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
Changes
=======

1.2.1 (TBD)
-----------

- Fix an off-by-one error in the merge tool (#2106, #).

1.2.0 (2021-01-25)
------------------

Expand Down
2 changes: 1 addition & 1 deletion rasterio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import rasterio.path

__all__ = ['band', 'open', 'pad', 'Env']
__version__ = "1.2.0"
__version__ = "1.2.1dev"
__gdal_version__ = gdal_version()

# Rasterio attaches NullHandler to the 'rasterio' logger and its
Expand Down
2 changes: 1 addition & 1 deletion rasterio/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def merge(
res=None,
nodata=None,
dtype=None,
precision=10,
precision=None,
indexes=None,
output_count=None,
resampling=Resampling.nearest,
Expand Down
9 changes: 6 additions & 3 deletions rasterio/rio/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
@options.nodata_opt
@options.bidx_mult_opt
@options.overwrite_opt
@click.option('--precision', type=int, default=10,
help="Number of decimal places of precision in alignment of "
"pixels")
@click.option(
"--precision",
type=int,
default=None,
help="Number of decimal places of precision in alignment of pixels",
)
@options.creation_options
@click.pass_context
def merge(ctx, files, output, driver, bounds, res, resampling,
Expand Down
14 changes: 10 additions & 4 deletions rasterio/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ def rowcol(transform, xs, ys, op=math.floor, precision=None):
op : function
Function to convert fractional pixels to whole numbers (floor, ceiling,
round)
precision : int, optional
Decimal places of precision in indexing, as in `round()`.
precision : int or float, optional
An integer number of decimal points of precision when computing
inverse transform, or an absolute float precision.
Returns
-------
Expand All @@ -224,8 +225,13 @@ def rowcol(transform, xs, ys, op=math.floor, precision=None):
if not isinstance(ys, Iterable):
ys = [ys]

eps = sys.float_info.epsilon

if precision is None:
eps = sys.float_info.epsilon * (1.0 - 2.0 * op(0.1))
elif isinstance(precision, int):
eps = 10.0 ** -precision * (1.0 - 2.0 * op(0.1))
else:
eps = precision

invtransform = ~transform

rows = []
Expand Down
7 changes: 4 additions & 3 deletions rasterio/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,9 @@ def from_bounds(left, bottom, right, top, transform=None,
Number of rows of the window.
width: int, required
Number of columns of the window.
precision: int, optional
Number of decimal points of precision when computing inverse
transform.
precision: int or float, optional
An integer number of decimal points of precision when computing
inverse transform, or an absolute float precision.
Returns
-------
Expand Down Expand Up @@ -680,6 +680,7 @@ def round_lengths(self, op='floor', pixel_precision=None):
operator(round(self.height, pixel_precision) if
pixel_precision is not None else self.height))

# TODO: deprecate round_shape at 1.3.0, with a warning.
round_shape = round_lengths

def round_offsets(self, op='floor', pixel_precision=None):
Expand Down

0 comments on commit 8ff3305

Please sign in to comment.